From f7487c76a6d2f2991fd5703d7763021a5fb8b4d1 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 25 May 2021 11:13:08 +0200 Subject: [PATCH 1/2] 2925 - Exported production database --- db/changes/10300-newFacility/00-saleValue.sql | 26 - .../00-supplierBeneficiary.sql | 2 - db/changes/10300-newFacility/00-weekWaste.sql | 28 - .../00-weekWaste_byWorker.sql | 32 - .../00-weekWaste_getDetail.sql | 30 - db/changes/10300-newFacility/01-waste.sql | 21 - .../10300-newFacility/02-waste_addSales.sql | 37 - db/dump/dumpedFixtures.sql | 50 +- db/dump/fixtures.sql | 36 +- db/dump/structure.sql | 8113 +++++++++++------ 10 files changed, 5137 insertions(+), 3238 deletions(-) delete mode 100644 db/changes/10300-newFacility/00-saleValue.sql delete mode 100644 db/changes/10300-newFacility/00-supplierBeneficiary.sql delete mode 100644 db/changes/10300-newFacility/00-weekWaste.sql delete mode 100644 db/changes/10300-newFacility/00-weekWaste_byWorker.sql delete mode 100644 db/changes/10300-newFacility/00-weekWaste_getDetail.sql delete mode 100644 db/changes/10300-newFacility/01-waste.sql delete mode 100644 db/changes/10300-newFacility/02-waste_addSales.sql diff --git a/db/changes/10300-newFacility/00-saleValue.sql b/db/changes/10300-newFacility/00-saleValue.sql deleted file mode 100644 index 5165bd4a5..000000000 --- a/db/changes/10300-newFacility/00-saleValue.sql +++ /dev/null @@ -1,26 +0,0 @@ -CREATE OR REPLACE DEFINER = root@`%` VIEW `vn`.`saleValue` AS -SELECT `wh`.`name` AS `warehouse`, - `c`.`name` AS `client`, - `c`.`typeFk` AS `clientTypeFk`, - `u`.`name` AS `buyer`, - `it`.`id` AS `itemTypeFk`, - `it`.`name` AS `family`, - `s`.`itemFk` AS `itemFk`, - `s`.`concept` AS `concept`, - `s`.`quantity` AS `quantity`, - `b`.`buyingValue` + `b`.`freightValue` + `b`.`comissionValue` + `b`.`packageValue` AS `cost`, - (`b`.`buyingValue` + `b`.`freightValue` + `b`.`comissionValue` + `b`.`packageValue`) * `s`.`quantity` AS `value`, - `tm`.`year` AS `year`, - `tm`.`week` AS `week` -FROM `vn`.`sale` `s` - JOIN `vn`.`item` `i` ON `i`.`id` = `s`.`itemFk` - JOIN `vn`.`itemType` `it` ON `it`.`id` = `i`.`typeFk` - JOIN `account`.`user` `u` ON `u`.`id` = `it`.`workerFk` - JOIN `vn`.`ticket` `t` ON `t`.`id` = `s`.`ticketFk` - JOIN `vn`.`client` `c` ON `c`.`id` = `t`.`clientFk` - JOIN `vn`.`warehouse` `wh` ON `wh`.`id` = `t`.`warehouseFk` - JOIN `vn`.`time` `tm` ON `tm`.`dated` = CAST(`t`.`shipped` AS DATE) - JOIN `cache`.`last_buy` `lb` ON `lb`.`item_id` = `i`.`id` AND `lb`.`warehouse_id` = `wh`.`id` - JOIN `vn`.`buy` `b` ON `b`.`id` = `lb`.`buy_id` -WHERE `wh`.`isManaged` <> 0; - diff --git a/db/changes/10300-newFacility/00-supplierBeneficiary.sql b/db/changes/10300-newFacility/00-supplierBeneficiary.sql deleted file mode 100644 index fcd5a1e2e..000000000 --- a/db/changes/10300-newFacility/00-supplierBeneficiary.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE vn.`supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; -UPDATE vn.supplierAccount SET beneficiary = `description`; diff --git a/db/changes/10300-newFacility/00-weekWaste.sql b/db/changes/10300-newFacility/00-weekWaste.sql deleted file mode 100644 index 4883a49fc..000000000 --- a/db/changes/10300-newFacility/00-weekWaste.sql +++ /dev/null @@ -1,28 +0,0 @@ -DROP PROCEDURE IF EXISTS `bs`.`weekWaste`; - -DELIMITER $$ -$$ -CREATE DEFINER = `root`@`%` PROCEDURE `bs`.`weekWaste__`() -BEGIN - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK); - - SELECT *, 100 * dwindle / total AS percentage - FROM ( - SELECT buyer, - SUM(saleTotal) AS total, - SUM(saleWaste) AS dwindle - FROM bs.waste - WHERE year = vYear - AND week = vWeek - GROUP BY buyer - ) sub - ORDER BY percentage DESC; -END;$$ -DELIMITER ; - diff --git a/db/changes/10300-newFacility/00-weekWaste_byWorker.sql b/db/changes/10300-newFacility/00-weekWaste_byWorker.sql deleted file mode 100644 index ff660494f..000000000 --- a/db/changes/10300-newFacility/00-weekWaste_byWorker.sql +++ /dev/null @@ -1,32 +0,0 @@ -DROP PROCEDURE IF EXISTS `bs`.`weekWaste_byWorker`; - -DELIMITER $$ -$$ -CREATE - DEFINER = root@`%` PROCEDURE `bs`.`weekWaste_byWorker__`(IN vWorkerFk INT) -BEGIN - - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE()); - - SELECT *, 100 * mermas / total AS porcentaje - FROM ( - SELECT ws.family, - SUM(ws.saleTotal) AS total, - SUM(ws.saleWaste) AS mermas - FROM bs.waste ws - JOIN vn.worker w ON w.user = ws.buyer - WHERE year = vYear - AND week = vWeek - AND w.id = vWorkerFk - GROUP BY family - ) sub - ORDER BY porcentaje DESC; -END;;$$ -DELIMITER ; - diff --git a/db/changes/10300-newFacility/00-weekWaste_getDetail.sql b/db/changes/10300-newFacility/00-weekWaste_getDetail.sql deleted file mode 100644 index 5cf107d24..000000000 --- a/db/changes/10300-newFacility/00-weekWaste_getDetail.sql +++ /dev/null @@ -1,30 +0,0 @@ -DROP PROCEDURE IF EXISTS `bs`.`weekWaste_getDetail`; - -DELIMITER $$ -$$ -CREATE - DEFINER = root@`%` PROCEDURE `bs`.`weekWaste_getDetail__`() -BEGIN - DECLARE vLastWeek DATE; - DECLARE vWeek INT; - DECLARE vYear INT; - - SET vLastWeek = TIMESTAMPADD(WEEK, -1, CURDATE()); - SET vYear = YEAR(vLastWeek); - SET vWeek = WEEK(vLastWeek, 1); - - SELECT *, 100 * dwindle / total AS percentage - FROM ( - SELECT buyer, - ws.family, - SUM(ws.saleTotal) AS total, - SUM(ws.saleWaste) AS dwindle - FROM bs.waste ws - WHERE year = vYear - AND week = vWeek - GROUP BY buyer, family - ) sub - ORDER BY percentage DESC; -END;$$ -DELIMITER ; - diff --git a/db/changes/10300-newFacility/01-waste.sql b/db/changes/10300-newFacility/01-waste.sql deleted file mode 100644 index b01f3b6df..000000000 --- a/db/changes/10300-newFacility/01-waste.sql +++ /dev/null @@ -1,21 +0,0 @@ -ALTER TABLE `bs`.`waste` - ADD itemFk INT NULL AFTER `family`; - -ALTER TABLE `bs`.`waste` - ADD itemTypeFk SMALLINT(5) UNSIGNED NULL AFTER `itemFk`; - -ALTER TABLE `bs`.`waste` - ADD CONSTRAINT waste_itemType_id - FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType (id) - ON UPDATE CASCADE; - -ALTER TABLE `bs`.`waste` - ADD CONSTRAINT waste_item_id - FOREIGN KEY (itemFk) REFERENCES vn.item (id) - ON UPDATE CASCADE; - -ALTER TABLE `bs`.`waste` DROP PRIMARY KEY; - -ALTER TABLE `bs`.`waste` - ADD PRIMARY KEY (buyer, `year`, week, family, itemFk); - diff --git a/db/changes/10300-newFacility/02-waste_addSales.sql b/db/changes/10300-newFacility/02-waste_addSales.sql deleted file mode 100644 index ae9efd95b..000000000 --- a/db/changes/10300-newFacility/02-waste_addSales.sql +++ /dev/null @@ -1,37 +0,0 @@ -UPDATE `bs`.nightTask t SET t.`procedure` = 'waste_addSales' WHERE t.id = 54; - -DROP PROCEDURE IF EXISTS `bs`.`waste_Add`; - -DELIMITER $$ -$$ -CREATE - DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`() -BEGIN - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = CURDATE(); - - REPLACE bs.waste - SELECT *, 100 * mermas / total as porcentaje - FROM ( - SELECT buyer, - year, - week, - family, - itemFk, - itemTypeFk, - floor(sum(value)) as total, - floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas - FROM vn.saleValue - where year = vYear and week = vWeek - - GROUP BY family, itemFk - - ) sub - ORDER BY mermas DESC; -END;$$ -DELIMITER ; diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 67f547c6d..683e5b51f 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -1,6 +1,6 @@ USE `util`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: util -- ------------------------------------------------------ @@ -22,7 +22,7 @@ USE `util`; LOCK TABLES `config` WRITE; /*!40000 ALTER TABLE `config` DISABLE KEYS */; -INSERT INTO `config` VALUES (1,'10291',0,'production',NULL); +INSERT INTO `config` VALUES (1,'10300',0,'production',NULL); /*!40000 ALTER TABLE `config` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -34,9 +34,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:49 +-- Dump completed on 2021-05-25 10:34:49 USE `account`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ @@ -68,7 +68,7 @@ UNLOCK TABLES; LOCK TABLES `roleInherit` WRITE; /*!40000 ALTER TABLE `roleInherit` DISABLE KEYS */; -INSERT INTO `roleInherit` VALUES (1,1,2),(2,1,3),(3,1,70),(4,2,11),(5,3,11),(6,5,1),(7,5,21),(8,5,33),(124,5,76),(123,9,76),(9,9,100),(10,11,6),(11,13,1),(12,15,35),(143,15,49),(13,15,57),(114,15,76),(14,16,13),(15,16,15),(127,16,76),(16,17,20),(17,17,37),(18,17,39),(19,17,64),(136,17,76),(20,18,1),(132,18,76),(21,19,21),(22,20,13),(23,20,16),(24,20,65),(134,20,76),(25,21,13),(26,21,18),(27,21,53),(131,21,76),(28,22,13),(29,22,21),(30,30,5),(31,30,20),(32,30,22),(33,30,53),(34,30,64),(118,30,76),(35,31,1),(36,32,1),(37,34,1),(38,34,13),(39,34,33),(40,35,1),(142,35,75),(129,35,76),(41,36,44),(42,36,47),(43,37,1),(139,37,74),(125,37,76),(44,38,37),(45,38,64),(126,38,76),(46,39,5),(47,39,21),(48,39,57),(115,39,76),(49,40,1),(50,40,49),(51,41,13),(52,41,35),(53,41,40),(135,41,76),(54,42,35),(55,42,49),(128,42,76),(56,43,13),(57,43,42),(58,44,1),(59,45,13),(60,45,44),(61,47,1),(62,48,13),(63,48,47),(64,49,36),(65,49,58),(66,50,13),(67,50,21),(68,50,35),(69,50,49),(70,50,57),(71,50,59),(133,50,76),(72,51,1),(140,51,74),(141,51,75),(73,52,13),(74,52,19),(75,52,35),(76,52,51),(137,52,76),(77,53,1),(78,54,1),(79,55,13),(80,55,54),(81,56,1),(82,57,13),(83,57,56),(138,57,76),(84,58,1),(85,59,13),(109,59,50),(87,60,5),(88,60,37),(89,60,50),(90,60,57),(130,60,76),(91,61,13),(92,61,36),(93,65,19),(94,65,35),(95,65,50),(117,65,76),(122,66,76),(96,66,100),(97,67,5),(98,67,37),(99,69,35),(100,69,47),(101,70,11),(144,70,76),(102,71,1),(103,71,58),(104,72,13),(105,72,18),(106,73,5),(108,73,19),(107,73,64); +INSERT INTO `roleInherit` VALUES (1,1,2),(2,1,3),(3,1,70),(4,2,11),(5,3,11),(6,5,1),(7,5,21),(8,5,33),(124,5,76),(123,9,76),(9,9,100),(10,11,6),(11,13,1),(12,15,35),(143,15,49),(13,15,57),(114,15,76),(14,16,13),(15,16,15),(127,16,76),(16,17,20),(17,17,37),(18,17,39),(19,17,64),(145,17,67),(136,17,76),(20,18,1),(132,18,76),(21,19,21),(22,20,13),(23,20,16),(24,20,65),(134,20,76),(25,21,13),(26,21,18),(27,21,53),(131,21,76),(28,22,13),(29,22,21),(30,30,5),(31,30,20),(32,30,22),(33,30,53),(34,30,64),(118,30,76),(35,31,1),(36,32,1),(37,34,1),(38,34,13),(39,34,33),(40,35,1),(142,35,75),(129,35,76),(41,36,44),(42,36,47),(43,37,1),(139,37,74),(125,37,76),(44,38,37),(45,38,64),(126,38,76),(46,39,5),(47,39,21),(48,39,57),(115,39,76),(49,40,1),(50,40,49),(51,41,13),(52,41,35),(53,41,40),(135,41,76),(54,42,35),(55,42,49),(128,42,76),(56,43,13),(57,43,42),(58,44,1),(59,45,13),(60,45,44),(61,47,1),(62,48,13),(63,48,47),(64,49,36),(65,49,58),(66,50,13),(67,50,21),(68,50,35),(69,50,49),(70,50,57),(71,50,59),(133,50,76),(72,51,1),(140,51,74),(141,51,75),(73,52,13),(74,52,19),(75,52,35),(76,52,51),(137,52,76),(77,53,1),(78,54,1),(79,55,13),(80,55,54),(81,56,1),(82,57,13),(83,57,56),(138,57,76),(84,58,1),(85,59,13),(109,59,50),(87,60,5),(88,60,37),(89,60,50),(90,60,57),(130,60,76),(91,61,13),(92,61,36),(93,65,19),(94,65,35),(95,65,50),(117,65,76),(122,66,76),(96,66,100),(97,67,5),(98,67,37),(99,69,35),(100,69,47),(101,70,11),(144,70,76),(102,71,1),(103,71,58),(104,72,13),(105,72,18),(106,73,5),(108,73,19),(107,73,64); /*!40000 ALTER TABLE `roleInherit` ENABLE KEYS */; UNLOCK TABLES; @@ -78,7 +78,7 @@ UNLOCK TABLES; LOCK TABLES `roleRole` WRITE; /*!40000 ALTER TABLE `roleRole` DISABLE KEYS */; -INSERT INTO `roleRole` VALUES (33021,1,1),(33022,1,2),(33023,1,3),(33027,1,6),(33026,1,11),(33024,1,70),(33025,1,76),(32939,2,2),(32941,2,6),(32940,2,11),(32834,3,3),(32836,3,6),(32835,3,11),(32806,5,1),(32813,5,2),(32812,5,3),(32805,5,5),(32817,5,6),(32816,5,11),(32810,5,13),(32814,5,18),(32807,5,21),(32808,5,33),(32815,5,53),(32811,5,70),(32809,5,76),(33092,6,6),(32985,9,1),(32982,9,2),(32970,9,3),(32968,9,5),(32990,9,6),(32960,9,9),(32965,9,11),(33017,9,13),(32999,9,15),(33000,9,16),(32967,9,17),(33015,9,18),(33014,9,19),(33001,9,20),(33013,9,21),(33018,9,22),(32988,9,30),(32989,9,31),(32986,9,32),(32996,9,33),(32971,9,34),(32975,9,35),(33011,9,36),(32993,9,37),(32994,9,38),(32966,9,39),(32991,9,40),(32992,9,41),(32972,9,42),(32973,9,43),(32963,9,44),(32964,9,45),(32979,9,47),(32981,9,48),(33008,9,49),(33010,9,50),(33002,9,51),(33003,9,52),(32995,9,53),(32997,9,54),(32998,9,55),(32983,9,56),(32984,9,57),(33006,9,58),(33007,9,59),(33009,9,60),(33012,9,61),(33004,9,62),(32974,9,64),(33005,9,65),(33016,9,66),(32969,9,67),(32980,9,69),(33019,9,70),(32977,9,71),(32978,9,72),(32987,9,73),(33020,9,74),(32976,9,75),(32961,9,76),(32962,9,100),(32754,11,6),(32753,11,11),(33553,13,1),(33554,13,2),(33555,13,3),(33559,13,6),(33558,13,11),(33552,13,13),(33556,13,70),(33557,13,76),(33178,15,1),(33185,15,2),(33184,15,3),(33187,15,6),(33186,15,11),(33179,15,13),(33170,15,15),(33171,15,35),(33176,15,36),(33182,15,44),(33181,15,47),(33172,15,49),(33180,15,56),(33173,15,57),(33175,15,58),(33183,15,70),(33177,15,75),(33174,15,76),(33194,16,1),(33199,16,2),(33198,16,3),(33206,16,6),(33205,16,11),(33189,16,13),(33190,16,15),(33188,16,16),(33193,16,35),(33200,16,36),(33204,16,44),(33203,16,47),(33192,16,49),(33202,16,56),(33195,16,57),(33201,16,58),(33197,16,70),(33196,16,75),(33191,16,76),(32778,17,1),(32788,17,2),(32787,17,3),(32782,17,5),(32800,17,6),(32796,17,11),(32781,17,13),(32792,17,15),(32780,17,16),(32771,17,17),(32793,17,18),(32791,17,19),(32772,17,20),(32783,17,21),(32785,17,33),(32790,17,35),(32802,17,36),(32773,17,37),(32774,17,39),(32804,17,44),(32803,17,47),(32799,17,49),(32789,17,50),(32794,17,53),(32795,17,56),(32784,17,57),(32801,17,58),(32797,17,59),(32775,17,64),(32779,17,65),(32786,17,70),(32777,17,74),(32798,17,75),(32776,17,76),(33484,18,1),(33487,18,2),(33486,18,3),(33490,18,6),(33489,18,11),(33483,18,18),(33488,18,70),(33485,18,76),(33477,19,1),(33480,19,2),(33479,19,3),(33482,19,6),(33481,19,11),(33473,19,13),(33474,19,18),(33471,19,19),(33472,19,21),(33475,19,53),(33478,19,70),(33476,19,76),(33215,20,1),(33221,20,2),(33220,20,3),(33233,20,6),(33230,20,11),(33208,20,13),(33214,20,15),(33209,20,16),(33226,20,18),(33213,20,19),(33207,20,20),(33222,20,21),(33212,20,35),(33229,20,36),(33232,20,44),(33231,20,47),(33218,20,49),(33216,20,50),(33225,20,53),(33227,20,56),(33217,20,57),(33228,20,58),(33224,20,59),(33210,20,65),(33219,20,70),(33223,20,75),(33211,20,76),(33465,21,1),(33468,21,2),(33467,21,3),(33470,21,6),(33469,21,11),(33461,21,13),(33462,21,18),(33460,21,21),(33463,21,53),(33466,21,70),(33464,21,76),(33564,22,1),(33569,22,2),(33568,22,3),(33571,22,6),(33570,22,11),(33561,22,13),(33563,22,18),(33562,22,21),(33560,22,22),(33565,22,53),(33567,22,70),(33566,22,76),(33064,30,1),(33070,30,2),(33069,30,3),(33053,30,5),(33081,30,6),(33077,30,11),(33061,30,13),(33066,30,15),(33060,30,16),(33067,30,18),(33065,30,19),(33054,30,20),(33063,30,21),(33055,30,22),(33052,30,30),(33062,30,33),(33071,30,35),(33080,30,36),(33083,30,44),(33082,30,47),(33076,30,49),(33072,30,50),(33056,30,53),(33078,30,56),(33075,30,57),(33079,30,58),(33073,30,59),(33057,30,64),(33059,30,65),(33068,30,70),(33074,30,75),(33058,30,76),(33085,31,1),(33086,31,2),(33087,31,3),(33091,31,6),(33090,31,11),(33084,31,31),(33088,31,70),(33089,31,76),(33029,32,1),(33030,32,2),(33031,32,3),(33035,32,6),(33034,32,11),(33028,32,32),(33032,32,70),(33033,32,76),(33151,33,33),(32838,34,1),(32843,34,2),(32842,34,3),(32846,34,6),(32845,34,11),(32839,34,13),(32840,34,33),(32837,34,34),(32841,34,70),(32844,34,76),(32881,35,1),(32886,35,2),(32885,35,3),(32888,35,6),(32887,35,11),(32880,35,35),(32884,35,70),(32882,35,75),(32883,35,76),(33380,36,1),(33382,36,2),(33381,36,3),(33386,36,6),(33385,36,11),(33377,36,36),(33378,36,44),(33379,36,47),(33383,36,70),(33384,36,76),(33124,37,1),(33129,37,2),(33128,37,3),(33131,37,6),(33130,37,11),(33123,37,37),(33127,37,70),(33125,37,74),(33126,37,76),(33137,38,1),(33140,38,2),(33139,38,3),(33142,38,6),(33141,38,11),(33133,38,37),(33132,38,38),(33134,38,64),(33138,38,70),(33136,38,74),(33135,38,76),(32763,39,1),(32768,39,2),(32767,39,3),(32756,39,5),(32770,39,6),(32769,39,11),(32761,39,13),(32760,39,18),(32757,39,21),(32762,39,33),(32755,39,39),(32764,39,53),(32765,39,56),(32758,39,57),(32766,39,70),(32759,39,76),(33094,40,1),(33097,40,2),(33096,40,3),(33105,40,6),(33104,40,11),(33099,40,36),(33093,40,40),(33102,40,44),(33101,40,47),(33095,40,49),(33100,40,58),(33098,40,70),(33103,40,76),(33113,41,1),(33117,41,2),(33116,41,3),(33122,41,6),(33121,41,11),(33107,41,13),(33108,41,35),(33114,41,36),(33109,41,40),(33106,41,41),(33120,41,44),(33119,41,47),(33111,41,49),(33118,41,58),(33115,41,70),(33112,41,75),(33110,41,76),(32853,42,1),(32858,42,2),(32857,42,3),(32861,42,6),(32860,42,11),(32848,42,35),(32851,42,36),(32847,42,42),(32855,42,44),(32859,42,47),(32849,42,49),(32854,42,58),(32856,42,70),(32852,42,75),(32850,42,76),(32866,43,1),(32872,43,2),(32871,43,3),(32878,43,6),(32877,43,11),(32863,43,13),(32865,43,35),(32873,43,36),(32864,43,42),(32862,43,43),(32876,43,44),(32875,43,47),(32867,43,49),(32874,43,58),(32870,43,70),(32869,43,75),(32868,43,76),(32736,44,1),(32737,44,2),(32738,44,3),(32742,44,6),(32741,44,11),(32735,44,44),(32739,44,70),(32740,44,76),(32746,45,1),(32748,45,2),(32747,45,3),(32752,45,6),(32751,45,11),(32744,45,13),(32745,45,44),(32743,45,45),(32749,45,70),(32750,45,76),(32911,47,1),(32912,47,2),(32913,47,3),(32917,47,6),(32916,47,11),(32910,47,47),(32914,47,70),(32915,47,76),(32932,48,1),(32934,48,2),(32933,48,3),(32938,48,6),(32937,48,11),(32930,48,13),(32931,48,47),(32929,48,48),(32935,48,70),(32936,48,76),(33321,49,1),(33324,49,2),(33323,49,3),(33327,49,6),(33326,49,11),(33317,49,36),(33320,49,44),(33319,49,47),(33316,49,49),(33318,49,58),(33322,49,70),(33325,49,76),(33369,50,1),(33374,50,2),(33373,50,3),(33376,50,6),(33375,50,11),(33356,50,13),(33368,50,18),(33357,50,21),(33358,50,35),(33365,50,36),(33371,50,44),(33370,50,47),(33359,50,49),(33355,50,50),(33367,50,53),(33363,50,56),(33360,50,57),(33364,50,58),(33361,50,59),(33372,50,70),(33366,50,75),(33362,50,76),(33235,51,1),(33240,51,2),(33239,51,3),(33243,51,6),(33242,51,11),(33234,51,51),(33238,51,70),(33236,51,74),(33237,51,75),(33241,51,76),(33253,52,1),(33258,52,2),(33257,52,3),(33260,52,6),(33259,52,11),(33245,52,13),(33255,52,18),(33246,52,19),(33252,52,21),(33247,52,35),(33248,52,51),(33244,52,52),(33254,52,53),(33256,52,70),(33250,52,74),(33251,52,75),(33249,52,76),(33144,53,1),(33145,53,2),(33146,53,3),(33150,53,6),(33149,53,11),(33143,53,53),(33147,53,70),(33148,53,76),(33153,54,1),(33154,54,2),(33155,54,3),(33159,54,6),(33158,54,11),(33152,54,54),(33156,54,70),(33157,54,76),(33163,55,1),(33165,55,2),(33164,55,3),(33169,55,6),(33168,55,11),(33161,55,13),(33162,55,54),(33160,55,55),(33166,55,70),(33167,55,76),(32943,56,1),(32944,56,2),(32945,56,3),(32949,56,6),(32948,56,11),(32942,56,56),(32946,56,70),(32947,56,76),(32954,57,1),(32957,57,2),(32956,57,3),(32959,57,6),(32958,57,11),(32951,57,13),(32952,57,56),(32950,57,57),(32955,57,70),(32953,57,76),(33287,58,1),(33288,58,2),(33289,58,3),(33293,58,6),(33292,58,11),(33286,58,58),(33290,58,70),(33291,58,76),(33298,59,1),(33308,59,2),(33307,59,3),(33315,59,6),(33314,59,11),(33295,59,13),(33305,59,18),(33297,59,21),(33299,59,35),(33309,59,36),(33313,59,44),(33312,59,47),(33300,59,49),(33296,59,50),(33304,59,53),(33311,59,56),(33301,59,57),(33310,59,58),(33294,59,59),(33306,59,70),(33303,59,75),(33302,59,76),(33338,60,1),(33350,60,2),(33349,60,3),(33329,60,5),(33354,60,6),(33353,60,11),(33334,60,13),(33347,60,18),(33337,60,21),(33336,60,33),(33339,60,35),(33344,60,36),(33330,60,37),(33352,60,44),(33351,60,47),(33340,60,49),(33331,60,50),(33346,60,53),(33342,60,56),(33332,60,57),(33343,60,58),(33341,60,59),(33328,60,60),(33348,60,70),(33335,60,74),(33345,60,75),(33333,60,76),(33391,61,1),(33395,61,2),(33394,61,3),(33398,61,6),(33397,61,11),(33388,61,13),(33389,61,36),(33390,61,44),(33392,61,47),(33387,61,61),(33393,61,70),(33396,61,76),(33261,62,62),(32879,64,64),(33269,65,1),(33278,65,2),(33277,65,3),(33285,65,6),(33284,65,11),(33267,65,13),(33280,65,18),(33263,65,19),(33270,65,21),(33264,65,35),(33275,65,36),(33283,65,44),(33282,65,47),(33271,65,49),(33265,65,50),(33279,65,53),(33281,65,56),(33272,65,57),(33274,65,58),(33273,65,59),(33262,65,65),(33276,65,70),(33268,65,75),(33266,65,76),(33517,66,1),(33513,66,2),(33501,66,3),(33499,66,5),(33522,66,6),(33516,66,9),(33496,66,11),(33548,66,13),(33531,66,15),(33532,66,16),(33498,66,17),(33547,66,18),(33546,66,19),(33533,66,20),(33545,66,21),(33549,66,22),(33520,66,30),(33521,66,31),(33518,66,32),(33528,66,33),(33502,66,34),(33506,66,35),(33543,66,36),(33525,66,37),(33526,66,38),(33497,66,39),(33523,66,40),(33524,66,41),(33503,66,42),(33504,66,43),(33494,66,44),(33495,66,45),(33510,66,47),(33512,66,48),(33540,66,49),(33542,66,50),(33534,66,51),(33535,66,52),(33527,66,53),(33529,66,54),(33530,66,55),(33514,66,56),(33515,66,57),(33538,66,58),(33539,66,59),(33541,66,60),(33544,66,61),(33536,66,62),(33505,66,64),(33537,66,65),(33491,66,66),(33500,66,67),(33511,66,69),(33550,66,70),(33508,66,71),(33509,66,72),(33519,66,73),(33551,66,74),(33507,66,75),(33492,66,76),(33493,66,100),(32822,67,1),(32830,67,2),(32829,67,3),(32819,67,5),(32833,67,6),(32832,67,11),(32827,67,13),(32826,67,18),(32821,67,21),(32823,67,33),(32820,67,37),(32831,67,53),(32818,67,67),(32828,67,70),(32825,67,74),(32824,67,76),(32922,69,1),(32926,69,2),(32925,69,3),(32928,69,6),(32927,69,11),(32919,69,35),(32920,69,47),(32918,69,69),(32924,69,70),(32921,69,75),(32923,69,76),(33575,70,6),(33573,70,11),(33572,70,70),(33574,70,76),(32892,71,1),(32895,71,2),(32894,71,3),(32899,71,6),(32898,71,11),(32893,71,58),(32896,71,70),(32891,71,71),(32897,71,76),(32904,72,1),(32906,72,2),(32905,72,3),(32909,72,6),(32908,72,11),(32901,72,13),(32902,72,18),(32907,72,70),(32900,72,72),(32903,72,76),(33042,73,1),(33047,73,2),(33046,73,3),(33037,73,5),(33051,73,6),(33050,73,11),(33044,73,13),(33048,73,18),(33038,73,19),(33041,73,21),(33040,73,33),(33049,73,53),(33039,73,64),(33045,73,70),(33036,73,73),(33043,73,76),(33576,74,74),(32889,75,75),(32890,76,76),(33424,100,1),(33420,100,2),(33407,100,3),(33405,100,5),(33429,100,6),(33423,100,9),(33402,100,11),(33456,100,13),(33438,100,15),(33439,100,16),(33404,100,17),(33454,100,18),(33453,100,19),(33440,100,20),(33452,100,21),(33457,100,22),(33427,100,30),(33428,100,31),(33425,100,32),(33435,100,33),(33408,100,34),(33412,100,35),(33450,100,36),(33432,100,37),(33433,100,38),(33403,100,39),(33430,100,40),(33431,100,41),(33409,100,42),(33410,100,43),(33400,100,44),(33401,100,45),(33417,100,47),(33419,100,48),(33447,100,49),(33449,100,50),(33441,100,51),(33442,100,52),(33434,100,53),(33436,100,54),(33437,100,55),(33421,100,56),(33422,100,57),(33445,100,58),(33446,100,59),(33448,100,60),(33451,100,61),(33443,100,62),(33411,100,64),(33444,100,65),(33455,100,66),(33406,100,67),(33418,100,69),(33458,100,70),(33415,100,71),(33416,100,72),(33426,100,73),(33459,100,74),(33413,100,75),(33414,100,76),(33399,100,100); +INSERT INTO `roleRole` VALUES (37416,1,1),(37417,1,2),(37418,1,3),(37422,1,6),(37421,1,11),(37419,1,70),(37420,1,76),(37334,2,2),(37336,2,6),(37335,2,11),(37229,3,3),(37231,3,6),(37230,3,11),(37201,5,1),(37208,5,2),(37207,5,3),(37200,5,5),(37212,5,6),(37211,5,11),(37205,5,13),(37209,5,18),(37202,5,21),(37203,5,33),(37210,5,53),(37206,5,70),(37204,5,76),(37487,6,6),(37380,9,1),(37377,9,2),(37365,9,3),(37363,9,5),(37385,9,6),(37355,9,9),(37360,9,11),(37412,9,13),(37394,9,15),(37395,9,16),(37362,9,17),(37410,9,18),(37409,9,19),(37396,9,20),(37408,9,21),(37413,9,22),(37383,9,30),(37384,9,31),(37381,9,32),(37391,9,33),(37366,9,34),(37370,9,35),(37406,9,36),(37388,9,37),(37389,9,38),(37361,9,39),(37386,9,40),(37387,9,41),(37367,9,42),(37368,9,43),(37358,9,44),(37359,9,45),(37374,9,47),(37376,9,48),(37403,9,49),(37405,9,50),(37397,9,51),(37398,9,52),(37390,9,53),(37392,9,54),(37393,9,55),(37378,9,56),(37379,9,57),(37401,9,58),(37402,9,59),(37404,9,60),(37407,9,61),(37399,9,62),(37369,9,64),(37400,9,65),(37411,9,66),(37364,9,67),(37375,9,69),(37414,9,70),(37372,9,71),(37373,9,72),(37382,9,73),(37415,9,74),(37371,9,75),(37356,9,76),(37357,9,100),(37148,11,6),(37147,11,11),(37948,13,1),(37949,13,2),(37950,13,3),(37954,13,6),(37953,13,11),(37947,13,13),(37951,13,70),(37952,13,76),(37573,15,1),(37580,15,2),(37579,15,3),(37582,15,6),(37581,15,11),(37574,15,13),(37565,15,15),(37566,15,35),(37571,15,36),(37577,15,44),(37576,15,47),(37567,15,49),(37575,15,56),(37568,15,57),(37570,15,58),(37578,15,70),(37572,15,75),(37569,15,76),(37589,16,1),(37594,16,2),(37593,16,3),(37601,16,6),(37600,16,11),(37584,16,13),(37585,16,15),(37583,16,16),(37588,16,35),(37595,16,36),(37599,16,44),(37598,16,47),(37587,16,49),(37597,16,56),(37590,16,57),(37596,16,58),(37592,16,70),(37591,16,75),(37586,16,76),(37174,17,1),(37183,17,2),(37182,17,3),(37172,17,5),(37195,17,6),(37191,17,11),(37177,17,13),(37187,17,15),(37176,17,16),(37165,17,17),(37188,17,18),(37186,17,19),(37166,17,20),(37178,17,21),(37180,17,33),(37185,17,35),(37197,17,36),(37167,17,37),(37168,17,39),(37199,17,44),(37198,17,47),(37194,17,49),(37184,17,50),(37189,17,53),(37190,17,56),(37179,17,57),(37196,17,58),(37192,17,59),(37169,17,64),(37175,17,65),(37170,17,67),(37181,17,70),(37173,17,74),(37193,17,75),(37171,17,76),(37879,18,1),(37882,18,2),(37881,18,3),(37885,18,6),(37884,18,11),(37878,18,18),(37883,18,70),(37880,18,76),(37872,19,1),(37875,19,2),(37874,19,3),(37877,19,6),(37876,19,11),(37868,19,13),(37869,19,18),(37866,19,19),(37867,19,21),(37870,19,53),(37873,19,70),(37871,19,76),(37610,20,1),(37616,20,2),(37615,20,3),(37628,20,6),(37625,20,11),(37603,20,13),(37609,20,15),(37604,20,16),(37621,20,18),(37608,20,19),(37602,20,20),(37617,20,21),(37607,20,35),(37624,20,36),(37627,20,44),(37626,20,47),(37613,20,49),(37611,20,50),(37620,20,53),(37622,20,56),(37612,20,57),(37623,20,58),(37619,20,59),(37605,20,65),(37614,20,70),(37618,20,75),(37606,20,76),(37860,21,1),(37863,21,2),(37862,21,3),(37865,21,6),(37864,21,11),(37856,21,13),(37857,21,18),(37855,21,21),(37858,21,53),(37861,21,70),(37859,21,76),(37959,22,1),(37964,22,2),(37963,22,3),(37966,22,6),(37965,22,11),(37956,22,13),(37958,22,18),(37957,22,21),(37955,22,22),(37960,22,53),(37962,22,70),(37961,22,76),(37459,30,1),(37465,30,2),(37464,30,3),(37448,30,5),(37476,30,6),(37472,30,11),(37456,30,13),(37461,30,15),(37455,30,16),(37462,30,18),(37460,30,19),(37449,30,20),(37458,30,21),(37450,30,22),(37447,30,30),(37457,30,33),(37466,30,35),(37475,30,36),(37478,30,44),(37477,30,47),(37471,30,49),(37467,30,50),(37451,30,53),(37473,30,56),(37470,30,57),(37474,30,58),(37468,30,59),(37452,30,64),(37454,30,65),(37463,30,70),(37469,30,75),(37453,30,76),(37480,31,1),(37481,31,2),(37482,31,3),(37486,31,6),(37485,31,11),(37479,31,31),(37483,31,70),(37484,31,76),(37424,32,1),(37425,32,2),(37426,32,3),(37430,32,6),(37429,32,11),(37423,32,32),(37427,32,70),(37428,32,76),(37546,33,33),(37233,34,1),(37238,34,2),(37237,34,3),(37241,34,6),(37240,34,11),(37234,34,13),(37235,34,33),(37232,34,34),(37236,34,70),(37239,34,76),(37276,35,1),(37281,35,2),(37280,35,3),(37283,35,6),(37282,35,11),(37275,35,35),(37279,35,70),(37277,35,75),(37278,35,76),(37775,36,1),(37777,36,2),(37776,36,3),(37781,36,6),(37780,36,11),(37772,36,36),(37773,36,44),(37774,36,47),(37778,36,70),(37779,36,76),(37519,37,1),(37524,37,2),(37523,37,3),(37526,37,6),(37525,37,11),(37518,37,37),(37522,37,70),(37520,37,74),(37521,37,76),(37532,38,1),(37535,38,2),(37534,38,3),(37537,38,6),(37536,38,11),(37528,38,37),(37527,38,38),(37529,38,64),(37533,38,70),(37531,38,74),(37530,38,76),(37157,39,1),(37162,39,2),(37161,39,3),(37150,39,5),(37164,39,6),(37163,39,11),(37155,39,13),(37154,39,18),(37151,39,21),(37156,39,33),(37149,39,39),(37158,39,53),(37159,39,56),(37152,39,57),(37160,39,70),(37153,39,76),(37489,40,1),(37492,40,2),(37491,40,3),(37500,40,6),(37499,40,11),(37494,40,36),(37488,40,40),(37497,40,44),(37496,40,47),(37490,40,49),(37495,40,58),(37493,40,70),(37498,40,76),(37508,41,1),(37512,41,2),(37511,41,3),(37517,41,6),(37516,41,11),(37502,41,13),(37503,41,35),(37509,41,36),(37504,41,40),(37501,41,41),(37515,41,44),(37514,41,47),(37506,41,49),(37513,41,58),(37510,41,70),(37507,41,75),(37505,41,76),(37248,42,1),(37253,42,2),(37252,42,3),(37256,42,6),(37255,42,11),(37243,42,35),(37246,42,36),(37242,42,42),(37250,42,44),(37254,42,47),(37244,42,49),(37249,42,58),(37251,42,70),(37247,42,75),(37245,42,76),(37261,43,1),(37267,43,2),(37266,43,3),(37273,43,6),(37272,43,11),(37258,43,13),(37260,43,35),(37268,43,36),(37259,43,42),(37257,43,43),(37271,43,44),(37270,43,47),(37262,43,49),(37269,43,58),(37265,43,70),(37264,43,75),(37263,43,76),(37130,44,1),(37131,44,2),(37132,44,3),(37136,44,6),(37135,44,11),(37129,44,44),(37133,44,70),(37134,44,76),(37140,45,1),(37142,45,2),(37141,45,3),(37146,45,6),(37145,45,11),(37138,45,13),(37139,45,44),(37137,45,45),(37143,45,70),(37144,45,76),(37306,47,1),(37307,47,2),(37308,47,3),(37312,47,6),(37311,47,11),(37305,47,47),(37309,47,70),(37310,47,76),(37327,48,1),(37329,48,2),(37328,48,3),(37333,48,6),(37332,48,11),(37325,48,13),(37326,48,47),(37324,48,48),(37330,48,70),(37331,48,76),(37716,49,1),(37719,49,2),(37718,49,3),(37722,49,6),(37721,49,11),(37712,49,36),(37715,49,44),(37714,49,47),(37711,49,49),(37713,49,58),(37717,49,70),(37720,49,76),(37764,50,1),(37769,50,2),(37768,50,3),(37771,50,6),(37770,50,11),(37751,50,13),(37763,50,18),(37752,50,21),(37753,50,35),(37760,50,36),(37766,50,44),(37765,50,47),(37754,50,49),(37750,50,50),(37762,50,53),(37758,50,56),(37755,50,57),(37759,50,58),(37756,50,59),(37767,50,70),(37761,50,75),(37757,50,76),(37630,51,1),(37635,51,2),(37634,51,3),(37638,51,6),(37637,51,11),(37629,51,51),(37633,51,70),(37631,51,74),(37632,51,75),(37636,51,76),(37648,52,1),(37653,52,2),(37652,52,3),(37655,52,6),(37654,52,11),(37640,52,13),(37650,52,18),(37641,52,19),(37647,52,21),(37642,52,35),(37643,52,51),(37639,52,52),(37649,52,53),(37651,52,70),(37645,52,74),(37646,52,75),(37644,52,76),(37539,53,1),(37540,53,2),(37541,53,3),(37545,53,6),(37544,53,11),(37538,53,53),(37542,53,70),(37543,53,76),(37548,54,1),(37549,54,2),(37550,54,3),(37554,54,6),(37553,54,11),(37547,54,54),(37551,54,70),(37552,54,76),(37558,55,1),(37560,55,2),(37559,55,3),(37564,55,6),(37563,55,11),(37556,55,13),(37557,55,54),(37555,55,55),(37561,55,70),(37562,55,76),(37338,56,1),(37339,56,2),(37340,56,3),(37344,56,6),(37343,56,11),(37337,56,56),(37341,56,70),(37342,56,76),(37349,57,1),(37352,57,2),(37351,57,3),(37354,57,6),(37353,57,11),(37346,57,13),(37347,57,56),(37345,57,57),(37350,57,70),(37348,57,76),(37682,58,1),(37683,58,2),(37684,58,3),(37688,58,6),(37687,58,11),(37681,58,58),(37685,58,70),(37686,58,76),(37693,59,1),(37703,59,2),(37702,59,3),(37710,59,6),(37709,59,11),(37690,59,13),(37700,59,18),(37692,59,21),(37694,59,35),(37704,59,36),(37708,59,44),(37707,59,47),(37695,59,49),(37691,59,50),(37699,59,53),(37706,59,56),(37696,59,57),(37705,59,58),(37689,59,59),(37701,59,70),(37698,59,75),(37697,59,76),(37733,60,1),(37745,60,2),(37744,60,3),(37724,60,5),(37749,60,6),(37748,60,11),(37729,60,13),(37742,60,18),(37732,60,21),(37731,60,33),(37734,60,35),(37739,60,36),(37725,60,37),(37747,60,44),(37746,60,47),(37735,60,49),(37726,60,50),(37741,60,53),(37737,60,56),(37727,60,57),(37738,60,58),(37736,60,59),(37723,60,60),(37743,60,70),(37730,60,74),(37740,60,75),(37728,60,76),(37786,61,1),(37790,61,2),(37789,61,3),(37793,61,6),(37792,61,11),(37783,61,13),(37784,61,36),(37785,61,44),(37787,61,47),(37782,61,61),(37788,61,70),(37791,61,76),(37656,62,62),(37274,64,64),(37664,65,1),(37673,65,2),(37672,65,3),(37680,65,6),(37679,65,11),(37662,65,13),(37675,65,18),(37658,65,19),(37665,65,21),(37659,65,35),(37670,65,36),(37678,65,44),(37677,65,47),(37666,65,49),(37660,65,50),(37674,65,53),(37676,65,56),(37667,65,57),(37669,65,58),(37668,65,59),(37657,65,65),(37671,65,70),(37663,65,75),(37661,65,76),(37912,66,1),(37908,66,2),(37896,66,3),(37894,66,5),(37917,66,6),(37911,66,9),(37891,66,11),(37943,66,13),(37926,66,15),(37927,66,16),(37893,66,17),(37942,66,18),(37941,66,19),(37928,66,20),(37940,66,21),(37944,66,22),(37915,66,30),(37916,66,31),(37913,66,32),(37923,66,33),(37897,66,34),(37901,66,35),(37938,66,36),(37920,66,37),(37921,66,38),(37892,66,39),(37918,66,40),(37919,66,41),(37898,66,42),(37899,66,43),(37889,66,44),(37890,66,45),(37905,66,47),(37907,66,48),(37935,66,49),(37937,66,50),(37929,66,51),(37930,66,52),(37922,66,53),(37924,66,54),(37925,66,55),(37909,66,56),(37910,66,57),(37933,66,58),(37934,66,59),(37936,66,60),(37939,66,61),(37931,66,62),(37900,66,64),(37932,66,65),(37886,66,66),(37895,66,67),(37906,66,69),(37945,66,70),(37903,66,71),(37904,66,72),(37914,66,73),(37946,66,74),(37902,66,75),(37887,66,76),(37888,66,100),(37217,67,1),(37225,67,2),(37224,67,3),(37214,67,5),(37228,67,6),(37227,67,11),(37222,67,13),(37221,67,18),(37216,67,21),(37218,67,33),(37215,67,37),(37226,67,53),(37213,67,67),(37223,67,70),(37220,67,74),(37219,67,76),(37317,69,1),(37321,69,2),(37320,69,3),(37323,69,6),(37322,69,11),(37314,69,35),(37315,69,47),(37313,69,69),(37319,69,70),(37316,69,75),(37318,69,76),(37970,70,6),(37968,70,11),(37967,70,70),(37969,70,76),(37287,71,1),(37290,71,2),(37289,71,3),(37294,71,6),(37293,71,11),(37288,71,58),(37291,71,70),(37286,71,71),(37292,71,76),(37299,72,1),(37301,72,2),(37300,72,3),(37304,72,6),(37303,72,11),(37296,72,13),(37297,72,18),(37302,72,70),(37295,72,72),(37298,72,76),(37437,73,1),(37442,73,2),(37441,73,3),(37432,73,5),(37446,73,6),(37445,73,11),(37439,73,13),(37443,73,18),(37433,73,19),(37436,73,21),(37435,73,33),(37444,73,53),(37434,73,64),(37440,73,70),(37431,73,73),(37438,73,76),(37971,74,74),(37284,75,75),(37285,76,76),(37819,100,1),(37815,100,2),(37802,100,3),(37800,100,5),(37824,100,6),(37818,100,9),(37797,100,11),(37851,100,13),(37833,100,15),(37834,100,16),(37799,100,17),(37849,100,18),(37848,100,19),(37835,100,20),(37847,100,21),(37852,100,22),(37822,100,30),(37823,100,31),(37820,100,32),(37830,100,33),(37803,100,34),(37807,100,35),(37845,100,36),(37827,100,37),(37828,100,38),(37798,100,39),(37825,100,40),(37826,100,41),(37804,100,42),(37805,100,43),(37795,100,44),(37796,100,45),(37812,100,47),(37814,100,48),(37842,100,49),(37844,100,50),(37836,100,51),(37837,100,52),(37829,100,53),(37831,100,54),(37832,100,55),(37816,100,56),(37817,100,57),(37840,100,58),(37841,100,59),(37843,100,60),(37846,100,61),(37838,100,62),(37806,100,64),(37839,100,65),(37850,100,66),(37801,100,67),(37813,100,69),(37853,100,70),(37810,100,71),(37811,100,72),(37821,100,73),(37854,100,74),(37808,100,75),(37809,100,76),(37794,100,100); /*!40000 ALTER TABLE `roleRole` ENABLE KEYS */; UNLOCK TABLES; @@ -120,9 +120,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:49 +-- Dump completed on 2021-05-25 10:34:50 USE `salix`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: salix -- ------------------------------------------------------ @@ -176,9 +176,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:50 +-- Dump completed on 2021-05-25 10:34:50 USE `vn`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: vn -- ------------------------------------------------------ @@ -310,7 +310,7 @@ UNLOCK TABLES; LOCK TABLES `claimReason` WRITE; /*!40000 ALTER TABLE `claimReason` DISABLE KEYS */; -INSERT INTO `claimReason` VALUES (1,'Prisas'),(2,'Novato'),(3,'Exceso de confianza'),(4,'Exceso de celo'),(5,'Indiferencia'),(6,'Extraviado o Hurto'),(7,'Incompetencia'),(8,'Ubicación erronea'),(9,'Dat.Inctos/Pak.conf'),(10,'Datos duplicados'),(11,'Fallo stock'),(12,'Innovación'),(13,'Distracción'),(15,'Portes indebidos'),(16,'Baja calidad'),(17,'Defectuoso'),(19,'Endiñado'),(20,'Calor'),(21,'Frio'),(22,'Cambiado'),(24,'Cansancio'),(25,'Mal etiquetado'),(26,'Cantidad malentendido'),(30,'No revisado'),(34,'Error fotografia'),(40,'Fallo Personal VN'),(41,'Fallo Personal Cliente'),(42,'Otros'),(43,'Precio alto'),(44,'Abuso de confianza'),(45,'Retraso Agencia'),(46,'Delicado'); +INSERT INTO `claimReason` VALUES (1,'Prisas',0),(2,'Novato',0),(3,'Exceso de confianza',0),(4,'Exceso de celo',0),(5,'Indiferencia',0),(6,'Extraviado o Hurto',0),(7,'Incompetencia',0),(8,'Ubicación erronea',0),(9,'Dat.Inctos/Pak.conf',0),(10,'Datos duplicados',0),(11,'Fallo stock',0),(12,'Innovación',0),(13,'Distracción',1),(15,'Portes indebidos',0),(16,'Baja calidad',0),(17,'Defectuoso',0),(19,'Endiñado',0),(20,'Calor',0),(21,'Frio',0),(22,'Cambiado',0),(24,'Cansancio',1),(25,'Mal etiquetado',1),(26,'Cantidad malentendido',0),(30,'No revisado',1),(34,'Error fotografia',0),(40,'Fallo Personal VN',0),(41,'Fallo Personal Cliente',0),(42,'Otros',0),(43,'Precio alto',0),(44,'Abuso de confianza',0),(45,'Retraso Agencia',0),(46,'Delicado',0); /*!40000 ALTER TABLE `claimReason` ENABLE KEYS */; UNLOCK TABLES; @@ -350,7 +350,7 @@ UNLOCK TABLES; LOCK TABLES `state` WRITE; /*!40000 ALTER TABLE `state` DISABLE KEYS */; -INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1),(2,'Libre',2,0,'FREE',NULL,2,1,0,0,0,1,0,4,1),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0),(5,'Preparación',6,1,'ON_PREPARATION',7,5,0,0,0,2,0,0,2,0),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0),(22,'¿Fecha?',2,0,'WRONG_DATE',NULL,22,0,0,0,0,0,0,4,1),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0),(26,'Prep Previa',5,1,'PREVIOUS_PREPARATION',1,26,0,0,0,1,0,0,2,0),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0),(28,'Previa OK',3,1,'OK PREVIOUS',3,28,1,0,0,1,1,1,3,0),(29,'Previa Impreso',4,1,'PRINTED PREVIOUS',2,29,1,0,1,1,0,1,3,0),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,3,0),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0); +INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1),(2,'Libre',2,0,'FREE',NULL,2,1,0,0,0,1,0,4,1),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0),(5,'Preparación',6,1,'ON_PREPARATION',7,5,0,0,0,2,0,0,2,0),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0),(22,'¿Fecha?',2,0,'WRONG_DATE',NULL,22,0,0,0,0,0,0,4,1),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0),(26,'Prep Previa',5,1,'PREVIOUS_PREPARATION',1,26,0,0,0,1,0,0,2,0),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0),(28,'Previa OK',3,1,'OK PREVIOUS',3,28,0,0,0,1,1,1,3,0),(29,'Previa Impreso',4,1,'PRINTED PREVIOUS',2,29,0,0,1,1,0,1,3,0),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,3,0),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0); /*!40000 ALTER TABLE `state` ENABLE KEYS */; UNLOCK TABLES; @@ -370,7 +370,7 @@ UNLOCK TABLES; LOCK TABLES `department` WRITE; /*!40000 ALTER TABLE `department` DISABLE KEYS */; -INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,2,763,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL),(22,NULL,'COMPRAS',3,4,NULL,72,596,2,5,0,0,0,0,NULL,'/',NULL,1,NULL),(23,NULL,'CAMARA',14,19,NULL,72,604,2,6,1,0,1,2,37,'/37/',NULL,0,NULL),(31,'IT','INFORMATICA',5,6,NULL,72,127,3,9,0,0,0,0,NULL,'/','informatica-cau',1,NULL),(34,NULL,'CONTABILIDAD',7,8,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL),(35,NULL,'FINANZAS',9,10,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL),(36,NULL,'LABORAL',11,12,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL),(37,NULL,'PRODUCCION',13,52,NULL,72,230,3,11,1,0,0,17,NULL,'/',NULL,0,NULL),(38,NULL,'SACADO',20,21,NULL,72,230,4,14,1,0,1,0,37,'/37/',NULL,0,NULL),(39,NULL,'ENCAJADO',22,23,NULL,72,230,4,12,1,0,1,0,37,'/37/',NULL,0,NULL),(41,NULL,'ADMINISTRACION',53,54,NULL,72,599,3,8,0,0,0,0,NULL,'/',NULL,1,NULL),(43,NULL,'VENTAS',55,76,NULL,0,NULL,NULL,NULL,0,0,0,10,NULL,'/',NULL,1,'direccioncomercial@verdnatura.es'),(44,NULL,'GERENCIA',77,78,NULL,72,300,2,7,0,0,0,0,NULL,'/',NULL,0,NULL),(45,NULL,'LOGISTICA',79,80,NULL,72,596,3,19,0,0,0,0,NULL,'/',NULL,1,NULL),(46,NULL,'REPARTO',81,84,NULL,72,659,3,10,0,0,0,1,NULL,'/',NULL,0,NULL),(48,NULL,'ALMACENAJE',85,86,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL),(49,NULL,'PROPIEDAD',87,88,NULL,72,1008,1,1,0,0,0,0,NULL,'/',NULL,0,NULL),(52,NULL,'CARGA AEREA',89,90,NULL,72,163,4,28,0,0,0,0,NULL,'/',NULL,0,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',91,92,NULL,72,1238,0,0,0,0,0,0,NULL,'/',NULL,1,NULL),(54,NULL,'ORNAMENTALES',93,94,NULL,72,433,3,21,0,0,0,0,NULL,'/',NULL,0,NULL),(55,NULL,'TALLER NATURAL',95,96,NULL,72,695,2,23,0,0,0,0,NULL,'/',NULL,0,NULL),(56,NULL,'TALLER ARTIFICIAL',97,98,NULL,72,1780,2,24,0,0,0,0,NULL,'/',NULL,0,NULL),(58,NULL,'CAMPOS',99,100,NULL,72,225,2,2,0,0,0,0,NULL,'/',NULL,0,NULL),(59,NULL,'MANTENIMIENTO',101,102,NULL,72,1907,4,16,0,0,0,0,NULL,'/',NULL,0,NULL),(60,NULL,'RECLAMACIONES',103,104,NULL,72,563,3,20,0,0,0,0,NULL,'/',NULL,1,NULL),(61,NULL,'VNH',105,106,NULL,73,1297,3,17,0,0,0,0,NULL,'/',NULL,0,NULL),(63,NULL,'VENTAS FRANCIA',56,57,NULL,72,277,2,27,0,0,1,0,43,'/43/',NULL,0,NULL),(66,NULL,'VERDNAMADRID',107,108,NULL,72,163,3,18,0,0,0,0,NULL,'/',NULL,0,NULL),(68,NULL,'COMPLEMENTOS',24,25,NULL,72,617,3,26,1,0,1,0,37,'/37/',NULL,0,NULL),(69,NULL,'VERDNABARNA',109,110,NULL,74,432,3,22,0,0,0,0,NULL,'/',NULL,0,NULL),(77,NULL,'PALETIZADO',82,83,NULL,72,230,4,15,1,0,1,0,46,'/46/',NULL,0,NULL),(80,NULL,'EQUIPO J VALLES',58,59,NULL,72,693,3,4,0,0,1,0,43,'/43/','jvp_equipo',1,NULL),(86,NULL,'LIMPIEZA',111,112,NULL,72,599,0,0,0,0,0,0,NULL,'/',NULL,0,NULL),(89,NULL,'COORDINACION',113,114,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL),(90,NULL,'TRAILER',115,116,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL),(91,NULL,'ARTIFICIAL',26,27,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(92,NULL,'EQUIPO SILVERIO',60,61,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','sdc_equipo',1,NULL),(93,NULL,'CONFECCION',117,118,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL),(94,NULL,'EQUIPO J BROCAL',62,63,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jes_equipo',1,NULL),(95,NULL,'EQUIPO C ZAMBRANO',64,65,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','czg_equipo',1,NULL),(96,NULL,'EQUIPO C LOPEZ',66,67,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','cla_equipo',1,NULL),(98,NULL,'EQUIPO RODRIGO',68,69,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','rhr_equipo',1,NULL),(101,NULL,'EQUIPO J IBAÑEZ',70,71,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jmi_equipo',1,NULL),(102,NULL,'EQ ROJO FV RUBEN C',28,29,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(103,NULL,'EQ AZUL FV A FOLQUES',30,31,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(104,NULL,'EQ AMARILLO FV NORMAN G',32,33,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(105,NULL,'EQ MORADO FV MATOU',34,35,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(106,NULL,'EQ VERDE PCA KEVIN GIMENEZ',36,37,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(107,NULL,'EQ NARANJA PCA RUBEN ZANON',38,39,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(110,NULL,'EQ ROSA PCA J BONDIA',40,41,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(111,NULL,'EQ REPONEDOR CAJAS',42,43,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(112,NULL,'CAMARA EQ EDGAR LLEO',15,16,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL),(113,NULL,'CAMARA EQ MARC ROCA',17,18,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL),(114,NULL,'EQ MARRON PCA JL NUEVO',44,45,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(115,NULL,'EQUIPO CLAUDI',72,73,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','csr_equipo',1,NULL),(120,NULL,'PCA PRODUCCION',46,47,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(121,NULL,'FV PRODUCCION',48,49,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(122,NULL,'PCA ALMACEN',50,51,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',74,75,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','ebt_equipo',1,NULL),(124,NULL,'CONTROL INTERNO',119,120,NULL,72,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL); +INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,2,763,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL),(22,NULL,'COMPRAS',3,4,NULL,72,596,2,5,0,0,0,0,NULL,'/',NULL,1,NULL),(23,NULL,'CAMARA',14,19,NULL,72,604,2,6,1,0,1,2,37,'/37/',NULL,0,NULL),(31,'IT','INFORMATICA',5,6,NULL,72,127,3,9,0,0,0,0,NULL,'/','informatica-cau',1,NULL),(34,NULL,'CONTABILIDAD',7,8,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL),(35,NULL,'FINANZAS',9,10,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL),(36,NULL,'LABORAL',11,12,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL),(37,NULL,'PRODUCCION',13,52,NULL,72,230,3,11,1,0,0,17,NULL,'/',NULL,0,NULL),(38,NULL,'SACADO',20,21,NULL,72,230,4,14,1,0,1,0,37,'/37/',NULL,0,NULL),(39,NULL,'ENCAJADO',22,23,NULL,72,230,4,12,1,0,1,0,37,'/37/',NULL,0,NULL),(41,NULL,'ADMINISTRACION',53,54,NULL,72,599,3,8,0,0,0,0,NULL,'/',NULL,1,NULL),(43,NULL,'VENTAS',55,76,NULL,0,NULL,NULL,NULL,0,0,0,10,NULL,'/',NULL,1,'direccioncomercial@verdnatura.es'),(44,NULL,'GERENCIA',77,78,NULL,72,300,2,7,0,0,0,0,NULL,'/',NULL,0,NULL),(45,NULL,'LOGISTICA',79,80,NULL,72,596,3,19,0,0,0,0,NULL,'/',NULL,1,NULL),(46,NULL,'REPARTO',81,84,NULL,72,659,3,10,0,0,0,1,NULL,'/',NULL,1,NULL),(48,NULL,'ALMACENAJE',85,86,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL),(49,NULL,'PROPIEDAD',87,88,NULL,72,1008,1,1,0,0,0,0,NULL,'/',NULL,0,NULL),(52,NULL,'CARGA AEREA',89,90,NULL,72,163,4,28,0,0,0,0,NULL,'/',NULL,0,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',91,92,NULL,72,1238,0,0,0,0,0,0,NULL,'/',NULL,1,NULL),(54,NULL,'ORNAMENTALES',93,94,NULL,72,433,3,21,0,0,0,0,NULL,'/',NULL,0,NULL),(55,NULL,'TALLER NATURAL',95,96,NULL,72,695,2,23,0,0,0,0,NULL,'/',NULL,0,NULL),(56,NULL,'TALLER ARTIFICIAL',97,98,NULL,72,1780,2,24,0,0,0,0,NULL,'/',NULL,0,NULL),(58,NULL,'CAMPOS',99,100,NULL,72,225,2,2,0,0,0,0,NULL,'/',NULL,0,NULL),(59,NULL,'MANTENIMIENTO',101,102,NULL,72,1907,4,16,0,0,0,0,NULL,'/',NULL,0,NULL),(60,NULL,'RECLAMACIONES',103,104,NULL,72,563,3,20,0,0,0,0,NULL,'/',NULL,1,NULL),(61,NULL,'VNH',105,106,NULL,73,1297,3,17,0,0,0,0,NULL,'/',NULL,0,NULL),(63,NULL,'VENTAS FRANCIA',56,57,NULL,72,277,2,27,0,0,1,0,43,'/43/',NULL,0,NULL),(66,NULL,'VERDNAMADRID',107,108,NULL,72,163,3,18,0,0,0,0,NULL,'/',NULL,0,NULL),(68,NULL,'COMPLEMENTOS',24,25,NULL,72,617,3,26,1,0,1,0,37,'/37/',NULL,0,NULL),(69,NULL,'VERDNABARNA',109,110,NULL,74,432,3,22,0,0,0,0,NULL,'/',NULL,0,NULL),(77,NULL,'PALETIZADO',82,83,NULL,72,230,4,15,1,0,1,0,46,'/46/',NULL,0,NULL),(80,NULL,'EQUIPO J VALLES',58,59,NULL,72,693,3,4,0,0,1,0,43,'/43/','jvp_equipo',1,NULL),(86,NULL,'LIMPIEZA',111,112,NULL,72,599,0,0,0,0,0,0,NULL,'/',NULL,0,NULL),(89,NULL,'COORDINACION',113,114,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL),(90,NULL,'TRAILER',115,116,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL),(91,NULL,'ARTIFICIAL',26,27,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(92,NULL,'EQUIPO SILVERIO',60,61,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','sdc_equipo',1,NULL),(93,NULL,'CONFECCION',117,118,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL),(94,NULL,'EQUIPO J BROCAL',62,63,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jes_equipo',1,NULL),(95,NULL,'EQUIPO C ZAMBRANO',64,65,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','czg_equipo',1,NULL),(96,NULL,'EQUIPO C LOPEZ',66,67,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','cla_equipo',1,NULL),(98,NULL,'EQUIPO RODRIGO',68,69,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','rhr_equipo',1,NULL),(101,NULL,'EQUIPO J IBAÑEZ',70,71,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jmi_equipo',1,NULL),(102,NULL,'EQ ROJO FV RUBEN C',28,29,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(103,NULL,'EQ AZUL FV A FOLQUES',30,31,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(104,NULL,'EQ AMARILLO FV NORMAN G',32,33,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(105,NULL,'EQ MORADO FV MATOU',34,35,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(106,NULL,'EQ VERDE PCA KEVIN GIMENEZ',36,37,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(107,NULL,'EQ NARANJA PCA RUBEN ZANON',38,39,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(110,NULL,'EQ ROSA PCA J BONDIA',40,41,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(111,NULL,'EQ REPONEDOR CAJAS',42,43,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(112,NULL,'CAMARA EQ EDGAR LLEO',15,16,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL),(113,NULL,'CAMARA EQ MARC ROCA',17,18,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL),(114,NULL,'EQ MARRON PCA JL NUEVO',44,45,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(115,NULL,'EQUIPO CLAUDI',72,73,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','csr_equipo',1,NULL),(120,NULL,'PCA PRODUCCION',46,47,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(121,NULL,'FV PRODUCCION',48,49,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(122,NULL,'PCA ALMACEN',50,51,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',74,75,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','ebt_equipo',1,NULL),(124,NULL,'CONTROL INTERNO',119,120,NULL,72,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL); /*!40000 ALTER TABLE `department` ENABLE KEYS */; UNLOCK TABLES; @@ -380,7 +380,7 @@ UNLOCK TABLES; LOCK TABLES `component` WRITE; /*!40000 ALTER TABLE `component` DISABLE KEYS */; -INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices'),(14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay'),(15,'reparto',6,NULL,NULL,1,'delivery'),(17,'recobro',5,NULL,NULL,1,'debtCollection'),(21,'ajuste',11,NULL,NULL,1,'adjustment'),(22,'venta por paquete',9,1,NULL,0,'salePerPackage'),(23,'venta por caja',9,2,NULL,0,'salePerBox'),(28,'valor de compra',1,NULL,NULL,1,'purchaseValue'),(29,'margen',4,NULL,NULL,1,'margin'),(32,'descuento ultimas unidades',9,3,-0.05,0,'lastUnitsDiscount'),(33,'venta por caja',9,1,NULL,0,'salePerBox'),(34,'descuento comprador',4,NULL,NULL,1,'buyerDiscount'),(35,'cartera comprador',10,NULL,NULL,1,NULL),(36,'descuadre',12,NULL,NULL,1,'imbalance'),(37,'maná',7,4,NULL,0,'mana'),(38,'embolsado',9,NULL,NULL,1,'bagged'),(39,'maná auto',7,NULL,NULL,1,'autoMana'),(40,'cambios Santos 2016',4,NULL,NULL,1,NULL),(41,'bonificacion porte',6,NULL,NULL,1,'freightCharge'),(42,'promocion Francia',4,NULL,NULL,1,'frenchOffer'),(43,'promocion Floramondo',4,NULL,NULL,1,'floramondoPromo'),(44,'rappel cadena',2,NULL,NULL,1,'rappel'); +INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices',0),(14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay',0),(15,'reparto',6,NULL,NULL,1,'delivery',1),(17,'recobro',5,NULL,NULL,1,'debtCollection',0),(21,'ajuste',11,NULL,NULL,1,'adjustment',0),(22,'venta por paquete',9,1,NULL,0,'salePerPackage',0),(23,'venta por caja',9,2,NULL,0,'salePerBox',0),(28,'valor de compra',1,NULL,NULL,1,'purchaseValue',1),(29,'margen',4,NULL,NULL,1,'margin',1),(32,'descuento ultimas unidades',9,3,-0.05,0,'lastUnitsDiscount',0),(33,'venta por caja',9,1,NULL,0,'salePerBox',0),(34,'descuento comprador',4,NULL,NULL,1,'buyerDiscount',0),(35,'cartera comprador',10,NULL,NULL,1,NULL,0),(36,'descuadre',12,NULL,NULL,1,'imbalance',0),(37,'maná',7,4,NULL,0,'mana',0),(38,'embolsado',9,NULL,NULL,1,'bagged',0),(39,'maná auto',7,NULL,NULL,1,'autoMana',0),(40,'cambios Santos 2016',4,NULL,NULL,1,NULL,0),(41,'bonificacion porte',6,NULL,NULL,1,'freightCharge',0),(42,'promocion Francia',4,NULL,NULL,1,'frenchOffer',0),(43,'promocion Floramondo',4,NULL,NULL,1,'floramondoPromo',0),(44,'rappel cadena',2,NULL,NULL,1,'rappel',0); /*!40000 ALTER TABLE `component` ENABLE KEYS */; UNLOCK TABLES; @@ -412,9 +412,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:51 +-- Dump completed on 2021-05-25 10:34:51 USE `cache`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: cache -- ------------------------------------------------------ @@ -448,9 +448,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:51 +-- Dump completed on 2021-05-25 10:34:52 USE `hedera`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: hedera -- ------------------------------------------------------ @@ -514,9 +514,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:51 +-- Dump completed on 2021-05-25 10:34:52 USE `postgresql`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: postgresql -- ------------------------------------------------------ @@ -588,7 +588,7 @@ UNLOCK TABLES; LOCK TABLES `workcenter` WRITE; /*!40000 ALTER TABLE `workcenter` DISABLE KEYS */; -INSERT INTO `workcenter` VALUES (1,'Silla',20,1125,1,'Av espioca 100',552703),(2,'Mercaflor',19,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL),(4,'VNH',NULL,NULL,3,NULL,NULL),(5,'Madrid',28,2858,5,'Av constitución 3',554145),(6,'Vilassar',88,88032,2,'Cami del Crist, 33',556412),(7,'Tenerife',NULL,NULL,10,NULL,NULL),(8,NULL,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,NULL,60,'Fenollars, 20',523549),(10,NULL,NULL,NULL,NULL,NULL,NULL); +INSERT INTO `workcenter` VALUES (1,'Silla',20,1177,1,'Av espioca 100',552703),(2,'Mercaflor',19,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL),(4,'VNH',NULL,NULL,3,NULL,NULL),(5,'Madrid',28,2861,5,'Av constitución 3',554145),(6,'Vilassar',88,88035,2,'Cami del Crist, 33',556412),(7,'Tenerife',NULL,NULL,10,NULL,NULL),(8,NULL,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,NULL,60,'Fenollars, 20',523549),(10,NULL,NULL,NULL,NULL,NULL,NULL); /*!40000 ALTER TABLE `workcenter` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -600,9 +600,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:52 +-- Dump completed on 2021-05-25 10:34:52 USE `sage`; --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: sage -- ------------------------------------------------------ @@ -624,7 +624,7 @@ USE `sage`; LOCK TABLES `TiposIva` WRITE; /*!40000 ALTER TABLE `TiposIva` DISABLE KEYS */; -INSERT INTO `TiposIva` VALUES (2,0,'Operaciones no sujetas',0.0000000000,0.0000000000,0.0000000000,'','4770000020','','','','','','','95B21A93-5910-489D-83BB-C32788C9B19D','','','','','','','','','',0,0),(4,0,'I.V.A. 4%',0.0000000000,4.0000000000,0.0000000000,'4720000004','4770000004','','6310000000','','','','','9E6160D5-984E-4643-ACBC-1EBC3BF73360','','','','','','','','','',0,0),(5,0,'I.V.A. 4% y R.E. 0.5%',0.0000000000,4.0000000000,0.5000000000,'','4770000504','4770000405','','','','','','DBEFA562-63FB-4FFC-8171-64F0C6F065FF','','','','','','','','','',0,0),(6,0,'H.P. IVA 4% CEE',0.0000000000,4.0000000000,0.0000000000,'4721000004','4771008888','','','','','','','DD0ECBA8-2EF5-425E-911B-623580BADA77','','','','','','','','','',0,1),(7,0,'H.P. IVA 10% CEE',0.0000000000,10.0000000000,0.0000000000,'4721000011','4771008888','','','','','','','593208CD-6F28-4489-B6EC-907AD689EAC9','','','','','','','','','',0,1),(8,0,'H.P. IVA 21% CEE',0.0000000000,21.0000000000,0.0000000000,'4721000021','4771008888','','','','','','','27061852-9BC1-4C4F-9B6E-69970E208F23','','','','','','','','','',0,1),(10,0,'I.V.A. 10% Nacional',0.0000000000,10.0000000000,0.0000000000,'4720000011','4770000010','','','','','','','828A9D6F-5C01-4C3A-918A-B2E4482830D3','','','','','','','','','',0,0),(11,0,'I.V.A. 10% y R.E. 1,4%',0.0000000000,10.0000000000,1.4000000000,'','4770000101','4770000110','','','','','','C1F2D910-83A1-4191-A76C-8B3D7AB98348','','','','','','','','','',0,0),(16,0,'I.V.A. Adqui. servicios CEE',0.0000000000,21.0000000000,0.0000000000,'4721000015','4771000016','','','','','','','E3EDE961-CE8F-41D4-9E6C-D8BCD32275A1','','','','','','','','','',0,1),(18,0,'H.P. Iva Importación 0% ISP',0.0000000000,0.0000000000,0.0000000000,'4720000005','4770000005','','','','','','','27AD4158-2349-49C2-B53A-A4E0EFAC5D09','','','','','','','','','',0,0),(20,0,'I.V.A 0% Nacional',0.0000000000,0.0000000000,0.0000000000,'4720000000','','','','','','','','B90B0FBD-E513-4F04-9721-C873504E08DF','','','','','','','','','',0,0),(21,0,'I.V.A. 21%',0.0000000000,21.0000000000,0.0000000000,'4720000021','4770000021','4770000000','','','','','','BA8C4E28-DCFA-4F7B-AE4F-CA044626B55E','','','','','','','','','',0,0),(22,0,'IVA 10% importaciones',0.0000000000,10.0000000000,0.0000000000,'4722000010','','','','','','','','540450A8-4B41-4607-96D1-E7F296FB6933','','','','','','','','','',0,0),(26,0,'I.V.A. 21% y R.E. 5,2%',0.0000000000,21.0000000000,5.2000000000,'4720000021','4770000215','4770000521','631000000','','','','','2BC0765F-7739-49AE-A5F0-28B648B81677','','','','','','','','','',0,0),(90,0,'IVA 21% importaciones',0.0000000000,21.0000000000,0.0000000000,'4722000021','','','','','','','','EB675F91-5FF2-4E26-A31E-EEB674125945','','','','','','','','','',0,0),(91,0,'IVA 0% importaciones',0.0000000000,0.0000000000,0.0000000000,'4723000000','','','','','','','','5E5EFA56-2A99-4D54-A16B-5D818274CA18','','','','','','','','','',0,0),(93,0,'12% com. agrícola o forestal',0.0000000000,12.0000000000,0.0000000000,'4720000012','','','','','','','','267B1DDB-247F-4A71-AB95-3349FEFC5F92','','','','','','','','','',0,0),(110,0,'HP IVA Devengado Exento CEE',0.0000000000,0.0000000000,0.0000000000,'','4771000000','','','','','','','C605BC32-E161-42FD-83F3-3A66B1FBE399','','','','','','','','','',0,1),(111,0,'H.P. Iva Devengado Exento Ser',0.0000000000,0.0000000000,0.0000000000,'','4771000001','','','','','','','F1AEC4DC-AFE5-498E-A713-2648FFB6DA32','','','','','','','','','',0,0),(112,0,'H.P. IVA Devengado en exportac',0.0000000000,0.0000000000,0.0000000000,'','4770000002','','','','','','','F980AE74-BF75-4F4C-927F-0CCCE0DB8D15','','','','','','','','','',0,0),(113,0,'HP DEVENGADO 21 ISP ',0.0000000000,21.0000000000,0.0000000000,'4720000006','4770000006','','','','','','','728D7A76-E936-438C-AF05-3CA38FE16EA5','','','','','','','','','',0,0); +INSERT INTO `TiposIva` VALUES (2,0,'Operaciones no sujetas',0.0000000000,0.0000000000,0.0000000000,'','4770000020','','','','','','','95B21A93-5910-489D-83BB-C32788C9B19D','','','','','','','','','',0,0),(4,0,'I.V.A. 4%',0.0000000000,4.0000000000,0.0000000000,'4720000004','4770000004','','6310000000','','','','','9E6160D5-984E-4643-ACBC-1EBC3BF73360','','','','','','','','','',0,0),(5,0,'I.V.A. 4% y R.E. 0.5%',0.0000000000,4.0000000000,0.5000000000,'','4770000504','4770000405','','','','','','DBEFA562-63FB-4FFC-8171-64F0C6F065FF','','','','','','','','','',0,0),(6,0,'H.P. IVA 4% CEE',0.0000000000,4.0000000000,0.0000000000,'4721000004','4771000004','','','','','','','DD0ECBA8-2EF5-425E-911B-623580BADA77','','','','','','','','','',0,1),(7,0,'H.P. IVA 10% CEE',0.0000000000,10.0000000000,0.0000000000,'4721000011','4771000010','','','','','','','593208CD-6F28-4489-B6EC-907AD689EAC9','','','','','','','','','',0,1),(8,0,'H.P. IVA 21% CEE',0.0000000000,21.0000000000,0.0000000000,'4721000021','4771000021','','','','','','','27061852-9BC1-4C4F-9B6E-69970E208F23','','','','','','','','','',0,1),(10,0,'I.V.A. 10% Nacional',0.0000000000,10.0000000000,0.0000000000,'4720000011','4770000010','','6290000553','','','','','828A9D6F-5C01-4C3A-918A-B2E4482830D3','','','','','','','','','',0,0),(11,0,'I.V.A. 10% y R.E. 1,4%',0.0000000000,10.0000000000,1.4000000000,'','4770000101','4770000110','','','','','','C1F2D910-83A1-4191-A76C-8B3D7AB98348','','','','','','','','','',0,0),(16,0,'I.V.A. Adqui. servicios CEE',0.0000000000,21.0000000000,0.0000000000,'4721000015','4771000016','','','','','','','E3EDE961-CE8F-41D4-9E6C-D8BCD32275A1','','','','','','','','','',0,1),(18,0,'H.P. Iva Importación 0% ISP',0.0000000000,0.0000000000,0.0000000000,'4720000005','4770000005','','','','','','','27AD4158-2349-49C2-B53A-A4E0EFAC5D09','','','','','','','','','',0,0),(20,0,'I.V.A 0% Nacional',0.0000000000,0.0000000000,0.0000000000,'4720000000','','','','','','','','B90B0FBD-E513-4F04-9721-C873504E08DF','','','','','','','','','',0,0),(21,0,'I.V.A. 21%',0.0000000000,21.0000000000,0.0000000000,'4720000021','4770000021','4770000000','','','','','','BA8C4E28-DCFA-4F7B-AE4F-CA044626B55E','','','','','','','','','',0,0),(22,0,'IVA 10% importaciones',0.0000000000,10.0000000000,0.0000000000,'4722000010','','','','','','','','540450A8-4B41-4607-96D1-E7F296FB6933','','','','','','','','','',0,0),(26,0,'I.V.A. 21% y R.E. 5,2%',0.0000000000,21.0000000000,5.2000000000,'4720000021','4770000215','4770000521','631000000','','','','','2BC0765F-7739-49AE-A5F0-28B648B81677','','','','','','','','','',0,0),(90,0,'IVA 21% importaciones',0.0000000000,21.0000000000,0.0000000000,'4722000021','','','','','','','','EB675F91-5FF2-4E26-A31E-EEB674125945','','','','','','','','','',0,0),(91,0,'IVA 0% importaciones',0.0000000000,0.0000000000,0.0000000000,'4723000000','','','','','','','','5E5EFA56-2A99-4D54-A16B-5D818274CA18','','','','','','','','','',0,0),(92,0,'8.5% comp. ganadera o pesquera',0.0000000000,8.5000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(93,0,'12% com. agrícola o forestal',0.0000000000,12.0000000000,0.0000000000,'4720000012','','','','','','','','267B1DDB-247F-4A71-AB95-3349FEFC5F92','','','','','','','','','',0,0),(94,0,'10,5% com. ganadera o pesquera',0.0000000000,10.5000000000,0.0000000000,'4770000000','4720000000','631000000','477000000','','','','','','','','','','','','','','',0,0),(108,0,'I.V.A. 8%',0.0000000000,8.0000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(109,0,'I.V.A. 8% y R.E. 1%',0.0000000000,8.0000000000,1.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(110,0,'HP IVA Devengado Exento CEE',0.0000000000,0.0000000000,0.0000000000,'','4771000000','','','','','','','C605BC32-E161-42FD-83F3-3A66B1FBE399','','','','','','','','','',0,1),(111,0,'H.P. Iva Devengado Exento Ser',0.0000000000,0.0000000000,0.0000000000,'','4771000001','','','','','','','F1AEC4DC-AFE5-498E-A713-2648FFB6DA32','','','','','','','','','',0,0),(112,0,'H.P. IVA Devengado en exportac',0.0000000000,0.0000000000,0.0000000000,'','4770000002','','','','','','','F980AE74-BF75-4F4C-927F-0CCCE0DB8D15','','','','','','','','','',0,0),(113,0,'HP DEVENGADO 21 ISP ',0.0000000000,21.0000000000,0.0000000000,'4720000006','4770000006','','','','','','','728D7A76-E936-438C-AF05-3CA38FE16EA5','','','','','','','','','',0,0),(114,0,'HP.IVA NO DEDUCIBLE 10%',0.0000000000,0.0000000000,0.0000000000,'4720000026','','','','','','','','','','','','','','','','','',0,0); /*!40000 ALTER TABLE `TiposIva` ENABLE KEYS */; UNLOCK TABLES; @@ -656,4 +656,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 11:16:52 +-- Dump completed on 2021-05-25 10:34:53 diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f34386676..850915579 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -459,6 +459,19 @@ INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, (791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', NULL), (1381, 'ORN', NULL, 30, NULL, 7, NULL, 'ORN Company - Plant passport'); +INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) + VALUES + ('CEE', 1, 10), + ('EQU', 0, 1), + ('NATIONAL', 0, 1), + ('WORLD', 2, 15); + +INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`) + VALUES + ('A', 'Global nacional', 1, 'NATIONAL', 0), + ('T', 'Española rapida', 1, 'NATIONAL', 0), + ('V', 'Intracomunitaria global', 0, 'CEE', 1); + INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) VALUES (1, 'T', 1014.24, CURDATE(), 101, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), @@ -504,19 +517,6 @@ INSERT INTO `vn`.`invoiceOutExpence`(`id`, `invoiceOutFk`, `amount`, `expenceFk` (6, 4, 8.07, 2000000000, CURDATE()), (7, 5, 8.07, 2000000000, CURDATE()); -INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) - VALUES - ('CEE', 1, 10), - ('EQU', 0, 1), - ('NATIONAL', 0, 1), - ('WORLD', 2, 15); - -INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`) - VALUES - ('A', 'Global nacional', 1, 'NATIONAL', 0), - ('T', 'Española rapida', 1, 'NATIONAL', 0), - ('V', 'Intracomunitaria global', 0, 'CEE', 1); - INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `m3Max`) VALUES (1, 'Zone pickup A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 30.50), @@ -774,6 +774,12 @@ INSERT INTO `vn`.`intrastat`(`id`, `description`, `taxClassFk`, `taxCodeFk`) (05080000, 'Coral y materiales similares', 2, 2), (06021010, 'Plantas vivas: Esqueje/injerto, Vid', 1, 1); +INSERT INTO `vn`.`itemFamily`(`code`, `description`) + VALUES + ('EMB', 'Packagings'), + ('SER', 'Services'), + ('VT', 'Sales'); + INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `isOnOffer`, `expenceFk`, `isBargain`, `comment`, `relevancy`, `image`, `taxClassFk`, `subName`, `minPrice`, `stars`, `family`) VALUES (1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '1', 1, NULL, 0, 1, 'VT'), @@ -2250,10 +2256,6 @@ INSERT INTO `vn`.`campaign`(`code`, `dated`) ('allSaints', CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -2 YEAR)), '-11-01')), ('allSaints', CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -3 YEAR)), '-11-01')); -INSERT INTO `hedera`.`image`(`collectionFk`, `name`) - VALUES - ('user', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd'); - INSERT INTO `hedera`.`imageCollectionSize`(`id`, `collectionFk`,`width`, `height`) VALUES (1, 4, 160, 160); diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 407770aef..8d8c144e5 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -1,4 +1,4 @@ --- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ @@ -405,12 +405,12 @@ CREATE TABLE `user` ( `emailVerified` tinyint(1) DEFAULT NULL, `verificationToken` varchar(512) CHARACTER SET utf8 DEFAULT NULL, `lang` char(2) CHARACTER SET utf8 DEFAULT NULL, - `recoverPass` tinyint(3) unsigned NOT NULL DEFAULT '1', `lastPassChange` datetime DEFAULT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `password` char(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', `image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `password` char(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', + `recoverPass` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'Deprecated', `sync` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Deprecated', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), @@ -448,15 +448,19 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `user_afterInsert` - AFTER INSERT ON `user` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER user_afterInsert + AFTER INSERT + ON user + FOR EACH ROW BEGIN + CALL hedera.image_ref('user', NEW.image); + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; END */;; DELIMITER ; @@ -497,17 +501,24 @@ DELIMITER ; /*!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 sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `user_afterUpdate` - AFTER UPDATE ON `user` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER user_afterUpdate + AFTER UPDATE + ON user + FOR EACH ROW BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL hedera.image_unref('user', OLD.image); + CALL hedera.image_ref('user', NEW.image); + END IF; + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; IF !(OLD.`name` <=> NEW.`name`) THEN INSERT IGNORE INTO userSync SET `name` = OLD.`name`; END IF; - + IF !(NEW.`role` <=> OLD.`role`) THEN INSERT INTO vn.mail SET @@ -526,15 +537,19 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `user_afterDelete` - AFTER DELETE ON `user` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER user_afterDelete + AFTER DELETE + ON user + FOR EACH ROW BEGIN + CALL hedera.image_unref('user', OLD.image); + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; END */;; DELIMITER ; @@ -1276,8 +1291,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `myUser_changePassword`(vOldPassword VARCHAR(255), vPassword VARCHAR(255)) BEGIN /** - * Changes the current user password, if user is in recovery mode ignores the - * current password. + * Changes the current user password. * * @param vOldPassword The current password * @param vPassword The new password @@ -1422,6 +1436,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 DROP PROCEDURE IF EXISTS `myUser_restorePassword` */; +/*!50003 SET @saved_cs_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 `myUser_restorePassword`(vVerificationToken VARCHAR(255), vPassword VARCHAR(255)) +BEGIN +/** + * Changes the current user password using recovery token. + * + * @param vVerificationToken The current password + * @param vPassword The new password + */ + CALL user_restorePassword(myUser_getId(), vVerificationToken, vPassword); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `role_checkName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2338,6 +2377,44 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `user_restorePassword` */; +/*!50003 SET @saved_cs_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 `user_restorePassword`(vSelf INT, vVerificationToken VARCHAR(255), vPassword VARCHAR(255)) +BEGIN +/** + * Changes the user password using recovery token. + * + * @param vSelf The user id + * @param vVerificationToken The verification token + * @param vPassword The new password + */ + DECLARE vTokenVerified BOOL; + DECLARE vUserName VARCHAR(255); + + SELECT verificationToken = vVerificationToken, `name` + INTO vTokenVerified, vUserName + FROM user WHERE id = vSelf; + + IF NOT vTokenVerified THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Invalid verification token'; + END IF; + + CALL user_setPassword(vSelf, vPassword); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `user_setPassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2362,7 +2439,7 @@ BEGIN UPDATE user SET `password` = MD5(vPassword), - `recoverPass` = FALSE + `verificationToken` = NULL WHERE id = vSelf; END ;; DELIMITER ; @@ -2672,6 +2749,28 @@ CREATE TABLE `indicators` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los valores actuales para una consulta diaria rápida por los directivos.'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `inspeccionSS_2021` +-- + +DROP TABLE IF EXISTS `inspeccionSS_2021`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `inspeccionSS_2021` ( + `business_id` int(11) DEFAULT NULL, + `id` int(11) NOT NULL DEFAULT '0', + `firstName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `lastName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + `timed` datetime NOT NULL, + `hours_week` smallint(6) DEFAULT NULL, + `year` int(4) NOT NULL, + `week` int(2) NOT NULL, + `dated` date NOT NULL, + `orden` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='bs.inspeccionSS_2021_add()'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `lastIndicators` -- @@ -2968,6 +3067,23 @@ CREATE TABLE `nightTaskConfig` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `packingSpeed` +-- + +DROP TABLE IF EXISTS `packingSpeed`; +/*!50001 DROP VIEW IF EXISTS `packingSpeed`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `packingSpeed` ( + `hora` tinyint NOT NULL, + `minuto` tinyint NOT NULL, + `cm3` tinyint NOT NULL, + `warehouse_id` tinyint NOT NULL, + `odbc_date` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `payMethodClient` -- @@ -3296,10 +3412,15 @@ CREATE TABLE `waste` ( `year` int(4) NOT NULL, `week` int(2) NOT NULL, `family` varchar(30) COLLATE utf8_unicode_ci NOT NULL, + `itemFk` int(11) DEFAULT NULL, + `itemTypeFk` smallint(5) unsigned DEFAULT NULL, `saleTotal` decimal(16,0) DEFAULT NULL, `saleWaste` decimal(16,0) DEFAULT NULL, - `rate` decimal(3,1) DEFAULT NULL, - PRIMARY KEY (`buyer`,`year`,`week`,`family`) + `rate` decimal(5,1) DEFAULT NULL, + KEY `waste_itemType_id` (`itemTypeFk`), + KEY `waste_item_id` (`itemFk`), + CONSTRAINT `waste_itemType_id` FOREIGN KEY (`itemTypeFk`) REFERENCES `vn`.`itemType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `waste_item_id` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -3375,6 +3496,38 @@ CREATE TABLE `workerSpeed__` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `zone_ETD` +-- + +DROP TABLE IF EXISTS `zone_ETD`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `zone_ETD` ( + `zoneFk` int(11) DEFAULT NULL, + `totalVolume` decimal(5,1) DEFAULT NULL, + `remainingVolume` decimal(5,1) DEFAULT NULL, + `speed` decimal(10,2) NOT NULL DEFAULT '0.00', + `hourTheoretical` time DEFAULT NULL, + `hourPractical` varchar(10) 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 `zone_ETD_byTime` +-- + +DROP TABLE IF EXISTS `zone_ETD_byTime`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `zone_ETD_byTime` ( + `theorical` time NOT NULL, + `practical` time NOT NULL DEFAULT '00:00:00', + `m3` decimal(10,1) NOT NULL DEFAULT '0.0', + PRIMARY KEY (`theorical`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Dumping events for database 'bs' -- @@ -3397,6 +3550,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 `zone_ETD_byTime_Refresh` */;; +DELIMITER ;; +/*!50003 SET @saved_cs_client = @@character_set_client */ ;; +/*!50003 SET @saved_cs_results = @@character_set_results */ ;; +/*!50003 SET @saved_col_connection = @@collation_connection */ ;; +/*!50003 SET character_set_client = utf8 */ ;; +/*!50003 SET character_set_results = utf8 */ ;; +/*!50003 SET collation_connection = utf8_general_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `zone_ETD_byTime_Refresh` ON SCHEDULE EVERY 5 MINUTE STARTS '2021-04-12 14:28:27' ON COMPLETION NOT PRESERVE ENABLE DO CALL bs.zone_ETD_byTime() */ ;; +/*!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 */ ; @@ -3816,9 +3987,9 @@ ALTER DATABASE `bs` 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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -3835,6 +4006,12 @@ BEGIN DELETE FROM ventas WHERE fecha < vFourYearsAgo; + + DELETE FROM payMethodClient + WHERE dated < vOneYearAgo; + + DELETE FROM payMethodClientEvolution + WHERE dated < vFourYearsAgo; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4744,6 +4921,60 @@ BEGIN 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 `inspeccionSS_2021_add` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `inspeccionSS_2021_add`() +BEGIN + + TRUNCATE bs.inspeccionSS_2021; + + INSERT INTO bs.inspeccionSS_2021 + SELECT wbd.business_id , + w.id, + w.firstName, + w.lastName, + d.name , + wtc.timed , + cl.hours_week , + t.`year` , + t.week , + t.dated , + 0 AS orden + FROM vn.workerTimeControl wtc + JOIN vn.worker w ON w.id = wtc.userFk + JOIN vn.workerBusinessDated wbd ON wbd.workerFk = wtc.userFk AND wbd.dated = date(wtc.timed) + JOIN vn.time t ON t.dated = wbd.dated + JOIN postgresql.business_labour bl ON bl.business_id = wbd.business_id + JOIN postgresql.calendar_labour_type AS cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id + JOIN vn.department d ON d.id = bl.department_id + JOIN vn.department d2 ON d2.id = d.parentFk AND d2.name = 'PRODUCCION' + WHERE wtc.timed BETWEEN '2020-10-01' AND '2021-04-19' + AND d.lft BETWEEN d2.lft AND d2.rgt + AND lastName NOT LIKE 'FERRER%'; + + SET @orden := 1; + SET @id := 0; + SET @day := 0; + + UPDATE bs.inspeccionSS_2021 + SET orden = IF(id = @id AND day(timed) = @day, @orden := @orden + 1, @orden := 1), + id = @id := id + (0 * @day := day(timed)) + ORDER BY id, timed; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5334,18 +5565,14 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `saleGraphic`(vItemFk INT, - vTypeFk INT, - vCategoryFk INT, - vFromDate DATE, - vToDate DATE, - vProducerFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `saleGraphic`(IN vItemFk INT, IN vTypeFk INT, IN vCategoryFk INT, IN vFromDate DATE, + IN vToDate DATE, IN vProducerFk INT) BEGIN DECLARE vFromDateLastYear DATE; @@ -6560,7 +6787,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 `waste_Add` */; +/*!50003 DROP PROCEDURE IF EXISTS `waste_addSales` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -6570,117 +6797,85 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `waste_Add`() +CREATE DEFINER=`root`@`%` PROCEDURE `waste_addSales`() BEGIN - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year + DECLARE vYear INT; + + SELECT week, year INTO vWeek, vYear - FROM vn.time - WHERE dated = CURDATE(); + FROM vn.time + WHERE dated = CURDATE(); - REPLACE bs.waste + REPLACE bs.waste SELECT *, 100 * mermas / total as porcentaje FROM ( SELECT buyer, year, - week, + week, family, + itemFk, + itemTypeFk, floor(sum(value)) as total, floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas FROM vn.saleValue where year = vYear and week = vWeek - GROUP BY family + GROUP BY family, itemFk ) sub ORDER BY mermas DESC; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `weekWaste` */; +/*!50003 DROP PROCEDURE IF EXISTS `waste_addSales_lastWeek` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `weekWaste`() +CREATE DEFINER=`root`@`%` PROCEDURE `waste_addSales_lastWeek`() BEGIN DECLARE vWeek INT; - DECLARE vYear INT; + DECLARE vYear INT; - SELECT week, year + SELECT week, year INTO vWeek, vYear - FROM vn.time - WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK); - - SELECT *, 100 * dwindle / total AS percentage - FROM ( - SELECT buyer, - sum(saleTotal) as total, - sum(saleWaste) as dwindle - FROM bs.waste - WHERE year = vYear and week = vWeek - GROUP BY buyer - ) sub - ORDER BY percentage DESC; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `weekWaste_byWorker` */; -/*!50003 SET @saved_cs_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 `weekWaste_byWorker`(vWorkerFk INT) -BEGIN - - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = TIMESTAMPADD(WEEK,-1,CURDATE()); - + FROM vn.time + WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE()); + + REPLACE bs.waste SELECT *, 100 * mermas / total as porcentaje FROM ( - SELECT ws.family, - sum(ws.saleTotal) as total, - sum(ws.saleWaste) as mermas - FROM bs.waste ws - JOIN vn.worker w ON w.user = ws.buyer - WHERE year = vYear AND week = vWeek - AND w.id = vWorkerFk - GROUP BY family + SELECT buyer, + year, + week, + family, + itemFk, + itemTypeFk, + floor(sum(value)) as total, + floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas + FROM vn.saleValue + where year = vYear and week = vWeek + + GROUP BY family, itemFk ) sub - ORDER BY porcentaje DESC; + ORDER BY mermas DESC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `weekWaste_getDetail` */; +/*!50003 DROP PROCEDURE IF EXISTS `weekWaste_byWorker__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -6690,27 +6885,105 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `weekWaste_getDetail`() +CREATE DEFINER=`root`@`%` PROCEDURE `weekWaste_byWorker__`(IN vWorkerFk INT) BEGIN - DECLARE vLastWeek DATE; - DECLARE vWeek INT; + + DECLARE vWeek INT; DECLARE vYear INT; - - SET vLastWeek = TIMESTAMPADD(WEEK,-1,CURDATE()); + + SELECT week, year + INTO vWeek, vYear + FROM vn.time + WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE()); + + SELECT *, 100 * mermas / total AS porcentaje + FROM ( + SELECT ws.family, + SUM(ws.saleTotal) AS total, + SUM(ws.saleWaste) AS mermas + FROM bs.waste ws + JOIN vn.worker w ON w.user = ws.buyer + WHERE year = vYear + AND week = vWeek + AND w.id = vWorkerFk + GROUP BY family + ) sub + ORDER BY porcentaje DESC; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `weekWaste_getDetail__` */; +/*!50003 SET @saved_cs_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 `weekWaste_getDetail__`() +BEGIN + DECLARE vLastWeek DATE; + DECLARE vWeek INT; + DECLARE vYear INT; + + SET vLastWeek = TIMESTAMPADD(WEEK, -1, CURDATE()); SET vYear = YEAR(vLastWeek); SET vWeek = WEEK(vLastWeek, 1); - - SELECT *, 100 * dwindle / total AS percentage - FROM ( - SELECT buyer, - ws.family, - sum(ws.saleTotal) AS total, - sum(ws.saleWaste) AS dwindle - FROM bs.waste ws - WHERE year = vYear AND week = vWeek - GROUP BY buyer, family - ) sub - ORDER BY percentage DESC; + + SELECT *, 100 * dwindle / total AS percentage + FROM ( + SELECT buyer, + ws.family, + SUM(ws.saleTotal) AS total, + SUM(ws.saleWaste) AS dwindle + FROM bs.waste ws + WHERE year = vYear + AND week = vWeek + GROUP BY buyer, family + ) sub + ORDER BY percentage DESC; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `weekWaste__` */; +/*!50003 SET @saved_cs_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 `weekWaste__`() +BEGIN + DECLARE vWeek INT; + DECLARE vYear INT; + + SELECT week, year + INTO vWeek, vYear + FROM vn.time + WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK); + + SELECT *, 100 * dwindle / total AS percentage + FROM ( + SELECT buyer, + SUM(saleTotal) AS total, + SUM(saleWaste) AS dwindle + FROM bs.waste + WHERE year = vYear + AND week = vWeek + GROUP BY buyer + ) sub + ORDER BY percentage DESC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -6963,6 +7236,53 @@ BEGIN SELECT * FROM bs.workerSpeed; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zone_ETD_byTime` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zone_ETD_byTime`() +BEGIN + + SET @m := 0; + + SELECT MAX(hourTheoretical) INTO @h + FROM vn.zoneEstimatedDelivery ze + WHERE ze.remainingVolume ; + + DROP TEMPORARY TABLE IF EXISTS tmpZone; + + CREATE TEMPORARY TABLE tmpZone + SELECT remainingVolume, + hourTheoretical, + @m := @m + minutesLess + HOUR(TIMEDIFF(@h, hourTheoretical)) * 60 + MINUTE(TIMEDIFF(@h, hourTheoretical)) totalMinutes, + @h := hourTheoretical + FROM vn.zoneEstimatedDelivery ze + WHERE ze.remainingVolume + ORDER BY ze.hourTheoretical DESC; + + TRUNCATE bs.zone_ETD_byTime ; + + INSERT INTO bs.zone_ETD_byTime(theorical, practical, m3) + SELECT tz.hourTheoretical, + TIMESTAMPADD(MINUTE, MIN(totalMinutes), tz.hourTheoretical), + sum(tz.remainingVolume) + FROM tmpZone tz + GROUP BY tz.hourTheoretical; + + DROP TEMPORARY TABLE tmpZone; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -7114,6 +7434,24 @@ CREATE TABLE `last_buy` ( UNIQUE KEY `item_id` (`item_id`,`warehouse_id`) USING HASH, KEY `buy_id` (`buy_id`), KEY `warehouse_id` (`warehouse_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `last_buy__` +-- + +DROP TABLE IF EXISTS `last_buy__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `last_buy__` ( + `item_id` int(10) unsigned NOT NULL, + `warehouse_id` smallint(5) unsigned NOT NULL, + `buy_id` int(10) unsigned DEFAULT NULL, + `landing` date DEFAULT NULL, + UNIQUE KEY `item_id` (`item_id`,`warehouse_id`) USING HASH, + KEY `buy_id` (`buy_id`), + KEY `warehouse_id` (`warehouse_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -7659,9 +7997,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -7675,7 +8013,7 @@ BEGIN UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id SET cc.last_refresh = NOW(), - cc.expires = ADDTIME(NOW(), c.lifetime), + cc.expires = LEAST(ADDTIME(NOW(), c.lifetime), util.midNight()), cc.connection_id = NULL WHERE cc.id = v_calc; @@ -7879,9 +8217,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -7902,10 +8240,10 @@ DECLARE vLoadingDelay DECIMAL(5) DEFAULT 2; DECLARE rs CURSOR FOR SELECT Departure - , Sum(pb.m3)/(GREATEST(IFNULL(v.m3,0),IFNULL(dp.minSpeed,0))) AS Horas - , curDate()+(Departure + vLoadingDelay -(Sum(pb.m3)/(GREATEST(IFNULL(v.m3,0),IFNULL(minSpeed,0))))/24) AS InicioPreparacion + , Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(dp.minSpeed,0))) AS Horas + , curDate()+(Departure + vLoadingDelay -(Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(minSpeed,0))))/24) AS InicioPreparacion FROM tmp.production_buffer pb - LEFT JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id + LEFT JOIN vn.lastHourProduction lhp ON lhp.warehouseFk = pb.warehouse_id LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = CURDATE() WHERE pb.Fecha = CURDATE() AND pb.graphCategory > 1 @@ -8614,6 +8952,7 @@ CREATE TABLE `deliveryInformation` ( `supplyResponseID` int(11) DEFAULT NULL, `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`ID`), + UNIQUE KEY `deliveryInformation_UN` (`Location`,`LatestDeliveryDateTime`,`FirstOrderDateTime`,`LatestOrderDateTime`,`supplyResponseID`), KEY `fgbSupplyResponse_idx` (`supplyResponseID`), KEY `fgbSupplyResponse_idx2` (`FirstOrderDateTime`), KEY `fgbSupplyResponse_idx3` (`LatestOrderDateTime`) USING BTREE, @@ -8622,6 +8961,25 @@ CREATE TABLE `deliveryInformation` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `di` +-- + +DROP TABLE IF EXISTS `di`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `di` ( + `ID` int(11) NOT NULL DEFAULT '0', + `Location` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `LatestDeliveryDateTime` datetime DEFAULT NULL, + `FirstOrderDateTime` datetime DEFAULT NULL, + `LatestOrderDateTime` datetime DEFAULT NULL, + `supplyResponseID` int(11) DEFAULT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `di_UN` (`Location`,`LatestDeliveryDateTime`,`FirstOrderDateTime`,`LatestOrderDateTime`,`supplyResponseID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `ekt` -- @@ -8700,6 +9058,28 @@ CREATE TABLE `ektEntryAssign__` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `errorList` +-- + +DROP TABLE IF EXISTS `errorList`; +/*!50001 DROP VIEW IF EXISTS `errorList`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `errorList` ( + `id` tinyint NOT NULL, + `name` tinyint NOT NULL, + `longName` tinyint NOT NULL, + `quantity` tinyint NOT NULL, + `stock` tinyint NOT NULL, + `error` tinyint NOT NULL, + `deliveryInformationID` tinyint NOT NULL, + `supplyResponseID` tinyint NOT NULL, + `OrderTradeLineDateTime` tinyint NOT NULL, + `EndUserPartyGLN` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `exchange` -- @@ -9149,6 +9529,7 @@ CREATE TABLE `putOrder` ( `isOrderProcessed` tinyint(4) DEFAULT NULL, `error` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `barcode` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `orderTradelineItemID_UNIQUE` (`orderTradelineItemID`), KEY `deliveryInformationID_idx` (`deliveryInformationID`), @@ -9257,11 +9638,16 @@ BEGIN JOIN vn.item i ON i.id = s.itemFk JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= CURDATE() - AND i.supplyResponseFk = NEW.supplyResponseID; + AND i.supplyResponseFk = NEW.supplyResponseID + LIMIT 1; UPDATE vn.sale s + JOIN vn.ticket t ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID SET s.quantity = 0 - WHERE s.id = vSaleFk; + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= CURDATE() + AND i.supplyResponseFk = NEW.supplyResponseID; INSERT INTO vn.mail (sender, `subject`, body) SELECT IF(u.id IS NOT NULL AND c.email IS NOT NULL, @@ -9277,7 +9663,7 @@ BEGIN FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.`client` c ON c.id = t.clientFk - LEFT JOIN account.user u ON u.id= c.salesPersonFk AND u.name IN ('ruben', 'ismael') + LEFT JOIN account.user u ON u.id= c.salesPersonFk AND u.name IN ('ruben', 'ismaelalcolea') WHERE s.id = vSaleFk; END IF; @@ -9433,6 +9819,32 @@ CREATE TABLE `supplyResponse` ( /*!50003 SET @saved_cs_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 supplyResponse_BU +BEFORE UPDATE +ON supplyResponse FOR EACH ROW +BEGIN + + + INSERT INTO edi.supplyResponseLog (supplyResponseFk, NumberOfUnitsOld, NumberOfUnitsNew, lastVMPUpdate) + SELECT OLD.ID, OLD.NumberOfUnits, NEW.NumberOfUnits, v.dateTimeLastSync + FROM edi.VMPSettings v + WHERE v.VMPID = OLD.vmpID; + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_general_ci */ ; @@ -9458,6 +9870,26 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Table structure for table `supplyResponseLog` +-- + +DROP TABLE IF EXISTS `supplyResponseLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `supplyResponseLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `supplyResponseFk` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `NumberOfUnitsOld` int(11) DEFAULT NULL, + `NumberOfUnitsNew` int(11) DEFAULT NULL, + `lastVMPUpdate` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `supplyResponseLog_FK` (`supplyResponseFk`), + CONSTRAINT `supplyResponseLog_FK` FOREIGN KEY (`supplyResponseFk`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `type` -- @@ -9598,6 +10030,45 @@ BEGIN FROM supplyResponse sr LEFT JOIN edi.deliveryInformation di ON sr.ID = di.supplyResponseID WHERE di.LatestOrderDateTime < vOneWeekAgo OR di.ID IS NULL; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `deliveryInformation_Delete` */; +/*!50003 SET @saved_cs_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 `deliveryInformation_Delete`() +BEGIN + + DECLARE vID INT; + DECLARE vGap INT DEFAULT 100; + DECLARE vTope INT; + + SELECT MIN(ID), MAX(ID) + INTO vID, vTope + FROM edi.deliveryInformation; + + WHILE vID <= vTope DO + + SET vID = vID + vGap; + + DELETE + FROM edi.deliveryInformation + WHERE ID < vID + AND EarliestDespatchDateTime IS NULL; + + END WHILE; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -9702,28 +10173,43 @@ BEGIN DECLARE vIsLot BOOLEAN; DECLARE vForceToPacking INT DEFAULT 2; DECLARE vEntryFk INT; + DECLARE vHasToChangePackagingFk BOOLEAN; -- Carga los datos necesarios del EKT - SELECT ref, qty, package, putOrderFk INTO vRef, vQty, vPackage, vPutOrderFk + SELECT ref, qty, package, putOrderFk, i2.id INTO vRef, vQty, vPackage, vPutOrderFk, vItem FROM ekt e LEFT JOIN item i ON e.ref = i.id - WHERE e.id = vSelf; + LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk + LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID + WHERE e.id = vSelf + LIMIT 1; -- Asigna la entrada SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; -- Inserta el cubo si no existe - IF vPackage = 800 - THEN - SET vPackage = 800 + vQty; + IF vPackage = 800 THEN + + SET vHasToChangePackagingFk = TRUE; + + IF vItem THEN + + SELECT vn.item_getPackage(vItem) INTO vPackage ; + + ELSE + + SET vPackage = 8000 + vQty; - INSERT IGNORE INTO vn2008.Cubos SET - Id_Cubo = vPackage, - x = 7200 / vQty, - y = 1; + INSERT IGNORE INTO vn.packaging(id, width, `depth`) + SELECT vPackage, vc.ccLength / vQty, vc.ccWidth + FROM vn.volumeConfig vc; + + END IF; + ELSE + INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z) SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10) FROM bucket WHERE bucket_id = vPackage; @@ -9745,6 +10231,7 @@ BEGIN JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID WHERE po.id = vPutOrderFk LIMIT 1; + END IF; INSERT IGNORE INTO item_track SET @@ -9808,14 +10295,13 @@ BEGIN ,@pac * e.qty ,vForceToPacking ,s.`name` - ,IFNULL(b.packageFk, e.package) + ,IF(vHasToChangePackagingFk OR ISNULL(b.packageFk), vPackage, b.packageFk) ,i.density * (vn.item_getVolume(i.id, IFNULL(b.packageFk, e.package)) / 1000000) FROM edi.ekt e LEFT JOIN vn.buy b ON b.id = vBuy LEFT JOIN vn.item i ON i.id = b.itemFk LEFT JOIN vn.supplier s ON e.pro = s.id - JOIN vn2008.config cfg - + JOIN vn2008.config cfg WHERE e.id = vSelf LIMIT 1; @@ -9827,6 +10313,177 @@ BEGIN WHERE ektFk = vSelf; CALL vn.buy_recalcPrices(); + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ekt_load_beta` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 `ekt_load_beta`(IN `vSelf` INT) +BEGIN + DECLARE vRef INT; + DECLARE vBuy INT; + DECLARE vItem INT; + DECLARE vQty INT; + DECLARE vPackage INT; + DECLARE vPutOrderFk INT; + DECLARE vIsLot BOOLEAN; + DECLARE vForceToPacking INT DEFAULT 2; + DECLARE vEntryFk INT; + DECLARE vHasToChangePackagingFk BOOLEAN; + + -- Carga los datos necesarios del EKT + + SELECT ref, qty, package, putOrderFk, i2.id INTO vRef, vQty, vPackage, vPutOrderFk, vItem + FROM ekt e + LEFT JOIN item i ON e.ref = i.id + LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk + LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID + WHERE e.id = vSelf + LIMIT 1; + + SELECT vItem; + + -- Asigna la entrada + SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; + + -- Inserta el cubo si no existe + + IF vPackage = 800 THEN + + SET vHasToChangePackagingFk = TRUE; + + IF vItem THEN + + SELECT vn.item_getPackage(vItem) INTO vPackage ; + + ELSE + + SET vPackage = 8000 + vQty; + + INSERT IGNORE INTO vn.packaging(id, width, `depth`) + SELECT vPackage, vc.ccLength / vQty, vc.ccWidth + FROM vn.volumeConfig vc; + + END IF; + + ELSE + + INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z) + SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10) + FROM bucket WHERE bucket_id = vPackage; + + IF ROW_COUNT() > 0 + THEN + INSERT INTO vn2008.mail SET + `subject` = 'Cubo añadido', + `text` = CONCAT('Se ha añadido el cubo: ', vPackage), + `to` = 'ekt@verdnatura.es'; + END IF; + END IF; + + -- Si es una compra de Floramondo obtiene el articulo + IF vPutOrderFk THEN + + SELECT i.id INTO vItem + FROM edi.putOrder po + JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID + WHERE po.id = vPutOrderFk + LIMIT 1; + + END IF; + + INSERT IGNORE INTO item_track SET + item_id = vRef; + + IF IFNULL(vItem,0) = 0 THEN + -- Intenta obtener el artículo en base a los atributos holandeses + + SELECT b.id, b.itemFk INTO vBuy, vItem + FROM edi.ekt e + JOIN edi.item_track t ON t.item_id = e.ref + LEFT JOIN edi.ekt l ON l.ref = e.ref + LEFT JOIN vn.buy b ON b.ektFk = l.id + JOIN vn2008.config cfg + WHERE e.id = vSelf + AND l.id != vSelf + AND b.itemFk != cfg.generic_item + AND IF(t.s1, l.s1 = e.s1, TRUE) + AND IF(t.s2, l.s2 = e.s2, TRUE) + AND IF(t.s3, l.s3 = e.s3, TRUE) + AND IF(t.s4, l.s4 = e.s4, TRUE) + AND IF(t.s5, l.s5 = e.s5, TRUE) + AND IF(t.s6, l.s6 = e.s6, TRUE) + AND IF(t.kop, l.kop = e.kop, TRUE) + AND IF(t.pac, l.pac = e.pac, TRUE) + AND IF(t.cat, l.cat = e.cat, TRUE) + AND IF(t.ori, l.ori = e.ori, TRUE) + AND IF(t.pro, l.pro = e.pro, TRUE) + AND IF(t.sub, l.sub = e.sub, TRUE) + AND IF(t.package, l.package = e.package, TRUE) + AND IF(t.item, l.item = e.item, TRUE) + AND b.itemFk < 170000 + ORDER BY l.now DESC, b.id ASC LIMIT 1; + + END IF; + + + INSERT INTO vn.buy + ( + entryFk + ,ektFk + ,buyingValue + ,itemFk + ,stickers + ,packing + ,`grouping` + ,quantity + ,groupingMode + ,producer + ,packageFk + ,weight + ) + SELECT + vEntryFk + ,vSelf + ,(@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue + ,IFNULL(vItem, cfg.generic_item) itemFk + ,e.qty stickers + ,@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing + ,IFNULL(b.`grouping`, e.pac) + ,@pac * e.qty + ,vForceToPacking + ,s.`name` + ,IF(vHasToChangePackagingFk OR ISNULL(b.packageFk), vPackage, b.packageFk) + ,i.density * (vn.item_getVolume(i.id, IFNULL(b.packageFk, e.package)) / 1000000) + FROM edi.ekt e + LEFT JOIN vn.buy b ON b.id = vBuy + LEFT JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.supplier s ON e.pro = s.id + JOIN vn2008.config cfg + WHERE e.id = vSelf + LIMIT 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; + + CREATE TEMPORARY TABLE tmp.buyRecalc + SELECT buy.id + FROM vn.buy + WHERE ektFk = vSelf; + + CALL vn.buy_recalcPrices(); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -10049,7 +10706,7 @@ proc: BEGIN DECLARE vSupplyResponseFk INT; DECLARE vLastInserted DATETIME; DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 100000; + DECLARE vMaxNewItems INT DEFAULT 10000; DECLARE vStartingTime DATETIME; DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; @@ -10098,10 +10755,12 @@ proc: BEGIN ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, NumberOfUnits DESC) t JOIN edi.item_groupToOffer igo ON igo.group_code = t.group_id LEFT JOIN edi.item_defaultType idt ON idt.item_id = t.Item_ArticleCode - GROUP BY Item_ArticleCode, s1, s2, s3, s4, s5, s6, company_name, Quality, NumberOfItemsPerCask, EmbalageCode, Price, PictureReference + GROUP BY t.srId + -- GROUP BY Item_ArticleCode, s1, s2, s3, s4, s5, s6, company_name, Quality, NumberOfItemsPerCask, EmbalageCode, Price, PictureReference ; - -- -- select now(),'Antes de crear edi.offer'; + -- select now(),'Antes de crear edi.offer'; + DROP TEMPORARY TABLE IF EXISTS edi.offer; CREATE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`)) ENGINE = MEMORY SELECT so.*, ev1.type_description s1Value, ev2.type_description s2Value, ev3.type_description s3Value, @@ -10148,15 +10807,19 @@ proc: BEGIN AND i.EmbalageCode <=> o.EmbalageCode AND i.quality <=> o.Quality JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN vn.sale s ON s.itemFk = i.id + LEFT JOIN vn.ticket t ON t.id = s.ticketFk AND t.shipped > TIMESTAMPADD(WEEK, -1, CURDATE()) LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN deliveryInformation di ON di.supplyResponseID = sr.ID + LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk AND po.OrderTradeLineDateTime > TIMESTAMPADD(WEEK, -1, CURDATE()) SET i.supplyResponseFk = o.srID WHERE ( sr.ID IS NULL OR sr.NumberOfUnits = 0 OR di.LatestOrderDateTime < NOW() OR di.ID IS NULL) AND it.isInventory - ; + AND t.id IS NULL + AND po.id IS NULL; -- select now(),'Antes de crear ITO'; DROP TEMPORARY TABLE IF EXISTS itemToInsert; CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY @@ -10201,21 +10864,24 @@ proc: BEGIN numberOfItemsPerCask, embalageCode, quality, - isFloramondo) - SELECT itemFk, - product_name, - product_name, - company_name, - expenseFk, - itemTypeFk, - intrastatFk, - originFk, - `srId`, - NumberOfItemsPerCask, - EmbalageCode, - Quality, - TRUE - FROM itemToInsert; + isFloramondo, + inkFk) + SELECT iti.itemFk, + iti.product_name, + iti.product_name, + iti.company_name, + iti.expenseFk, + iti.itemTypeFk, + iti.intrastatFk, + iti.originFk, + iti.`srId`, + iti.NumberOfItemsPerCask, + iti.EmbalageCode, + iti.Quality, + TRUE, + ii.inkFk + FROM itemToInsert iti + LEFT JOIN vn.itemInk ii ON ii.longName = iti.product_name; INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) SELECT i.id, PictureReference @@ -10442,430 +11108,6 @@ proc: BEGIN INSERT INTO edi.log(tableName, fieldName,fieldValue) VALUES('floramondo_offerRefresh','Tiempo de proceso',TIMEDIFF(NOW(),vStartingTime)); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `floramondo_offerRefresh_beta` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 `floramondo_offerRefresh_beta`() -proc: BEGIN - - DECLARE vLanded DATETIME; - DECLARE done INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 100000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - DECLARE vLastUpdated DATETIME DEFAULT now(); - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SET vStartingTime = NOW(); - - -- CALL vn.clean_logiflora(); - - -- Refresca las fotos de los items existentes, con prioridad baja (0.7 seg) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url,priority) - SELECT i.id, sr.PictureReference , 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - WHERE i.image != edi.imageName(sr.PictureReference) - AND sr.NumberOfUnits > 0; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - DROP TEMPORARY TABLE IF EXISTS tmp; - CREATE TEMPORARY TABLE tmp (INDEX (`Item_ArticleCode`)) ENGINE = MEMORY - SELECT t.*, - IFNULL(idt.itemTypeFk, igo.itemTypeFk) itemTypeFk, - igo.expenseFk , - igo.intrastatFk , - igo.originFk - FROM ( - SELECT * - FROM edi.supplyOffer so - JOIN vn.floramondoConfig fc - WHERE so.supplyResponseUpdated > fc.LastUpdated - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, NumberOfUnits DESC) t - JOIN edi.item_groupToOffer igo ON igo.group_code = t.group_id - LEFT JOIN edi.item_defaultType idt ON idt.item_id = t.Item_ArticleCode - GROUP BY Item_ArticleCode, s1, s2, s3, s4, s5, s6, company_name, Quality, NumberOfItemsPerCask, EmbalageCode, Price, PictureReference - ; - - -- -- select now(),'Antes de crear edi.offer'; - DROP TEMPORARY TABLE IF EXISTS edi.offer; - CREATE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`)) ENGINE = MEMORY - SELECT so.*, ev1.type_description s1Value, ev2.type_description s2Value, ev3.type_description s3Value, - ev4.type_description s4Value, ev5.type_description s5Value, ev6.type_description s6Value, - eif1.feature ef1, eif2.feature ef2, eif3.feature ef3, eif4.feature ef4, eif5.feature ef5, eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN deliveryInformation di ON di.supplyResponseID = sr.ID - SET i.supplyResponseFk = o.srID - WHERE ( sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < NOW() - OR di.ID IS NULL) - AND it.isInventory - ; - -- select now(),'Antes de crear ITO'; - DROP TEMPORARY TABLE IF EXISTS itemToInsert; - CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF done THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item( id, - `name`, - longName, - subName, - expenceFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT itemFk, - product_name, - product_name, - company_name, - expenseFk, - itemTypeFk, - intrastatFk, - originFk, - `srId`, - NumberOfItemsPerCask, - EmbalageCode, - Quality, - TRUE - FROM itemToInsert; - - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL; - - INSERT INTO edi.log(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Inserta los tags sólo en los articulos nuevos - - -- desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId`; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId`; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId`; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s1Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s2Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s3Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s4Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s5Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s6Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, ink.name, 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - JOIN edi.`type` tp ON tp.type_id = f.feature_type_id AND tp.`description` = 'Hoofdkleur 1' - JOIN vn.ink ON ink.dutchCode = f.feature_value; - - UPDATE vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId` - JOIN vn.packaging p ON p.id LIKE ii.EmbalageCode AND hasCompressionVariations - JOIN vn.itemTag diameter ON diameter.itemFk = i.id - JOIN vn.tag tDiameter ON tDiameter.overwrite = 'diameter' AND tDiameter.id = diameter.tagFk - JOIN vn.itemTag size ON size.itemFk = i.id - JOIN vn.tag tSize ON tSize.overwrite = 'size' AND tSize.id = size.tagFk - SET i.`compression` = - (PI() * POW(diameter.`value`/ 2, 2) * size.`value`) - / - ((p.width * p.depth * p.height) / ii.NumberOfItemsPerCask); - - DROP TABLE IF EXISTS tmp.item; - CREATE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - SET @isTriggerDisabled = FALSE; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF(fc.MaxLatestOrderHour > HOUR(NOW()), CURDATE(), TIMESTAMPADD(DAY,1,CURDATE())); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - - -- Elimina la oferta obsoleta - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.putOrder po ON b.deliveryFk = po.deliveryInformationID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (di.LatestOrderDateTime < NOW() - OR sr.ID IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.floramondo_getEntry(TIMESTAMPADD(DAY,travellingDays,vLanded), warehouseFk); - - IF vLanded IS NOT NULL THEN - -- actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask OR b.buyingValue <> o.price); - - -- Se eliminan las ofertas ya incluidas en las entradas - DELETE o - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN vn.buy b ON i.id = b.itemFk - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk; - - -- Se inserta el resto - SET vLastInserted := NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy(entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packageFk, - deliveryFk) - - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask as quantity, - o.Price, - o.NumberOfUnits as etiquetas, - o.NumberOfItemsPerCask as packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask as `grouping`, - 2, -- Obliga al Packing - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN vn.itemType it ON it.id = i.typeFk - JOIN edi.warehouseFloramondo wf ON wf.isFV = it.isFV OR wf.isFV IS NULL - JOIN vn.packaging p ON p.id LIKE o.embalageCode; -- llevar esta linea i mirar de crear els packages a temps real - - DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; - - CREATE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - DROP TABLE tmp.item; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - INSERT INTO edi.log(tableName, fieldName,fieldValue) - VALUES('floramondo_offerRefresh','Tiempo de proceso',TIMEDIFF(NOW(),vStartingTime)); - - UPDATE vn.floramondoConfig SET LastUpdated = vLastUpdated; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -17137,10 +17379,13 @@ CREATE TABLE `business` ( `date_end` date DEFAULT NULL, `workerBusiness` longtext, `reasonEndFk` int(11) DEFAULT NULL, + `occupationCodeFk` varchar(1) DEFAULT NULL, PRIMARY KEY (`business_id`), KEY `business_client` (`client_id`), KEY `bussiness_provider` (`provider_id`), + KEY `business_occupationCodeFk` (`occupationCodeFk`), CONSTRAINT `business_client` FOREIGN KEY (`client_id`) REFERENCES `profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `business_occupationCodeFk` FOREIGN KEY (`occupationCodeFk`) REFERENCES `vn`.`occupationCode` (`code`) ON UPDATE CASCADE, CONSTRAINT `bussiness_provider` FOREIGN KEY (`provider_id`) REFERENCES `profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -18098,179 +18343,6 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; --- --- Table structure for table `movContaCopia` --- - -DROP TABLE IF EXISTS `movContaCopia`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `movContaCopia` ( - `OrdenMovimientos` int(11) NOT NULL DEFAULT '0', - `MovPosicion` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Ejercicio` smallint(6) NOT NULL, - `CodigoEmpresa` smallint(6) NOT NULL, - `Asiento` int(11) NOT NULL, - `CargoAbono` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoCuenta` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Contrapartida` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `FechaAsiento` datetime NOT NULL, - `TipoDocumento` varchar(6) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `DocumentoConta` varchar(9) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Comentario` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `ImporteAsiento` decimal(28,10) NOT NULL, - `CodigoDiario` smallint(6) NOT NULL, - `CodigoCanal` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoActividad` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `FechaVencimiento` datetime NOT NULL, - `NumeroPeriodo` smallint(6) NOT NULL, - `CodigoUsuario` smallint(6) NOT NULL, - `FechaGrabacion` datetime NOT NULL, - `TipoEntrada` varchar(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoDepartamento` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoSeccion` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoDivisa` varchar(3) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `ImporteCambio` decimal(28,10) NOT NULL, - `ImporteDivisa` decimal(28,10) NOT NULL, - `FactorCambio` decimal(28,10) NOT NULL, - `CodigoProyecto` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `LibreN1` int(11) NOT NULL, - `LibreN2` int(11) NOT NULL, - `LibreA1` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `LibreA2` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdDelegacion` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `MovCartera` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `IdProcesoIME` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `TipoCarteraIME` smallint(6) NOT NULL, - `TipoAnaliticaIME` smallint(6) NOT NULL, - `StatusTraspasadoIME` tinyint(4) NOT NULL, - `TipoImportacionIME` tinyint(4) NOT NULL, - `BaseIva1` decimal(28,10) NOT NULL, - `PorBaseCorrectora1` decimal(28,10) NOT NULL, - `PorIva1` decimal(28,10) NOT NULL, - `CuotaIva1` decimal(28,10) NOT NULL, - `PorRecargoEquivalencia1` decimal(28,10) NOT NULL, - `RecargoEquivalencia1` decimal(28,10) NOT NULL, - `CodigoTransaccion1` tinyint(4) NOT NULL, - `BaseIva2` decimal(28,10) NOT NULL, - `PorBaseCorrectora2` decimal(28,10) NOT NULL, - `PorIva2` decimal(28,10) NOT NULL, - `CuotaIva2` decimal(28,10) NOT NULL, - `PorRecargoEquivalencia2` decimal(28,10) NOT NULL, - `RecargoEquivalencia2` decimal(28,10) NOT NULL, - `CodigoTransaccion2` tinyint(4) NOT NULL, - `BaseIva3` decimal(28,10) NOT NULL, - `PorBaseCorrectora3` decimal(28,10) NOT NULL, - `PorIva3` decimal(28,10) NOT NULL, - `CuotaIva3` decimal(28,10) NOT NULL, - `PorRecargoEquivalencia3` decimal(28,10) NOT NULL, - `RecargoEquivalencia3` decimal(28,10) NOT NULL, - `CodigoTransaccion3` tinyint(4) NOT NULL, - `baseIva4` decimal(28,10) NOT NULL, - `PorBaseCorrectora4` decimal(28,10) NOT NULL, - `PorIva4` decimal(28,10) NOT NULL, - `CuotaIva4` decimal(28,10) NOT NULL, - `PorRecargoEquivalencia4` decimal(28,10) NOT NULL, - `RecargoEquivalencia4` decimal(28,10) NOT NULL, - `CodigoTransaccion4` tinyint(4) NOT NULL, - `Año` smallint(6) NOT NULL, - `Serie` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Factura` int(11) NOT NULL, - `SuFacturaNo` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `FechaFactura` datetime NOT NULL, - `ImporteFactura` decimal(28,10) NOT NULL, - `TipoFactura` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoCuentaFactura` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CifDni` varchar(13) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Nombre` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `CodigoRetencion` smallint(6) NOT NULL, - `BaseRetencion` decimal(28,10) NOT NULL, - `PorRetencion` decimal(28,10) NOT NULL, - `ImporteRetencion` decimal(28,10) NOT NULL, - `AbonoIva` smallint(6) NOT NULL, - `CodigoActividadF` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Intracomunitaria` smallint(6) NOT NULL, - `CodigoTerritorio` smallint(6) NOT NULL, - `SiglaNacion` varchar(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `RetencionInformativa` smallint(6) NOT NULL, - `EjercicioFacturaOriginal` smallint(6) NOT NULL, - `SerieFacturaOriginal` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `NumeroFacturaOriginal` int(11) NOT NULL, - `EjercicioFactura` smallint(6) NOT NULL, - `CobroPagoRetencion` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `FechaOperacion` datetime NOT NULL, - `Exclusion347` smallint(6) NOT NULL, - `MovIdentificadorIME` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Previsiones` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `MantenerAsiento` tinyint(4) NOT NULL, - `OrdenMovIME` smallint(6) NOT NULL, - `Metalico347` smallint(6) NOT NULL, - `ClaveOperacionFactura_` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `SerieAgrupacion_` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `NumeroFacturaInicial_` int(11) NOT NULL, - `NumeroFacturaFinal_` int(11) NOT NULL, - `IdAsientoExterno` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdDiarioExterno` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdFacturaExterno` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdMovimiento` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdCuadre` smallint(6) NOT NULL, - `FechaCuadre` datetime NOT NULL, - `TipoCuadre` varchar(4) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `AgrupacionCuadre` int(11) NOT NULL, - `StatusSaldo` smallint(6) NOT NULL, - `StatusConciliacion` smallint(6) NOT NULL, - `CodigoConciliacion` int(11) NOT NULL, - `FechaConciliacion` datetime NOT NULL, - `TipoConciliacion` smallint(6) NOT NULL, - `IndicadorContaBanco` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion3` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion4` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion5` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion6` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion7` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion8` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion9` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion2` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Descripcion1` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `Punteo1` smallint(6) NOT NULL, - `Punteo9` smallint(6) NOT NULL, - `Punteo8` smallint(6) NOT NULL, - `Punteo7` smallint(6) NOT NULL, - `Punteo6` smallint(6) NOT NULL, - `Punteo5` smallint(6) NOT NULL, - `Punteo4` smallint(6) NOT NULL, - `Punteo3` smallint(6) NOT NULL, - `Punteo2` smallint(6) NOT NULL, - `CodigoIva1` smallint(6) NOT NULL, - `CodigoIva2` smallint(6) NOT NULL, - `CodigoIva3` smallint(6) NOT NULL, - `CodigoIva4` smallint(6) NOT NULL, - `CriterioIva` tinyint(4) NOT NULL, - `FechaMaxVencimiento` datetime NOT NULL, - `TipoCriterioCaja` tinyint(4) NOT NULL, - `MovFacturaOrigenIME` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdFacturaExternoFinal` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdFacturaExternoInicial` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IdFacturaExternoOriginal` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `NumFacturasExternoAgrupacion` int(11) NOT NULL, - `CodigoMedioCobro` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `MedioCobro` varchar(31) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `IvaDeducible1` smallint(6) NOT NULL DEFAULT '1', - `IvaDeducible2` smallint(6) NOT NULL DEFAULT '1', - `IvaDeducible3` smallint(6) NOT NULL DEFAULT '1', - `IvaDeducible4` smallint(6) NOT NULL DEFAULT '1', - `TipoRectificativa` smallint(6) NOT NULL, - `FechaFacturaOriginal` datetime NOT NULL, - `BaseImponibleOriginal` decimal(28,10) NOT NULL, - `CuotaIvaOriginal` decimal(28,10) NOT NULL, - `ClaseAbonoRectificativas` smallint(6) NOT NULL, - `RecargoEquivalenciaOriginal` decimal(28,10) NOT NULL, - `ObjetoFactura` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `enlazado` tinyint(1) NOT NULL DEFAULT '0', - PRIMARY KEY (`OrdenMovimientos`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `pgcToSage` -- @@ -18363,11 +18435,11 @@ TRUNCATE TABLE clientesProveedores; Nacion, Telefono, Telefono2, - CodigoTransaccion, + CodigoTransaccion, CodigoRetencion, Email1, iban) - SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest) CodigoEmpresa, + SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest) CodigoEmpresa, 'C' ClienteOProveedor, cl.id CodigoClienteProveedor, cl.socialName RazonSocial, @@ -18376,25 +18448,25 @@ TRUNCATE TABLE clientesProveedores; cl.accountingAccount CodigoCuenta, TRIM(IF(co.code = LEFT(cl.fi,2), MID(cl.fi,3, length(cl.fi)-1), cl.fi)) AS CifDni, IF(sn.NacionCEE,TRIM(CONCAT(co.code, IF(co.code = LEFT(cl.fi,2), MID(cl.fi,3, length(cl.fi)-1), cl.fi))) , "")AS CifEuropeo, - cl.postcode CodigoPostal, + cl.postcode CodigoPostal, cl.city Municipio, sp.CodigoProvincia CodigoProvincia, p.name Provincia, - IF (sn.SiglaNacion = "XB",IF(sp.CodigoProvincia IN (51,52), 22, IF (sp.CodigoProvincia IN (35,38), 21, sn.CodigoNacion)), sn.CodigoNacion) CodigoNacion, + IF (sn.SiglaNacion = "XB",IF(sp.CodigoProvincia IN (51,52), 22, IF (sp.CodigoProvincia IN (35,38), 21, sn.CodigoNacion)), sn.CodigoNacion) CodigoNacion, IF (sn.SiglaNacion = "XB",IF(sp.CodigoProvincia IN (51,52), "XC",IF (sp.CodigoProvincia IN (35,38), "XB", sn.SiglaNacion)), sn.SiglaNacion) SiglaNacion, IF((cl.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F') PersonaFisicaJuridica, IF((co.id = 1 OR co.id = 30) OR (co.isUeeMember = 1 AND NOT cl.isVies) , 1, IF((co.isUeeMember = 1 AND cl.isVies), 2, 4)) TipoDocumentoPersona, - -- IF(cl.isEqualizated, 'R', IF ((cl.isVies AND cl.countryFk <> 1) OR (NOT co.isUeeMember),'E','I'))AS CodigoIva, + -- IF(cl.isEqualizated, 'R', IF ((cl.isVies AND cl.countryFk <> 1) OR (NOT co.isUeeMember),'E','I'))AS CodigoIva, cl.taxTypeSageFk CodigoIva, - IF(sn.SiglaNacion = "XB", IF(sp.CodigoProvincia IN (51,52), "CEUTA Y MELILLA", IF (sp.CodigoProvincia IN (35,38), "ISLAS CANARIAS",sn.Nacion)) , sn.Nacion) Nacion, + IF(sn.SiglaNacion = "XB", IF(sp.CodigoProvincia IN (51,52), "CEUTA Y MELILLA", IF (sp.CodigoProvincia IN (35,38), "ISLAS CANARIAS",sn.Nacion)) , sn.Nacion) Nacion, cl.phone Telefono, cl.mobile Telefono2, cl.transactionTypeSageFk CodigoTransaccion, - 0 CodigoRetencion, - SUBSTR(cl.email, 1, LOCATE(',', CONCAT(cl.email,','))-1) Email1, + 0 CodigoRetencion, + SUBSTR(cl.email, 1, LOCATE(',', CONCAT(cl.email,','))-1) Email1, cl.iban iban - FROM vn.client cl + FROM vn.client cl JOIN vn2008.v_xsubclien ON v_xsubclien.Id_Cliente = cl.id LEFT JOIN vn.country co ON co.id = cl.countryFk LEFT JOIN sage.Naciones sn ON sn.countryFk = co.id @@ -18411,23 +18483,23 @@ TRUNCATE TABLE clientesProveedores; s.street Domicilio, s.account CodigoCuenta, TRIM(IF(co.code = LEFT(s.nif,2), MID(s.nif,3, length(s.nif)-1), s.nif)) CifDni, - IF(sn.NacionCEE,TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif,2), MID(s.nif,3, length(s.nif)-1), s.nif))), "") AS CifEuropeo, + IF(sn.NacionCEE,TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif,2), MID(s.nif,3, length(s.nif)-1), s.nif))), "") AS CifEuropeo, s.postCode CodigoPostal, s.city Municipio, sp.CodigoProvincia CodigoProvincia, p.name Provincia, sn.CodigoNacion CodigoNacion, sn.SiglaNacion SiglaNacion, - IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F') PersonaFisicaJuridica, + IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F') PersonaFisicaJuridica, IF((co.id = 1 OR co.id = 30),1,IF((co.isUeeMember = 1), 2, 4)) TipoDocumentoPersona, -- 'I' CodigoIva, - s.taxTypeSageFk CodigoIva, + s.taxTypeSageFk CodigoIva, sn.Nacion Nacion, con.Telefono Telefono, con.Movil Telefono2, - s.transactionTypeSageFk CodigoTransaccion, + s.transactionTypeSageFk CodigoTransaccion, s.withholdingSageFk CodigoRetencion, - SUBSTR(con.email,1,(COALESCE(NULLIF(LOCATE(',', con.email), 0), 99) - 1)) Email1, + SUBSTR(con.email,1,(COALESCE(NULLIF(LOCATE(',', con.email), 0), 99) - 1)) Email1, sa.iban iban FROM vn.supplier s JOIN vn2008.v_xsubprov xsp ON xsp.proveedor_id = s.id -- Proveedores activos los últimos 3 meses @@ -18463,208 +18535,208 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `movContaAdd`() BEGIN /* Copia en movConta los asientos de XDiario para que luego los importe el proceso automático que hay en SQL Server - */ + */ DECLARE vDated DATE; - SELECT CONCAT(YEAR(CURDATE()), "-01-01") INTO vDated; + SELECT CONCAT(YEAR(CURDATE()), "-01-01") INTO vDated; TRUNCATE XDiario_movConta_IVA; DELETE FROM movConta WHERE enlazadoSage = FALSE AND Asiento <> 1 ; - CALL clientesProveedoresAdd; - CALL planCuentasPgcAdd; - CALL XDiario_movConta_IVA_InvoiceOutAdd_Manager; - CALL XDiario_movConta_IVA_InvoiceInAdd_Manager; + CALL clientesProveedoresAdd; + CALL planCuentasPgcAdd; + CALL XDiario_movConta_IVA_InvoiceOutAdd_Manager; + CALL XDiario_movConta_IVA_InvoiceInAdd_Manager; INSERT INTO movConta( - TipoEntrada, -- VARCHAR(2) - Ejercicio, -- Año - CodigoEmpresa, -- ENT(2) - Asiento, -- LONG(4), nº ASIENTO - CargoAbono, -- VARCHAR(1) "D" debe ó "H" haber - CodigoCuenta, -- VARCHAR(15) partida contable - Contrapartida, -- VARCHAR(15) partida contable - FechaAsiento, -- FECHA(8) - Comentario, -- VARCHAR(40) - ImporteAsiento, -- DOBLE(19) - NumeroPeriodo, -- ENT(2) "-1" Al informar este valor se calcula automát. A partir de la fecha de asiento - FechaGrabacion, -- FECHA(8) - CodigoDivisa, -- VARCHAR(3) - ImporteCambio, -- DOBLE(19) - ImporteDivisa, -- DOBLE(19) - FactorCambio, -- DOBLE(19) - IdProcesoIME, -- GUID(16) - TipoCarteraIME, -- ENT(2) "0" para que no genere cartera - TipoAnaliticaIME, -- ENT(2) - StatusTraspasadoIME, -- BYTE "0" para dejar como no importado aún - TipoImportacionIME, -- BYTE "0" Alta "1" Baja - Metalico347, -- ENT(2) - /* ESTOS CAMPOS SOLO SE INFORMAN EN EL CASO DE SER FACTURA */ - BaseIva1, -- DOBLE(19) - PorBaseCorrectora1, -- DOBLE(19) - PorIva1, -- DOBLE(19) - CuotaIva1, -- DOBLE(19) - PorRecargoEquivalencia1,-- DOBLE(19) - RecargoEquivalencia1, -- DOBLE(19) - CodigoTransaccion1, -- BYTE "0" Nacional "1" Intracomunitario "2" Extracomunitario - BaseIva2, - PorBaseCorrectora2, - PorIva2, - CuotaIva2, - PorRecargoEquivalencia2, - RecargoEquivalencia2, - CodigoTransaccion2, - BaseIva3, - PorBaseCorrectora3, - PorIva3, - CuotaIva3, - PorRecargoEquivalencia3, - RecargoEquivalencia3, - CodigoTransaccion3, - BaseIva4, - PorBaseCorrectora4, - PorIva4, - CuotaIva4, - PorRecargoEquivalencia4, - RecargoEquivalencia4, - CodigoTransaccion4, - Año, -- ENT(2) - Serie, -- VARCHAR(10) - Factura, -- LONG(4) - SuFacturaNo, -- VARCHAR(40) - FechaFactura, -- FECHA(8) - ImporteFactura, -- DOBLE(19) - TipoFactura, -- VARCHAR(1) "E" / "R" / "I" - CodigoCuentaFactura, -- VARCHAR(15) cuenta del cliente/proveedor - CifDni, -- VARCHAR(13) - Nombre, -- VARCHAR(35) - CodigoRetencion, -- ENT(2) - BaseRetencion, -- DOBLE(19) - PorRetencion, -- DOBLE(19) - ImporteRetencion, -- DOBLE(19) - SiglaNacion, -- VARCHAR(2) "ES" por defecto - EjercicioFactura, -- ENT(2) - FechaOperacion, -- FECHA(8) - Exclusion347, -- ENT(2) - MantenerAsiento, -- BYTE "-1" mantener "0" Sage asigna nuevo - ClaveOperacionFactura_, -- VARCHAR(1) P(4721000011,4721000021)-I(4721000015-4720000005-4720000006)-D (Rectificativas) - TipoRectificativa, -- ENT(2) - FechaFacturaOriginal, -- FECHA(8) - BaseImponibleOriginal, -- DOBLE(19) - CuotaIvaOriginal, -- DOBLE(19) - ClaseAbonoRectificativas,-- ENT(2) - RecargoEquivalenciaOriginal, -- DOBLE(19) */ - LibreA1, - CodigoIva1, -- ENT(6) - CodigoIva2, -- ENT(6) - CodigoIva3, -- ENT(6) - CodigoIva4, -- ENT(6) + TipoEntrada, -- VARCHAR(2) + Ejercicio, -- Año + CodigoEmpresa, -- ENT(2) + Asiento, -- LONG(4), nº ASIENTO + CargoAbono, -- VARCHAR(1) "D" debe ó "H" haber + CodigoCuenta, -- VARCHAR(15) partida contable + Contrapartida, -- VARCHAR(15) partida contable + FechaAsiento, -- FECHA(8) + Comentario, -- VARCHAR(40) + ImporteAsiento, -- DOBLE(19) + NumeroPeriodo, -- ENT(2) "-1" Al informar este valor se calcula automát. A partir de la fecha de asiento + FechaGrabacion, -- FECHA(8) + CodigoDivisa, -- VARCHAR(3) + ImporteCambio, -- DOBLE(19) + ImporteDivisa, -- DOBLE(19) + FactorCambio, -- DOBLE(19) + IdProcesoIME, -- GUID(16) + TipoCarteraIME, -- ENT(2) "0" para que no genere cartera + TipoAnaliticaIME, -- ENT(2) + StatusTraspasadoIME, -- BYTE "0" para dejar como no importado aún + TipoImportacionIME, -- BYTE "0" Alta "1" Baja + Metalico347, -- ENT(2) + /* ESTOS CAMPOS SOLO SE INFORMAN EN EL CASO DE SER FACTURA */ + BaseIva1, -- DOBLE(19) + PorBaseCorrectora1, -- DOBLE(19) + PorIva1, -- DOBLE(19) + CuotaIva1, -- DOBLE(19) + PorRecargoEquivalencia1,-- DOBLE(19) + RecargoEquivalencia1, -- DOBLE(19) + CodigoTransaccion1, -- BYTE "0" Nacional "1" Intracomunitario "2" Extracomunitario + BaseIva2, + PorBaseCorrectora2, + PorIva2, + CuotaIva2, + PorRecargoEquivalencia2, + RecargoEquivalencia2, + CodigoTransaccion2, + BaseIva3, + PorBaseCorrectora3, + PorIva3, + CuotaIva3, + PorRecargoEquivalencia3, + RecargoEquivalencia3, + CodigoTransaccion3, + BaseIva4, + PorBaseCorrectora4, + PorIva4, + CuotaIva4, + PorRecargoEquivalencia4, + RecargoEquivalencia4, + CodigoTransaccion4, + Año, -- ENT(2) + Serie, -- VARCHAR(10) + Factura, -- LONG(4) + SuFacturaNo, -- VARCHAR(40) + FechaFactura, -- FECHA(8) + ImporteFactura, -- DOBLE(19) + TipoFactura, -- VARCHAR(1) "E" / "R" / "I" + CodigoCuentaFactura, -- VARCHAR(15) cuenta del cliente/proveedor + CifDni, -- VARCHAR(13) + Nombre, -- VARCHAR(35) + CodigoRetencion, -- ENT(2) + BaseRetencion, -- DOBLE(19) + PorRetencion, -- DOBLE(19) + ImporteRetencion, -- DOBLE(19) + SiglaNacion, -- VARCHAR(2) "ES" por defecto + EjercicioFactura, -- ENT(2) + FechaOperacion, -- FECHA(8) + Exclusion347, -- ENT(2) + MantenerAsiento, -- BYTE "-1" mantener "0" Sage asigna nuevo + ClaveOperacionFactura_, -- VARCHAR(1) P(4721000011,4721000021)-I(4721000015-4720000005-4720000006)-D (Rectificativas) + TipoRectificativa, -- ENT(2) + FechaFacturaOriginal, -- FECHA(8) + BaseImponibleOriginal, -- DOBLE(19) + CuotaIvaOriginal, -- DOBLE(19) + ClaseAbonoRectificativas,-- ENT(2) + RecargoEquivalenciaOriginal, -- DOBLE(19) */ + LibreA1, + CodigoIva1, -- ENT(6) + CodigoIva2, -- ENT(6) + CodigoIva3, -- ENT(6) + CodigoIva4, -- ENT(6) IvaDeducible1, -- Entero 2 ((-1)) IvaDeducible2, -- Entero 2 ((-1)) IvaDeducible3, -- Entero 2 ((-1)) IvaDeducible4, -- Entero 2 ((-1))-- ENT(6) - Intracomunitaria -- INT(2) - ) - SELECT 'EN' as TipoEntrada, + Intracomunitaria -- INT(2) + ) + SELECT 'EN' as TipoEntrada, YEAR(x.FECHA) AS Ejercicio, - IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS CodigoEmpresa, -- ENT(2) c.companyCode AS CodigoEmpresa, - x.ASIEN AS Asiento, -- LONG(4), nº ASIENTO - IF(EURODEBE<>0 OR (EURODEBE=0 AND EUROHABER IS NULL),'D','H')AS CargoAbono, -- IF(EURODEBE IS NULL,"H","D") AS CargoAbono, VARCHAR(1) "D" debe ó "H" haber - x.SUBCTA AS CodigoCuenta, -- VARCHAR(15) partida contable - x.CONTRA AS Contrapartida, -- VARCHAR(15) partida contable - x.FECHA AS FechaAsiento, -- FECHA(8) - SUBSTRING(x.CONCEPTO, 1, 40) AS Comentario, -- VARCHAR(40) - IF(x.EURODEBE,x.EURODEBE,x.EUROHABER) AS ImporteAsiento, -- DOBLE(19) - MONTH(x.FECHA) AS NumeroPeriodo, -- ENT(2) "-1" Al informar este valor se calcula automát. A partir de la fecha de asiento - IF( sub2.FECREGCON IS NULL, sub2.FECHA_EX, sub2.FECREGCON) FechaGrabacion, -- FECHA(8) - IF(x.CAMBIO,IFNULL(xmi.CodigoDivisa, sub3.code),'') CodigoDivisa, -- VARCHAR(3) - x.CAMBIO AS ImporteCambio, -- DOBLE(19) - IFNULL(x.DEBEME,x.HABERME) AS ImporteDivisa, -- DOBLE(19) - IF(x.CAMBIO,1,0) AS FactorCambio, -- DOBLE(19) - NULL AS IdProcesoIME, -- GUID(16) - 0 AS TipoCarteraIME, -- ENT(2) "0" para que no genere cartera - 0 AS TipoAnaliticaIME, -- ENT(2) - 0 AS StatusTraspasadoIME, -- BYTE "0" para dejar como no importado aún - 0 AS TipoImportacionIME, -- BYTE "0" Alta "1" Baja - x.METAL as Metalico347, - /* ESTOS CAMPOS SOLO SE INFORMAN EN EL CASO DE SER FACTURA */ - xmi.BaseIva1, -- DOBLE(19) - xmi.PorBaseCorrectora1, -- DOBLE(19) - xmi.PorIva1, -- DOBLE(19) - xmi.CuotaIva1, -- DOBLE(19) - xmi.PorRecargoEquivalencia1,-- DOBLE(19) - xmi.RecargoEquivalencia1, -- DOBLE(19) - xmi.CodigoTransaccion1, -- BYTE "0" Nacional "1" Intracomunitario "2" Extracomunitario - xmi.BaseIva2, - xmi.PorBaseCorrectora2, - xmi.PorIva2, - xmi.CuotaIva2, - xmi.PorRecargoEquivalencia2, - xmi.RecargoEquivalencia2, - xmi.CodigoTransaccion2, - xmi.BaseIva3, - xmi.PorBaseCorrectora3, - xmi.PorIva3, - xmi.CuotaIva3, - xmi.PorRecargoEquivalencia3, - xmi.RecargoEquivalencia3, - xmi.CodigoTransaccion3, - xmi.BaseIva4, - xmi.PorBaseCorrectora4, - xmi.PorIva4, - xmi.CuotaIva4, - xmi.PorRecargoEquivalencia4, - xmi.RecargoEquivalencia4, - xmi.CodigoTransaccion4, - xmi.Año, -- ENT(2) - xmi.Serie, -- VARCHAR(10) - xmi.Factura, -- LONG(4) - xmi.SuFacturaNo, -- VARCHAR(40) - xmi.FechaFactura, -- FECHA(8) - xmi.ImporteFactura, -- DOBLE(19) - xmi.TipoFactura, -- VARCHAR(1) "E" / "R" - xmi.CodigoCuentaFactura, -- VARCHAR(15) cuenta del cliente/proveedor - xmi.CifDni, -- VARCHAR(13) - xmi.Nombre, -- VARCHAR(35) - xmi.CodigoRetencion, -- ENT(2) - xmi.BaseRetencion, -- DOBLE(19) - xmi.PorRetencion, -- DOBLE(19) - xmi.ImporteRetencion, -- DOBLE(19) - xmi.SiglaNacion, -- VARCHAR(2) "ES" por defecto - xmi.EjercicioFactura, -- ENT(2) - xmi.FechaOperacion, -- FECHA(8) - xmi.Exclusion347, -- ENT(2) - 1, -- xmi.MantenerAsiento BYTE "-1" mantener "0" Sage asigna nuevo - xmi.ClaveOperacionFactura, -- VARCHAR(1) - xmi.TipoRectificativa, -- ENT(2) - xmi.FechaFacturaOriginal, -- FECHA(8) - xmi.BaseImponibleOriginal, -- DOBLE(19) - xmi.CuotaIvaOriginal, -- DOBLE(19) - xmi.ClaseAbonoRectificativas,-- ENT(2) - xmi.RecargoEquivalenciaOriginal,-- DOBLE(19) */ - xmi.LibreA1, - xmi.CodigoIva1, -- ENT(6) - xmi.CodigoIva2, -- ENT(6) - xmi.CodigoIva3, -- ENT(6) - xmi.CodigoIva4, -- ENT(6) + IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS CodigoEmpresa, -- ENT(2) c.companyCode AS CodigoEmpresa, + x.ASIEN AS Asiento, -- LONG(4), nº ASIENTO + IF(EURODEBE<>0 OR (EURODEBE=0 AND EUROHABER IS NULL),'D','H')AS CargoAbono, -- IF(EURODEBE IS NULL,"H","D") AS CargoAbono, VARCHAR(1) "D" debe ó "H" haber + x.SUBCTA AS CodigoCuenta, -- VARCHAR(15) partida contable + x.CONTRA AS Contrapartida, -- VARCHAR(15) partida contable + x.FECHA AS FechaAsiento, -- FECHA(8) + SUBSTRING(x.CONCEPTO, 1, 40) AS Comentario, -- VARCHAR(40) + IF(x.EURODEBE,x.EURODEBE,x.EUROHABER) AS ImporteAsiento, -- DOBLE(19) + MONTH(x.FECHA) AS NumeroPeriodo, -- ENT(2) "-1" Al informar este valor se calcula automát. A partir de la fecha de asiento + IF( sub2.FECREGCON IS NULL, sub2.FECHA_EX, sub2.FECREGCON) FechaGrabacion, -- FECHA(8) + IF(x.CAMBIO,IFNULL(xmi.CodigoDivisa, sub3.code),'') CodigoDivisa, -- VARCHAR(3) + x.CAMBIO AS ImporteCambio, -- DOBLE(19) + IFNULL(x.DEBEME,x.HABERME) AS ImporteDivisa, -- DOBLE(19) + IF(x.CAMBIO,1,0) AS FactorCambio, -- DOBLE(19) + NULL AS IdProcesoIME, -- GUID(16) + 0 AS TipoCarteraIME, -- ENT(2) "0" para que no genere cartera + 0 AS TipoAnaliticaIME, -- ENT(2) + 0 AS StatusTraspasadoIME, -- BYTE "0" para dejar como no importado aún + 0 AS TipoImportacionIME, -- BYTE "0" Alta "1" Baja + x.METAL as Metalico347, + /* ESTOS CAMPOS SOLO SE INFORMAN EN EL CASO DE SER FACTURA */ + xmi.BaseIva1, -- DOBLE(19) + xmi.PorBaseCorrectora1, -- DOBLE(19) + xmi.PorIva1, -- DOBLE(19) + xmi.CuotaIva1, -- DOBLE(19) + xmi.PorRecargoEquivalencia1,-- DOBLE(19) + xmi.RecargoEquivalencia1, -- DOBLE(19) + xmi.CodigoTransaccion1, -- BYTE "0" Nacional "1" Intracomunitario "2" Extracomunitario + xmi.BaseIva2, + xmi.PorBaseCorrectora2, + xmi.PorIva2, + xmi.CuotaIva2, + xmi.PorRecargoEquivalencia2, + xmi.RecargoEquivalencia2, + xmi.CodigoTransaccion2, + xmi.BaseIva3, + xmi.PorBaseCorrectora3, + xmi.PorIva3, + xmi.CuotaIva3, + xmi.PorRecargoEquivalencia3, + xmi.RecargoEquivalencia3, + xmi.CodigoTransaccion3, + xmi.BaseIva4, + xmi.PorBaseCorrectora4, + xmi.PorIva4, + xmi.CuotaIva4, + xmi.PorRecargoEquivalencia4, + xmi.RecargoEquivalencia4, + xmi.CodigoTransaccion4, + xmi.Año, -- ENT(2) + xmi.Serie, -- VARCHAR(10) + xmi.Factura, -- LONG(4) + xmi.SuFacturaNo, -- VARCHAR(40) + xmi.FechaFactura, -- FECHA(8) + xmi.ImporteFactura, -- DOBLE(19) + xmi.TipoFactura, -- VARCHAR(1) "E" / "R" + xmi.CodigoCuentaFactura, -- VARCHAR(15) cuenta del cliente/proveedor + xmi.CifDni, -- VARCHAR(13) + xmi.Nombre, -- VARCHAR(35) + xmi.CodigoRetencion, -- ENT(2) + xmi.BaseRetencion, -- DOBLE(19) + xmi.PorRetencion, -- DOBLE(19) + xmi.ImporteRetencion, -- DOBLE(19) + xmi.SiglaNacion, -- VARCHAR(2) "ES" por defecto + xmi.EjercicioFactura, -- ENT(2) + xmi.FechaOperacion, -- FECHA(8) + xmi.Exclusion347, -- ENT(2) + 1, -- xmi.MantenerAsiento BYTE "-1" mantener "0" Sage asigna nuevo + xmi.ClaveOperacionFactura, -- VARCHAR(1) + xmi.TipoRectificativa, -- ENT(2) + xmi.FechaFacturaOriginal, -- FECHA(8) + xmi.BaseImponibleOriginal, -- DOBLE(19) + xmi.CuotaIvaOriginal, -- DOBLE(19) + xmi.ClaseAbonoRectificativas,-- ENT(2) + xmi.RecargoEquivalenciaOriginal,-- DOBLE(19) */ + xmi.LibreA1, + xmi.CodigoIva1, -- ENT(6) + xmi.CodigoIva2, -- ENT(6) + xmi.CodigoIva3, -- ENT(6) + xmi.CodigoIva4, -- ENT(6) xmi.IvaDeducible1, -- Entero 2 ((-1)) xmi.IvaDeducible2, -- Entero 2 ((-1)) xmi.IvaDeducible3, -- Entero 2 ((-1)) xmi.IvaDeducible4, -- Entero 2 ((-1))-- ENT(6) - xmi.Intracomunitaria -- TINYINT(1) - FROM vn2008.XDiario x - JOIN vn.company c ON c.id = x.empresa_id - LEFT JOIN XDiario_movConta_IVA xmi ON xmi.id = x.id AND xmi.moveData > 0 - LEFT JOIN (SELECT ASIEN, FECREGCON, FECHA_EX + xmi.Intracomunitaria -- TINYINT(1) + FROM vn2008.XDiario x + JOIN vn.company c ON c.id = x.empresa_id + LEFT JOIN XDiario_movConta_IVA xmi ON xmi.id = x.id AND xmi.moveData > 0 + LEFT JOIN (SELECT ASIEN, FECREGCON, FECHA_EX FROM (SELECT ASIEN, FECREGCON, FECHA_EX FROM vn2008.XDiario ORDER BY ASIEN, FECREGCON DESC, FECHA_EX DESC ) sub GROUP BY ASIEN )sub2 ON sub2.ASIEN = x.ASIEN - LEFT JOIN ( SELECT DISTINCT(account),cu.code + LEFT JOIN ( SELECT DISTINCT(account),cu.code FROM vn.bank b JOIN vn.currency cu ON cu.id = b.currencyFk - WHERE cu.code <> "EUR" -- no se informa cuando la divisa en EUR - )sub3 ON sub3.account = x.SUBCTA + WHERE cu.code <> "EUR" -- no se informa cuando la divisa en EUR + )sub3 ON sub3.account = x.SUBCTA WHERE x.enlazadoSage = 0 AND c.companyCode AND - x.FECHA >= vDated; + x.FECHA >= vDated; -- Prepara Metálicos UPDATE sage.movConta m @@ -18684,10 +18756,10 @@ BEGIN UPDATE sage.movConta m SET Metalico347 = FALSE, - m.TipoFactura = "", - m.Metalico347 = FALSE + m.TipoFactura = "", + m.Metalico347 = FALSE WHERE CargoAbono = "D" AND - m.enlazadoSage = FALSE; + m.enlazadoSage = FALSE; -- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación DELETE cp @@ -18720,12 +18792,13 @@ BEGIN m.IvaDeducible1 = TRUE, m.FechaFacturaOriginal = x.FECHA_EX, m.SuFacturaNo = x.FACTURAEX, - m.FechaOperacion = x.FECHA_OP + m.FechaOperacion = x.FECHA_OP, + m.ImporteFactura = m.ImporteFactura + x.BASEEURO + (x.IVA/100) * x.BASEEURO WHERE m.CodigoCuenta = 4700000999 AND m.enlazadoSage = FALSE AND x.SERIE='D' AND x.IVA = 10; - + UPDATE movConta m JOIN vn.XDiario x ON x.ASIEN = m.Asiento SET m.BaseIva2 = x.BASEEURO , @@ -18733,7 +18806,8 @@ BEGIN m.CuotaIva2 = (x.IVA/100) * x.BASEEURO , m.CodigoTransaccion2 = 56 , m.CodigoIva2 = 90, - m.IvaDeducible2 = TRUE + m.IvaDeducible2 = TRUE, + m.ImporteFactura = m.ImporteFactura + x.BASEEURO + (x.IVA/100) * x.BASEEURO WHERE m.CodigoCuenta = 4700000999 AND m.enlazadoSage = FALSE AND x.SERIE='D' @@ -18750,79 +18824,86 @@ UPDATE movConta m GROUP BY x.ASIEN ) sub ON sub.ASIEN = m.Asiento SET m.EjercicioFacturaOriginal = YEAR(sub.FECHA_RT), - m.SerieFacturaOriginal = sub.SERIE_RT, - m.NumeroFacturaOriginal = sub.FACTU_RT + m.SerieFacturaOriginal = sub.SERIE_RT, + m.NumeroFacturaOriginal = sub.FACTU_RT WHERE m.TipoRectificativa > 0 AND - m.enlazadoSage = FALSE ; + m.enlazadoSage = FALSE ; -- Exportaciones Andorras y Canarias cambia TT (la cuenta de taxCode es compartida, id:125) UPDATE sage.movConta m - SET CodigoTransaccion1 = 15, + SET CodigoTransaccion1 = 15, CodigoTransaccion2 = IF(CodigoTransaccion2 = 0, 0, 15), - CodigoTransaccion3 = IF(CodigoTransaccion3 = 0, 0, 15), - CodigoTransaccion4 = IF(CodigoTransaccion4 = 0, 0, 15) - WHERE enlazadoSage = FALSE AND + CodigoTransaccion3 = IF(CodigoTransaccion3 = 0, 0, 15), + CodigoTransaccion4 = IF(CodigoTransaccion4 = 0, 0, 15) + WHERE enlazadoSage = FALSE AND (CodigoTransaccion1 = 14 OR CodigoTransaccion2 = 14 OR CodigoTransaccion3 = 14 OR CodigoTransaccion4 = 14) AND - SiglaNAcion IN ('XC','XB'); - - + SiglaNAcion IN ('XC','XB'); -- Divisas - UPDATE sage.movConta - SET CodigoDivisa = IF(ImporteCambio<>0, "USD", "") - WHERE enlazadoSage = FALSE AND - ImporteCambio<>0 AND - ImporteDivisa<>0; - - + + UPDATE sage.movConta mc + SET CodigoDivisa = 'USD', + FactorCambio = 1, + ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio=0, ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) + WHERE (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio <> 0) + AND enlazadoSage = FALSE ; + + UPDATE sage.movConta mc + SET importeDivisa= importeDivisa * -1 + WHERE enlazadoSage = FALSE + AND importeDivisa > 0 + AND ImporteAsiento < 0; + + + /*-- Actualiza las facturas DUA para excluirlas del 347 y marcarlas como intracomunitarias /*UPDATE sage.movConta mc SET mc.Intracomunitaria = 1, mc.Exclusion347 = 1 WHERE - mc.CodigoCuenta = '4700000999'; */ + mc.CodigoCuenta = '4700000999'; */ - + -- MARCAR EN CASO DE SER INTRACOMUNITARIA -/* +/* UPDATE sage.movConta mc SET mc.Intracomunitaria = 1 WHERE - mc.CodigoTransaccion1 IN (20,29); + mc.CodigoTransaccion1 IN (20,29); */ - + -- LAS FACTURAS RTECTIFICATIVAS QUE TIENEN CUENTA DE IVA 477.2 SALE CON T.T. 1, TODAS ESTAS FACTURAS DEBEN DE TENER T.T. 15 /*UPDATE sage.movConta mc - JOIN - (SELECT - Asiento - FROM - sage.movConta - WHERE - CodigoCuenta = 4770000002) sub ON sub.Asiento = mc.Asiento + JOIN + (SELECT + Asiento + FROM + sage.movConta + WHERE + CodigoCuenta = 4770000002) sub ON sub.Asiento = mc.Asiento SET - CodigoTransaccion1 = CASE - WHEN CodigoTransaccion1 = 1 THEN 15 - ELSE CodigoTransaccion1 - END, - CodigoTransaccion2 = CASE - WHEN CodigoTransaccion2 = 1 THEN 15 - ELSE CodigoTransaccion2 - END, - CodigoTransaccion3 = CASE - WHEN CodigoTransaccion3 = 1 THEN 15 - ELSE CodigoTransaccion3 - END, - CodigoTransaccion4 = CASE - WHEN CodigoTransaccion4 = 1 THEN 15 - ELSE CodigoTransaccion4 - END + CodigoTransaccion1 = CASE + WHEN CodigoTransaccion1 = 1 THEN 15 + ELSE CodigoTransaccion1 + END, + CodigoTransaccion2 = CASE + WHEN CodigoTransaccion2 = 1 THEN 15 + ELSE CodigoTransaccion2 + END, + CodigoTransaccion3 = CASE + WHEN CodigoTransaccion3 = 1 THEN 15 + ELSE CodigoTransaccion3 + END, + CodigoTransaccion4 = CASE + WHEN CodigoTransaccion4 = 1 THEN 15 + ELSE CodigoTransaccion4 + END WHERE - serie = 'R'; + serie = 'R'; */ @@ -20039,10 +20120,10 @@ REPLACE INTO planCuentasPGC( CodigoCuenta, Cuenta, ClienteOProveedor - ) + ) SELECT codigoEmpresa, CodigoCuenta, Cuenta, ClienteOProveedor - FROM - ( + FROM + ( SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS codigoEmpresa, e.id AS CodigoCuenta, @@ -20054,9 +20135,9 @@ REPLACE INTO planCuentasPGC( WHERE c.companyCode GROUP BY e.id - + UNION - SELECT + SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS codigoEmpresa, b.account AS CodigoCuenta, UCASE(b.bank) AS Cuenta, @@ -20068,7 +20149,7 @@ REPLACE INTO planCuentasPGC( AND b.account GROUP BY b.account UNION - SELECT + SELECT codigoEmpresa, CodigoCuenta, Nombre AS Cuenta, @@ -20099,26 +20180,26 @@ BEGIN DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBase DOUBLE; - DECLARE vVat DOUBLE; - DECLARE vRate DOUBLE; - DECLARE vTransactionCode INT; - DECLARE vCounter INT DEFAULT 0; - DECLARE vTransactionCodeOld INT; + DECLARE vVat DOUBLE; + DECLARE vRate DOUBLE; + DECLARE vTransactionCode INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vTransactionCodeOld INT; DECLARE vTaxCode INT; DECLARE vTaxCodeOld INT; - DECLARE vOperationCode VARCHAR(1); + DECLARE vOperationCode VARCHAR(1); DECLARE vIsIntracommunity BOOL DEFAULT FALSE; - DECLARE vDuaExcluded INT; - + DECLARE vDuaExcluded INT; + DECLARE rs CURSOR FOR -- IVA - SELECT it.taxableBase BASEEURO, - CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)) vat, - t.PorcentajeIva rate, - it.transactionTypeSageFk transactionCode, - it.taxTypeSageFk taxCode, - t.isIntracommunity, - tt.ClaveOperacionDefecto operationCode, - id.id + SELECT it.taxableBase BASEEURO, + CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)) vat, + t.PorcentajeIva rate, + it.transactionTypeSageFk transactionCode, + it.taxTypeSageFk taxCode, + t.isIntracommunity, + tt.ClaveOperacionDefecto operationCode, + id.id FROM vn.invoiceIn i JOIN vn.invoiceInTax it ON it.InvoiceInFk = i.id JOIN TiposIva t ON t.CodigoIva = it.taxTypeSageFk @@ -20128,13 +20209,13 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DELETE FROM XDiario_movConta_IVA + DELETE FROM XDiario_movConta_IVA WHERE id = vXDiarioId; - + INSERT INTO XDiario_movConta_IVA(id, LibreA1) VALUES (vXDiarioId, vInvoiceInFk); - OPEN rs; + OPEN rs; FETCH rs INTO vBase, vVat, vRate, @@ -20146,7 +20227,7 @@ BEGIN SET vTransactionCodeOld=vTransactionCode; SET vTaxCodeOld=vTaxCode; - + WHILE NOT vDone DO IF vOperationCode IS NOT NULL THEN UPDATE XDiario_movConta_IVA @@ -20220,18 +20301,21 @@ BEGIN END WHILE; CLOSE rs; - UPDATE XDiario_movConta_IVA xmi + UPDATE XDiario_movConta_IVA xmi JOIN tmp.invoiceInList ii ON ii.id = vInvoiceInFk JOIN vn2008.XDiario x ON x.id = xmi.id - LEFT JOIN tmp.invoiceDua id ON id.id = xmi.id - JOIN vn.supplier s ON s.id = ii.supplierFk + LEFT JOIN tmp.invoiceDua id ON id.id = xmi.id + JOIN vn.supplier s ON s.id = ii.supplierFk JOIN Naciones n ON n.countryFk = s.countryFk SET xmi.CodigoDivisa = ii.currencyFk, xmi.Año = YEAR(ii.issued), xmi.Serie = ii.serial, xmi.Factura = ii.serialNumber, -- x.FACTURA, DUAS¿? xmi.FechaFactura = ii.issued, - xmi.ImporteFactura = BaseIva1 + CuotaIva1 + BaseIva2 + CuotaIva2 + BaseIva3 + CuotaIva3 + BaseIva4 + CuotaIva4, + xmi.ImporteFactura = IFNULL(xmi.BaseIva1, 0) + IFNULL(xmi.CuotaIva1, 0) + + IFNULL(xmi.BaseIva2, 0) + IFNULL(xmi.CuotaIva2, 0) + + IFNULL(xmi.BaseIva3, 0) + IFNULL(xmi.CuotaIva3, 0) + + IFNULL(xmi.BaseIva4, 0) + IFNULL(xmi.CuotaIva4, 0), xmi.TipoFactura = IF(id.id,IF( ii.serial = 'D', 'R','I'), 'R'), -- MARCAR I para informativa xmi.CodigoCuentaFactura = x.SUBCTA, xmi.CifDni = IF(LEFT(TRIM(s.nif),2) = n.SiglaNacion, SUBSTRING(TRIM(s.nif),3) ,s.nif), @@ -20240,43 +20324,43 @@ BEGIN xmi.EjercicioFactura = YEAR(ii.issued), xmi.FechaOperacion = ii.issued, xmi.MantenerAsiento = TRUE, - xmi.SuFacturaNo = ii.supplierRef, - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva1,FALSE),FALSE,ii.isVatDeductible)), - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva2,FALSE),FALSE,ii.isVatDeductible)), - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva3,FALSE),FALSE,ii.isVatDeductible)), - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva4,FALSE),FALSE,ii.isVatDeductible)), - xmi.FechaFacturaOriginal = x.FECHA_EX + xmi.SuFacturaNo = ii.supplierRef, + xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva1,FALSE),FALSE,ii.isVatDeductible)), + xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva2,FALSE),FALSE,ii.isVatDeductible)), + xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva3,FALSE),FALSE,ii.isVatDeductible)), + xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva4,FALSE),FALSE,ii.isVatDeductible)), + xmi.FechaFacturaOriginal = x.FECHA_EX WHERE xmi.id = vXDiarioId; - + -- RETENCIONES /* UPDATE XDiario_movConta_IVA xmi JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk JOIN vn2008.XDiario x ON x.id = xmi.id - JOIN vn.supplier s ON s.id = supplierFk + JOIN vn.supplier s ON s.id = supplierFk JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk + JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk SET xmi.CodigoRetencion = t.CodigoRetencion, xmi.BaseRetencion = iit.taxableBase, xmi.PorRetencion = t.PorcentajeRetencion, - xmi.ImporteRetencion = iit.taxableBase * (t.PorcentajeRetencion / 100) + xmi.ImporteRetencion = iit.taxableBase * (t.PorcentajeRetencion / 100) WHERE xmi.id = vXDiarioId AND iit.taxableBase < 0 ;*/ - - UPDATE XDiario_movConta_IVA xmi + + UPDATE XDiario_movConta_IVA xmi JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk JOIN vn2008.XDiario x ON x.id = xmi.id - JOIN vn.supplier s ON s.id = supplierFk + JOIN vn.supplier s ON s.id = supplierFk JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk - JOIN (SELECT SUM(BASEEURO) taxableBase, SUM(EURODEBE) taxBase + JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk + JOIN (SELECT SUM(BASEEURO) taxableBase, SUM(EURODEBE) taxBase FROM vn.XDiario - WHERE BASEEURO <> 0 AND ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioId) + WHERE BASEEURO <> 0 AND ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioId) )sub SET xmi.CodigoRetencion = t.CodigoRetencion, - xmi.BaseRetencion = IF (t.CodigoRetencion = 2, sub.taxableBase + sub.taxBase, sub.taxableBase), + xmi.BaseRetencion = IF (t.CodigoRetencion = 2, sub.taxableBase + sub.taxBase, sub.taxableBase), xmi.PorRetencion = t.PorcentajeRetencion, - xmi.ImporteRetencion = iit.taxableBase * - 1 + xmi.ImporteRetencion = iit.taxableBase * - 1 WHERE xmi.id = vXDiarioId AND iit.expenceFk= 4751000000 ; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -20651,10 +20735,10 @@ CREATE DEFINER=`root`@`%` PROCEDURE `XDiario_movConta_IVA_InvoiceInAdd_Manager`( BEGIN DECLARE done BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; - DECLARE vXDiarioFk INT; - DECLARE vDated DATE; + DECLARE vXDiarioFk INT; + DECLARE vDated DATE; DECLARE rs CURSOR FOR - SELECT IFNULL(ii.id,x.FACTURA) invoiceInFk, x.id XDiarioFk + SELECT IFNULL(x.CLAVE,x.FACTURA) invoiceInFk, x.id XDiarioFk FROM vn2008.XDiario x JOIN(SELECT DISTINCT (x.ASIEN) FROM vn2008.XDiario x @@ -20664,28 +20748,26 @@ BEGIN x.enlazadoSage = FALSE AND x.FECHA >= vDated ) sub ON sub.ASIEN =x.ASIEN -- Elimina las Facturas con IVA 0 (-) no se trasladan a sage - LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id WHERE x.enlazadoSage = FALSE AND x.FECHA >= vDated AND - ii.id IS NOT NULL ; + x.CLAVE IS NOT NULL ; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - SELECT CONCAT(YEAR(CURDATE()), "-01-01") INTO vDated; - DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; + SELECT CONCAT(YEAR(CURDATE()), "-01-01") INTO vDated; + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; CREATE TEMPORARY TABLE tmp.invoiceDua SELECT id - FROM vn2008.XDiario x - WHERE ASIEN IN (SELECT ASIEN - FROM vn.invoiceIn ii - JOIN vn2008.XDiario x ON x.CLAVE = ii.id - WHERE x.enlazadoSage = FALSE AND - x.SUBCTA = '4700000999' AND - x.FECHA >= vDated - ) AND - NOT CONTRA <=> "4330002067"; + FROM vn2008.XDiario x + WHERE ASIEN IN (SELECT ASIEN + FROM vn2008.XDiario x + WHERE x.enlazadoSage = FALSE AND + x.SUBCTA = '4700000999' AND + x.FECHA >= vDated + ) AND + NOT CONTRA <=> "4330002067"; - DROP TEMPORARY TABLE IF EXISTS tmp.invoiceInList; + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceInList; CREATE TEMPORARY TABLE tmp.invoiceInList SELECT i.id id, i.supplierRef supplierRef, @@ -20699,7 +20781,7 @@ BEGIN JOIN vn.currency c ON c.id = i.currencyFk WHERE i.bookEntried >= vDated UNION ALL - SELECT d.id , + SELECT d.id , d.code , 'D' , d.companyFk , @@ -20718,11 +20800,11 @@ BEGIN FETCH rs INTO vInvoiceFk, vXDiarioFk; END WHILE; CLOSE rs; - + DROP TEMPORARY TABLE tmp.invoiceDua; DROP TEMPORARY TABLE tmp.invoiceInList; - - -- ASIENTOS CON IVA SOPORTADO 472. y 477. hay que informar 2 líneas la info de facturas una como tipo de factura emitida y otra como recibida + + -- ASIENTOS CON IVA SOPORTADO 472. y 477. hay que informar 2 líneas la info de facturas una como tipo de factura emitida y otra como recibida DROP TEMPORARY TABLE IF EXISTS tmp.XDiario_movConta_IVA; CREATE TEMPORARY TABLE tmp.XDiario_movConta_IVA SELECT @@ -20804,7 +20886,7 @@ BEGIN FROM vn.XDiario x WHERE SUBCTA LIKE '472%' AND x.enlazadoSage = FALSE AND - x.FECHA >= vDated + x.FECHA >= vDated ) sub JOIN vn.XDiario x ON x.ASIEN = sub.ASIEN WHERE x.SUBCTA LIKE '477%' )sub2 ON sub2.ASIEN = x.ASIEN @@ -20884,7 +20966,7 @@ BEGIN `moveData`) SELECT * FROM tmp.XDiario_movConta_IVA; - DROP TEMPORARY TABLE tmp.XDiario_movConta_IVA; + DROP TEMPORARY TABLE tmp.XDiario_movConta_IVA; END ;; DELIMITER ; @@ -21160,69 +21242,243 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `XDiario_movConta_IVA_InvoiceInAdd_Manager___`() BEGIN - DECLARE done BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; DECLARE vXDiarioFk INT; + DECLARE vDated DATE; DECLARE rs CURSOR FOR SELECT IFNULL(ii.id,x.FACTURA) invoiceInFk, x.id XDiarioFk FROM vn2008.XDiario x - LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id - WHERE x.enlazadoSage=0 - AND ((SUBCTA<>"4700000999" AND ii.id IS NOT NULL) - OR (SUBCTA LIKE '472%' AND CONTRA ='4330002067' AND ii.id IS NULL)) ; - -/*VALORAR QUITAR LAS FACTURAS CON IVA 0 - FROM vn.invoiceInTax iit - JOIN vn.taxCode tx ON tx.id = iit.taxCodeFk - WHERE iit.rate <> 0 -*/ + JOIN(SELECT DISTINCT (x.ASIEN) + FROM vn2008.XDiario x + LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id + LEFT JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id + WHERE it.taxTypeSageFk IS NOT NULL AND + x.enlazadoSage = FALSE AND + x.FECHA >= vDated + ) sub ON sub.ASIEN =x.ASIEN -- Elimina las Facturas con IVA 0 (-) no se trasladan a sage + LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id + WHERE x.enlazadoSage = FALSE AND + x.FECHA >= vDated AND + ii.id IS NOT NULL ; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + SELECT CONCAT(YEAR(CURDATE()), "-01-01") INTO vDated; DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; - CREATE TEMPORARY TABLE tmp.invoiceDua SELECT id FROM vn2008.XDiario x WHERE ASIEN IN (SELECT ASIEN FROM vn.invoiceIn ii JOIN vn2008.XDiario x ON x.CLAVE = ii.id - WHERE enlazadoSage=0 AND - SUBCTA = '4700000999' - ) - AND (CONTRA <> "4330002067" OR CONTRA IS NULL); - + WHERE x.enlazadoSage = FALSE AND + x.SUBCTA = '4700000999' AND + x.FECHA >= vDated + ) AND + NOT CONTRA <=> "4330002067"; + + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceInList; + CREATE TEMPORARY TABLE tmp.invoiceInList + SELECT i.id id, + i.supplierRef supplierRef, + i.serial serial, + i.supplierFk supplierFk, + i.issued issued, + i.isVatDeductible isVatDeductible, + i.serialNumber serialNumber, + IF(c.code = "EUR", '',c.code) currencyFk + FROM vn.invoiceIn i + JOIN vn.currency c ON c.id = i.currencyFk + WHERE i.bookEntried >= vDated + UNION ALL + SELECT d.id , + d.code , + 'D' , + d.companyFk , + d.issued , + FALSE, + d.id, + '' -- EUROS + FROM vn.dua d + WHERE d.issued IS NOT NULL AND + code IS NOT NULL; + OPEN rs; FETCH rs INTO vInvoiceFk, vXDiarioFk; - WHILE NOT done DO - CALL XDiario_movConta_IVA_InvoiceInAdd(vInvoiceFk, vXDiarioFk); FETCH rs INTO vInvoiceFk, vXDiarioFk; - END WHILE; - CLOSE rs; + + DROP TEMPORARY TABLE tmp.invoiceDua; + DROP TEMPORARY TABLE tmp.invoiceInList; - DROP TEMPORARY TABLE tmp.invoiceDua; - - DELETE xmi - FROM sage.XDiario_movConta_IVA xmi - JOIN ( SELECT sub.invoiceIn invoiceIn, XDiarioFk, SUM(total) total, tipo - FROM (SELECT IFNULL(ii.id,x.FACTURA) invoiceIn, x.id XDiarioFk,tc.type tipo, 1 as total - FROM vn2008.XDiario x - LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id - LEFT JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id - LEFT JOIN vn.taxCode tc ON tc.id = iit.taxCodeFk - WHERE x.enlazadoSage = 0 AND - ((SUBCTA<>"4700000999" AND ii.id IS NOT NULL) OR - (SUBCTA LIKE '472%' AND CONTRA ='4330002067' AND ii.id IS NULL)) AND - serial='R' - GROUP BY invoiceIn, XDiarioFk,tc.type - )sub - GROUP BY sub.invoiceIn, sub.XDiarioFk - HAVING tipo='-' AND total=1 - ) sub2 ON sub2.invoiceIn = xmi.LibreA1 AND sub2.XDiarioFk = xmi.id ; + -- ASIENTOS CON IVA SOPORTADO 472. y 477. hay que informar 2 líneas la info de facturas una como tipo de factura emitida y otra como recibida + DROP TEMPORARY TABLE IF EXISTS tmp.XDiario_movConta_IVA; + CREATE TEMPORARY TABLE tmp.XDiario_movConta_IVA + SELECT + sub3.id, + mc.CodigoDivisa, + mc.BaseIva1, + mc.PorBaseCorrectora1, + mc.PorIva1, + mc.CuotaIva1, + mc.PorRecargoEquivalencia1, + mc.RecargoEquivalencia1, + mc.CodigoTransaccion1, + mc.CodigoIva1, + mc.BaseIva2, + mc.PorBaseCorrectora2, + mc.PorIva2, + mc.CuotaIva2, + mc.PorRecargoEquivalencia2, + mc.RecargoEquivalencia2, + mc.CodigoTransaccion2, + mc.CodigoIva2, + mc.BaseIva3, + mc.PorBaseCorrectora3, + mc.PorIva3, + mc.CuotaIva3, + mc.PorRecargoEquivalencia3, + mc.RecargoEquivalencia3, + mc.CodigoTransaccion3, + mc.CodigoIva3, + mc.BaseIva4, + mc.PorBaseCorrectora4, + mc.PorIva4, + mc.CuotaIva4, + mc.PorRecargoEquivalencia4, + mc.RecargoEquivalencia4, + mc.CodigoTransaccion4, + mc.CodigoIva4, + mc.Año, + mc.Serie, + mc.Factura, + mc.SuFacturaNo, + mc.FechaFactura, + mc.ImporteFactura, + 'E', + mc.CodigoCuentaFactura, + mc.CifDni, + mc.Nombre, + mc.CodigoRetencion, + mc.BaseRetencion, + mc.PorRetencion, + mc.ImporteRetencion, + mc.SiglaNacion, + mc.EjercicioFactura, + x.FECHA, + mc.Exclusion347, + mc.MantenerAsiento, + mc.Metalico347, + mc.ClaveOperacionFactura, + mc.TipoRectificativa, + mc.FechaFacturaOriginal, + mc.CuotaIvaOriginal, + mc.BaseImponibleOriginal, + mc.ClaseAbonoRectificativas, + mc.RecargoEquivalenciaOriginal, + mc.LibreA1, + mc.IvaDeducible1, + mc.IvaDeducible2, + mc.IvaDeducible3, + mc.IvaDeducible4, + mc.FechaGrabacion, + mc.Intracomunitaria, + mc.moveData + FROM sage.XDiario_movConta_IVA mc + JOIN vn.XDiario x ON x.id = mc.id + JOIN (SELECT x.ASIEN, x.id + FROM vn.XDiario x + JOIN(SELECT DISTINCT(x.ASIEN) ASIEN + FROM (SELECT DISTINCT(ASIEN) + FROM vn.XDiario x + WHERE SUBCTA LIKE '472%' AND + x.enlazadoSage = FALSE AND + x.FECHA >= vDated + ) sub JOIN vn.XDiario x ON x.ASIEN = sub.ASIEN + WHERE x.SUBCTA LIKE '477%' + )sub2 ON sub2.ASIEN = x.ASIEN + WHERE x.CONTRA IS NOT NULL AND x.SUBCTA LIKE '477%' + GROUP BY x.ASIEN + )sub3 ON sub3.ASIEN = x.ASIEN; + + INSERT INTO sage.XDiario_movConta_IVA + (`id`, + `CodigoDivisa`, + `BaseIva1`, + `PorBaseCorrectora1`, + `PorIva1`, + `CuotaIva1`, + `PorRecargoEquivalencia1`, + `RecargoEquivalencia1`, + `CodigoTransaccion1`, + `CodigoIva1`, + `BaseIva2`, + `PorBaseCorrectora2`, + `PorIva2`, + `CuotaIva2`, + `PorRecargoEquivalencia2`, + `RecargoEquivalencia2`, + `CodigoTransaccion2`, + `CodigoIva2`, + `BaseIva3`, + `PorBaseCorrectora3`, + `PorIva3`, + `CuotaIva3`, + `PorRecargoEquivalencia3`, + `RecargoEquivalencia3`, + `CodigoTransaccion3`, + `CodigoIva3`, + `BaseIva4`, + `PorBaseCorrectora4`, + `PorIva4`, + `CuotaIva4`, + `PorRecargoEquivalencia4`, + `RecargoEquivalencia4`, + `CodigoTransaccion4`, + `CodigoIva4`, + `Año`, + `Serie`, + `Factura`, + `SuFacturaNo`, + `FechaFactura`, + `ImporteFactura`, + `TipoFactura`, + `CodigoCuentaFactura`, + `CifDni`, + `Nombre`, + `CodigoRetencion`, + `BaseRetencion`, + `PorRetencion`, + `ImporteRetencion`, + `SiglaNacion`, + `EjercicioFactura`, + `FechaOperacion`, + `Exclusion347`, + `MantenerAsiento`, + `Metalico347`, + `ClaveOperacionFactura`, + `TipoRectificativa`, + `FechaFacturaOriginal`, + `CuotaIvaOriginal`, + `BaseImponibleOriginal`, + `ClaseAbonoRectificativas`, + `RecargoEquivalenciaOriginal`, + `LibreA1`, + `IvaDeducible1`, + `IvaDeducible2`, + `IvaDeducible3`, + `IvaDeducible4`, + `FechaGrabacion`, + `Intracomunitaria`, + `moveData`) + SELECT * + FROM tmp.XDiario_movConta_IVA; + DROP TEMPORARY TABLE tmp.XDiario_movConta_IVA; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -21493,35 +21749,35 @@ BEGIN DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBase DOUBLE; - DECLARE vVat DOUBLE; - DECLARE vRate DOUBLE; - DECLARE vIs340 DOUBLE; - DECLARE vIs347 DOUBLE; - DECLARE vVatRE DOUBLE; - DECLARE vRateRE DOUBLE; - DECLARE vTransactionCode INT; - DECLARE vCounter INT DEFAULT 0; - DECLARE vInvoiceOutCorrectedFk INT; + DECLARE vVat DOUBLE; + DECLARE vRate DOUBLE; + DECLARE vIs340 DOUBLE; + DECLARE vIs347 DOUBLE; + DECLARE vVatRE DOUBLE; + DECLARE vRateRE DOUBLE; + DECLARE vTransactionCode INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vInvoiceOutCorrectedFk INT; DECLARE vTaxCode INT; - DECLARE vIsIntracommunity BOOL DEFAULT FALSE; - DECLARE vOperationCode VARCHAR(1); - + DECLARE vIsIntracommunity BOOL DEFAULT FALSE; + DECLARE vOperationCode VARCHAR(1); + -- IVA DECLARE rs CURSOR FOR SELECT oit.taxableBase, oit.vat, - pgc.rate, - pgc.mod340, - pgc.mod347, - pgcRE.rate as rateRE, - oitRE.vat as vatRE, - tc.transactionCode , + pgc.rate, + pgc.mod340, + pgc.mod347, + pgcRE.rate as rateRE, + oitRE.vat as vatRE, + tc.transactionCode , tc.taxCode, - tc.isIntracommunity, - tc.operationcode + tc.isIntracommunity, + tc.operationcode FROM vn.invoiceOutTax oit JOIN vn.pgc ON pgc.code = oit.pgcFk - LEFT JOIN vn.pgcEqu e ON e.vatFk = oit.pgcFk + LEFT JOIN vn.pgcEqu e ON e.vatFk = oit.pgcFk LEFT JOIN vn.pgcEqu eRE ON eRE.equFk = oit.pgcFk LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk AND oitRE.pgcFk = e.equFk LEFT JOIN vn.pgc pgcRE ON pgcRE.code = oitRE.pgcFk @@ -21540,64 +21796,64 @@ BEGIN OPEN rs; FETCH rs INTO vBase, vVat, - vRate, - vIs340, - vIs347, - vVatRE, - vRateRE, - vTransactionCode, - vTaxCode, - vIsIntracommunity, - vOperationCode; + vRate, + vIs340, + vIs347, + vVatRE, + vRateRE, + vTransactionCode, + vTaxCode, + vIsIntracommunity, + vOperationCode; WHILE NOT vDone DO - + IF vOperationCode IS NOT NULL THEN UPDATE XDiario_movConta_IVA SET ClaveOperacionFactura = vOperationCode WHERE id = vXDiarioId; - END IF; - + END IF; + SET vCounter = vCounter + 1; CASE vCounter WHEN 1 THEN UPDATE XDiario_movConta_IVA SET BaseIva1 = vBase, PorIva1 = vRate, - CuotaIva1 = vVat, - PorRecargoEquivalencia1 = vVatRE, - RecargoEquivalencia1 = vRateRE, - CodigoTransaccion1 = vTransactionCode, + CuotaIva1 = vVat, + PorRecargoEquivalencia1 = vVatRE, + RecargoEquivalencia1 = vRateRE, + CodigoTransaccion1 = vTransactionCode, CodigoIva1 = vTaxCode WHERE id = vXDiarioId; - WHEN 2 THEN - UPDATE XDiario_movConta_IVA + WHEN 2 THEN + UPDATE XDiario_movConta_IVA SET BaseIva2 = vBase, PorIva2 = vRate, - CuotaIva2 = vVat, - PorRecargoEquivalencia2 = vVatRE, - RecargoEquivalencia2 =vRateRE, - CodigoTransaccion2 = vTransactionCode, + CuotaIva2 = vVat, + PorRecargoEquivalencia2 = vVatRE, + RecargoEquivalencia2 =vRateRE, + CodigoTransaccion2 = vTransactionCode, CodigoIva2 = vTaxCode WHERE id = vXDiarioId; - WHEN 3 THEN + WHEN 3 THEN UPDATE XDiario_movConta_IVA SET BaseIva3 = vBase, PorIva3 = vRate, - CuotaIva3 = vVat, - PorRecargoEquivalencia3 = vVatRE, - RecargoEquivalencia3 = vRateRE, - CodigoTransaccion3 = vTransactionCode, + CuotaIva3 = vVat, + PorRecargoEquivalencia3 = vVatRE, + RecargoEquivalencia3 = vRateRE, + CodigoTransaccion3 = vTransactionCode, CodigoIva3 = vTaxCode WHERE id = vXDiarioId; - WHEN 4 THEN - UPDATE XDiario_movConta_IVA + WHEN 4 THEN + UPDATE XDiario_movConta_IVA SET BaseIva4 = vBase, PorIva4 = vRate, - CuotaIva4 = vVat, - PorRecargoEquivalencia4 = vVatRE, - RecargoEquivalencia4 = vRateRE, - CodigoTransaccion4 = vTransactionCode, + CuotaIva4 = vVat, + PorRecargoEquivalencia4 = vVatRE, + RecargoEquivalencia4 = vRateRE, + CodigoTransaccion4 = vTransactionCode, CodigoIva4 = vTaxCode WHERE id = vXDiarioId; END CASE; @@ -21605,37 +21861,37 @@ BEGIN UPDATE XDiario_movConta_IVA SET Exclusion347 = NOT vIs347 WHERE id = vXDiarioId; - + IF vIsIntracommunity THEN UPDATE XDiario_movConta_IVA SET Intracomunitaria = TRUE WHERE id = vXDiarioId; - END IF; + END IF; - FETCH rs INTO vBase, + FETCH rs INTO vBase, vVat, - vRate, - vIs340, - vIs347, - vVatRE, - vRateRE, - vTransactionCode, - vTaxCode, - vIsIntracommunity, - vOperationCode; + vRate, + vIs340, + vIs347, + vVatRE, + vRateRE, + vTransactionCode, + vTaxCode, + vIsIntracommunity, + vOperationCode; END WHILE; CLOSE rs; -- OTROS CAMPOS RELATIVOS A LAS FACTURAS - UPDATE XDiario_movConta_IVA xmi + UPDATE XDiario_movConta_IVA xmi JOIN vn.invoiceOut io ON io.id = vInvoiceOutFk LEFT JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutFk LEFT JOIN vn.invoiceOut ioc ON ioc.id = ic.correctingFk JOIN vn2008.XDiario x ON x.id = xmi.id JOIN vn.client c ON c.id = io.clientFk - JOIN Naciones n ON n.countryFk = c.countryFk + JOIN Naciones n ON n.countryFk = c.countryFk JOIN vn.invoiceOutSerial ios ON ios.code = io.serial JOIN vn.taxArea ta ON ta.code = ios.taxAreaFk - JOIN (SELECT SERIE + JOIN (SELECT SERIE FROM vn2008.XDiario WHERE ASIEN = (SELECT ASIEN FROM vn2008.XDiario @@ -21658,42 +21914,42 @@ BEGIN xmi.MantenerAsiento = TRUE, xmi.FechaFacturaOriginal = x.FECHA_EX WHERE xmi.id = vXDiarioId; - - -- RECTIFICATIVAS + + -- RECTIFICATIVAS SELECT correctedFk INTO vInvoiceOutCorrectedFk FROM vn.invoiceCorrection WHERE correctingFk = vInvoiceOutFk; - + IF vInvoiceOutCorrectedFk THEN UPDATE XDiario_movConta_IVA xmi JOIN vn.invoiceOut ioc ON ioc.id = vInvoiceOutCorrectedFk JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk - JOIN vn.invoiceOut io ON io.id = vInvoiceOutCorrectedFk + JOIN vn.invoiceOut io ON io.id = vInvoiceOutCorrectedFk JOIN ( SELECT sum(IF(IFNULL(e.vatFk,1),iot.taxableBase,0)) AS Base, sum(IF(IFNULL(e.vatFk,1),iot.vat,0)) AS CuotaIva, - sum(IF(IFNULL(e.vatFk,1),0,iot.vat)) as RE + sum(IF(IFNULL(e.vatFk,1),0,iot.vat)) as RE FROM vn.invoiceOutTax iot LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk ) iocTAX - SET xmi.TipoRectificativa = 2, + SET xmi.TipoRectificativa = 2, xmi.ClaseAbonoRectificativas = 1, -- ic.invoiceCorrectionTypeFk no coincide con las opcioens de SAGE * - xmi.FechaFacturaOriginal = io.issued, - xmi.FechaOperacion = io.issued, + xmi.FechaFacturaOriginal = io.issued, + xmi.FechaOperacion = io.issued, xmi.BaseImponibleOriginal = iocTAX.Base, xmi.CuotaIvaOriginal = iocTAX.CuotaIva, xmi.RecargoEquivalenciaOriginal = RE, - xmi.ClaveOperacionFactura = 'D' + xmi.ClaveOperacionFactura = 'D' WHERE xmi.id = vXDiarioId; /* - Envases y embalajes / descuentos y bonificaciones / eror fundado - Concurso de acreedores - Creditos incobrables - resto de tectificativas - Restificativas de facturas simplificadas - */ + Envases y embalajes / descuentos y bonificaciones / eror fundado + Concurso de acreedores + Creditos incobrables + resto de tectificativas + Restificativas de facturas simplificadas + */ END IF; END ;; DELIMITER ; @@ -21716,9 +21972,9 @@ BEGIN DECLARE done BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; - DECLARE vXDiarioFk INT; + DECLARE vXDiarioFk INT; DECLARE vDated DATE; - + DECLARE rs CURSOR FOR SELECT io.id invoiceOutFk, x.XDiarioFk FROM vn.invoiceOut io @@ -21738,7 +21994,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; SELECT CONCAT(YEAR(CURDATE()), "-01-01") INTO vDated; - OPEN rs; + OPEN rs; FETCH rs INTO vInvoiceFk, vXDiarioFk; WHILE NOT done DO CALL XDiario_movConta_IVA_InvoiceOutAdd(vInvoiceFk, vXDiarioFk); @@ -23458,7 +23714,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` FUNCTION `dayEnd`(vDated DATE) RETURNS datetime +CREATE DEFINER=`root`@`%` FUNCTION `dayend`(vDated DATE) RETURNS datetime NO SQL DETERMINISTIC BEGIN @@ -23613,7 +23869,7 @@ CREATE DEFINER=`root`@`%` FUNCTION `midnight`() RETURNS datetime READS SQL DATA BEGIN - RETURN TIMESTAMPADD(SECOND, 24 * 60 * 60 - 1, CURDATE()); + RETURN TIMESTAMP(CURDATE(), '23:59:59'); END ;; DELIMITER ; @@ -24933,6 +25189,8 @@ CREATE TABLE `agencyTerm` ( `packagePrice` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'precio extra por bulto', `routePrice` decimal(10,2) DEFAULT NULL COMMENT 'precio fijo por ruta', `minimumKm` int(11) NOT NULL DEFAULT '0', + `minimumM3` decimal(10,0) DEFAULT NULL, + `m3Price` decimal(10,0) DEFAULT NULL, PRIMARY KEY (`agencyFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -25115,42 +25373,6 @@ BEGIN SET NEW.year= year(CURDATE()); -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `awb_ai` AFTER INSERT ON `awb` FOR EACH ROW -BEGIN - - DECLARE invoiceInFk INT; - - -- Eliminar cuando funcione el sistema DUA - INSERT INTO invoiceIn(supplierFk,issued,companyFk) - VALUES(NEW.transitoryFk,CURDATE(),442); - - SELECT last_insert_id() INTO invoiceInFk; -/* - INSERT INTO awb_recibida(awb_id,recibida_id) - VALUES(NEW.id,invoiceInFk); - */ - -- Sistema DUA - INSERT INTO vn.dua(awbFk) - VALUES(NEW.id); - - INSERT INTO vn.duaInvoiceIn(duaFk, invoiceInFk) - VALUES(LAST_INSERT_ID(), invoiceInFk); - END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -26118,6 +26340,7 @@ DROP TABLE IF EXISTS `claimReason`; CREATE TABLE `claimReason` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + `isTired` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Motivos de las fallos'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -26214,12 +26437,12 @@ CREATE TABLE `client` ( `postcode` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL, `socialName` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `contact` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `wholesaler` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', - `isReExpedition` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `wholesaler__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `isReExpedition__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', `hasToInvoice` tinyint(1) NOT NULL DEFAULT '1', `notes` text COLLATE utf8_unicode_ci COMMENT 'obsoleta (comprobar)', - `administrativeNotes` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'obsoleta (comprobar)', - `invoiceCopy` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `administrativeNotes__` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'obsoleta (comprobar)', + `invoiceCopy__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', `hold` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', `isFreezed` tinyint(1) NOT NULL DEFAULT '0', `salesPersonFk` int(11) DEFAULT NULL, @@ -26234,18 +26457,18 @@ CREATE TABLE `client` ( `isToBeMailed` tinyint(1) NOT NULL DEFAULT '1', `contactChannelFk` smallint(6) DEFAULT NULL, `isVies` tinyint(4) NOT NULL DEFAULT '0', - `splitHolland` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', - `sepaFth` tinyint(1) DEFAULT '0' COMMENT 'campo para recibir los escritos de los clientes para el sepa\n\nobsoleta (comprobar)', + `splitHolland__` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `sepaFth__` tinyint(1) DEFAULT '0' COMMENT 'campo para recibir los escritos de los clientes para el sepaobsoleta (comprobar)', `hasSepaVnl` tinyint(1) DEFAULT '0', - `coreFth` tinyint(1) DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `coreFth__` tinyint(1) DEFAULT '0' COMMENT 'obsoleta (comprobar)', `hasCoreVnl` tinyint(1) DEFAULT '0', `riskCalculated` date NOT NULL, `hasCoreVnh` tinyint(1) DEFAULT '0', `isRelevant` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Define los clientes cuyas ventas hay que tener en cuenta en los calculos estadisticos.', `clientTypeFk` int(11) NOT NULL DEFAULT '1', - `postcodeOld` int(11) unsigned DEFAULT NULL COMMENT 'obsoleta (comprobar)', + `postcodeOld__` int(11) unsigned DEFAULT NULL COMMENT 'obsoleta (comprobar)', `mailAddress` int(11) DEFAULT NULL, - `codposOLD` char(5) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', + `codposOLD__` char(5) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', `creditInsurance` int(11) DEFAULT NULL, `eypbc` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Email\\nYesterday\\nPurchases\\nBy\\nConsigna', `hasToInvoiceByAddress` tinyint(1) DEFAULT '0', @@ -26272,7 +26495,7 @@ CREATE TABLE `client` ( KEY `Telefono` (`phone`), KEY `movil` (`mobile`), KEY `tipos_de_cliente_idx` (`clientTypeFk`), - KEY `codpos` (`codposOLD`,`postcode`), + KEY `codpos` (`codposOLD__`,`postcode`), KEY `fk_Clientes_entity_idx` (`bankEntityFk`), KEY `typeFk` (`typeFk`), KEY `client_taxTypeSageFk_idx` (`taxTypeSageFk`), @@ -27005,6 +27228,26 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `collectionSmartTag` +-- + +DROP TABLE IF EXISTS `collectionSmartTag`; +/*!50001 DROP VIEW IF EXISTS `collectionSmartTag`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `collectionSmartTag` ( + `code` tinyint NOT NULL, + `ticketFk` tinyint NOT NULL, + `level` tinyint NOT NULL, + `wagon` tinyint NOT NULL, + `shelvingFk` tinyint NOT NULL, + `collectionFk` tinyint NOT NULL, + `agencyFk` tinyint NOT NULL, + `clientFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `collectionVolumetry` -- @@ -27018,18 +27261,21 @@ CREATE TABLE `collectionVolumetry` ( `lines` int(10) unsigned NOT NULL DEFAULT '1', `liters` int(10) unsigned NOT NULL DEFAULT '0', `height` int(10) unsigned NOT NULL DEFAULT '20', - PRIMARY KEY (`id`) + `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'H', + PRIMARY KEY (`id`), + KEY `collectionVolumetry_FK` (`itemPackingTypeFk`), + CONSTRAINT `collectionVolumetry_FK` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `collectionVolumetry_Paloma` +-- Table structure for table `collectionVolumetry_Paloma__` -- -DROP TABLE IF EXISTS `collectionVolumetry_Paloma`; +DROP TABLE IF EXISTS `collectionVolumetry_Paloma__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `collectionVolumetry_Paloma` ( +CREATE TABLE `collectionVolumetry_Paloma__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `level` int(10) unsigned NOT NULL DEFAULT '0', `lines` int(10) unsigned NOT NULL DEFAULT '1', @@ -27130,6 +27376,7 @@ CREATE TABLE `component` ( `tax` double DEFAULT NULL, `isRenewable` tinyint(2) NOT NULL DEFAULT '1', `code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `isRequired` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Son componentes imprescindibles en toda venta', PRIMARY KEY (`id`), KEY `series_componentes_idx` (`typeFk`), KEY `comp` (`classRate`), @@ -27480,6 +27727,21 @@ CREATE TABLE `conveyorType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `corridor` +-- + +DROP TABLE IF EXISTS `corridor`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `corridor` ( + `code` varchar(1) COLLATE utf8_unicode_ci NOT NULL COMMENT 'letra que da nombre al pasillo', + `isAscendent` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'TRUE cuando se prepara de menor a mayor, FALSE cuando es a la inversa', + `prepOrder` int(10) unsigned NOT NULL COMMENT 'orden de preparacion de los pasillos', + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='establece el orden y sentido de preparacion de los pasillos del parking'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `country` -- @@ -28179,7 +28441,7 @@ CREATE TABLE `dms` ( `hasFile` tinyint(4) NOT NULL DEFAULT '0', `workerFk` int(11) DEFAULT NULL, `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT '1', + `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT '60', PRIMARY KEY (`id`), UNIQUE KEY `emp_id` (`companyFk`,`hardCopyNumber`,`warehouseFk`), KEY `trabajador_id` (`workerFk`), @@ -28202,11 +28464,11 @@ CREATE TABLE `dms` ( DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`dms_beforeInsert` BEFORE INSERT ON `vn`.`dms` FOR EACH ROW BEGIN - DECLARE vHardCopyNumber INT; - DECLARE vDmsTypeCode INT; - - IF NEW.warehouseFk = 44 THEN - SET NEW.warehouseFk = 1; + DECLARE vHardCopyNumber INT; + DECLARE vDmsTypeCode INT; + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + CALL util.throw('this warehouse has not dms'); END IF; IF NEW.hasFile THEN @@ -28214,7 +28476,7 @@ BEGIN FROM dms WHERE companyFk = NEW.companyFk AND warehouseFk = NEW.warehouseFk ; - + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1) ; END IF; @@ -28241,15 +28503,21 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` BEFORE UPDATE ON `vn`.`dms` FOR EACH ROW BEGIN DECLARE vHardCopyNumber INT; + IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) THEN - + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); + END IF; + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber FROM dms WHERE companyFk = NEW.companyFk AND warehouseFk = NEW.warehouseFk; - + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); END IF; + IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN SET NEW.hasFile = 0; @@ -29119,7 +29387,7 @@ CREATE TABLE `expedition` ( `counter` smallint(5) unsigned NOT NULL, `checked` tinyint(4) NOT NULL DEFAULT '0', `workerFk` int(11) DEFAULT NULL, - `externalId` bigint(25) DEFAULT NULL, + `externalId` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `packagingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), @@ -29326,7 +29594,8 @@ SET character_set_client = utf8; `eti` tinyint NOT NULL, `palletFk` tinyint NOT NULL, `isMatch` tinyint NOT NULL, - `warehouseFk` tinyint NOT NULL + `warehouseFk` tinyint NOT NULL, + `nombreDia` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -29343,7 +29612,8 @@ SET character_set_client = utf8; `tickets` tinyint NOT NULL, `expeditions` tinyint NOT NULL, `scanned` tinyint NOT NULL, - `lastPacked` tinyint NOT NULL + `lastPacked` tinyint NOT NULL, + `created` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -29360,7 +29630,8 @@ SET character_set_client = utf8; `ticket` tinyint NOT NULL, `code` tinyint NOT NULL, `almacen` tinyint NOT NULL, - `updated` tinyint NOT NULL + `updated` tinyint NOT NULL, + `parkingCode` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -29429,6 +29700,31 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `expeditionSticker` +-- + +DROP TABLE IF EXISTS `expeditionSticker`; +/*!50001 DROP VIEW IF EXISTS `expeditionSticker`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `expeditionSticker` ( + `expeditionFk` tinyint NOT NULL, + `ticketFk` tinyint NOT NULL, + `addressFk` tinyint NOT NULL, + `clientFk` tinyint NOT NULL, + `street` tinyint NOT NULL, + `postalCode` tinyint NOT NULL, + `city` tinyint NOT NULL, + `nickname` tinyint NOT NULL, + `routeFk` tinyint NOT NULL, + `beachFk` tinyint NOT NULL, + `zona` tinyint NOT NULL, + `province` tinyint NOT NULL, + `phone` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `expeditionTimeExpended` -- @@ -29874,6 +30170,7 @@ CREATE TABLE `ink` ( `isCargex` tinyint(4) NOT NULL DEFAULT '0', `dutchCode` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `hex` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, + `isRealColor` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `dutchCode_UNIQUE` (`dutchCode`), CONSTRAINT `ink_fk1` FOREIGN KEY (`dutchCode`) REFERENCES `edi`.`feature` (`feature_value`) ON DELETE SET NULL ON UPDATE CASCADE @@ -30064,6 +30361,7 @@ CREATE TABLE `invoiceIn` ( `bookEntried` date DEFAULT NULL COMMENT 'Fecha Asiento', `isVatDeductible` tinyint(1) NOT NULL DEFAULT '1', `withholdingSageFk` smallint(6) DEFAULT NULL COMMENT 'Tipos de retención SAGE', + `expenceFkDeductible` varchar(10) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`), KEY `proveedor_id` (`supplierFk`), KEY `empresa_id` (`companyFk`), @@ -30077,6 +30375,8 @@ CREATE TABLE `invoiceIn` ( KEY `recibida_ibfk_6` (`cplusRectificationTypeFk`), KEY `recibida_ibfk_7` (`cplusTrascendency472Fk`), KEY `invoiceIn_withholdingFk_idx` (`withholdingSageFk`), + KEY `invoiceIn_expenceFkDeductible` (`expenceFkDeductible`), + CONSTRAINT `invoiceIn_expenceFkDeductible` FOREIGN KEY (`expenceFkDeductible`) REFERENCES `expence` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_ibfk_1` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_ibfk_2` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_ibfk_3` FOREIGN KEY (`cplusSubjectOpFk`) REFERENCES `cplusSubjectOp` (`id`) ON UPDATE CASCADE, @@ -30097,53 +30397,58 @@ CREATE TABLE `invoiceIn` ( /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `invoiceIn_bi` BEFORE INSERT ON `invoiceIn` FOR EACH ROW BEGIN - DECLARE vSerie CHAR(1) DEFAULT 'R'; - DECLARE vNumReceived INT; - DECLARE vIssuingCountry, vhostCountry INT; - DECLARE vActive TINYINT; - DECLARE vWithholdingSageFk INT; - - SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier - WHERE id = NEW.supplierFk; - - SET NEW.withholdingSageFk = vWithholdingSageFk; - - SELECT countryFk, isActive INTO vIssuingCountry, vActive - FROM vn.supplier - WHERE id = NEW.supplierFk; - - SELECT countryFk INTO vhostCountry - FROM vn.supplier - WHERE id = NEW.companyFk; - - IF vActive = 0 THEN - CALL util.throw('INACTIVE_PROVIDER'); - END IF; - - IF (SELECT COUNT(*) FROM vn.invoiceIn WHERE supplierRef = NEW.supplierRef AND supplierFk = NEW.supplierFk AND YEAR(issued) = YEAR(CURDATE())) THEN - CALL util.throw('reference duplicated'); - END IF; - - SELECT CASE WHEN (SELECT account FROM vn.supplier where id = NEW.supplierFk) LIKE '___3______' THEN 'C' - WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' - WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' - WHEN (SELECT vIssuingCountry<>vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' - END INTO vSerie; - - SET NEW.serial = IFNULL(vSerie,'R'); + DECLARE vSerie CHAR(1) DEFAULT 'R'; + DECLARE vNumReceived INT; + DECLARE vIssuingCountry, vhostCountry INT; + DECLARE vActive TINYINT; + DECLARE vWithholdingSageFk INT; - IF vSerie LIKE 'W' THEN - SELECT IFNULL(MAX(serialNumber) + 1,1) INTO vNumReceived - FROM invoiceIn - WHERE `serial` LIKE NEW.serial AND - YEAR(issued) = YEAR(NEW.issued) AND - companyFk = NEW.companyFk; - SET NEW.serialNumber = vNumReceived; - END IF; + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier + WHERE id = NEW.supplierFk; + + SET NEW.withholdingSageFk = vWithholdingSageFk; + + SELECT countryFk, isActive INTO vIssuingCountry, vActive + FROM vn.supplier + WHERE id = NEW.supplierFk; + + SELECT countryFk INTO vhostCountry + FROM vn.supplier + WHERE id = NEW.companyFk; + + IF vActive = 0 THEN + CALL util.throw('INACTIVE_PROVIDER'); + END IF; + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + AND id = NEW.id + ) THEN + CALL util.throw('reference duplicated'); + END IF; + + SELECT CASE WHEN (SELECT account FROM vn.supplier where id = NEW.supplierFk) LIKE '___3______' THEN 'C' + WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' + WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' + WHEN (SELECT vIssuingCountry<>vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' + END INTO vSerie; + + SET NEW.serial = IFNULL(vSerie,'R'); + + IF vSerie LIKE 'W' THEN + SELECT IFNULL(MAX(serialNumber) + 1,1) INTO vNumReceived + FROM invoiceIn + WHERE `serial` LIKE NEW.serial AND + YEAR(issued) = YEAR(NEW.issued) AND + companyFk = NEW.companyFk; + SET NEW.serialNumber = vNumReceived; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -30163,13 +30468,23 @@ DELIMITER ;; BEGIN DECLARE vWithholdingSageFk INT; - + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + AND id <> NEW.id + ) THEN + CALL util.throw('reference duplicated'); + END IF; + IF NEW.supplierFk != OLD.supplierFk THEN - SELECT withholdingSageFk INTO vWithholdingSageFk + SELECT withholdingSageFk INTO vWithholdingSageFk FROM vn.supplier WHERE id = NEW.supplierFk; SET NEW.withholdingSageFk = vWithholdingSageFk; - END IF; + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -30193,7 +30508,7 @@ BEGIN NEW.currencyFk != OLD.currencyFk THEN - -- CALL vn2008.recibidaIvaDivisaUpdate(NEW.id); + CALL vn2008.recibidaIvaDivisaUpdate(NEW.id); END IF; @@ -30389,6 +30704,39 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `invoiceInSage` +-- + +DROP TABLE IF EXISTS `invoiceInSage`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `invoiceInSage` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `taxClassFk` varchar(1) COLLATE utf8_unicode_ci NOT NULL, + `invoiceInSerialFk` varchar(2) COLLATE utf8_unicode_ci NOT NULL, + `taxTypeSageFk` smallint(6) NOT NULL, + `transactionTypeSageFk` tinyint(4) NOT NULL, + `isService` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para diferenciar producto de servicio', + `expenceFk` varchar(10) CHARACTER SET utf8 NOT NULL, + `withholdingSageFk` smallint(6) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `invoiceInSafe_unique` (`taxClassFk`,`invoiceInSerialFk`,`isService`,`withholdingSageFk`), + KEY `invoiceInSage_expenceFk` (`expenceFk`), + KEY `invoiceInSage_withholdingSageFk` (`withholdingSageFk`), + KEY `invoiceInSage_taxClassFk` (`taxClassFk`), + KEY `invoiceInSage_invoiceInSerialFk` (`invoiceInSerialFk`), + KEY `invoiceInSage_taxTypeSageFk` (`taxTypeSageFk`), + KEY `invoiceInSage_transactionTypeSageFk` (`transactionTypeSageFk`), + CONSTRAINT `invoiceInSage_expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `expence` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_invoiceInSerialFk` FOREIGN KEY (`invoiceInSerialFk`) REFERENCES `invoiceInSerial` (`code`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_taxClassFk` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`code`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_taxTypeSageFk` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_withholdingSageFk` FOREIGN KEY (`withholdingSageFk`) REFERENCES `sage`.`TiposRetencion` (`CodigoRetencion`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciones de entrelas series de facturas recibidas y sus tipo de IVA con código Iva y codigo de Transación en Sage. Para precontabilizadar facturas recibidas'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `invoiceInSerial` -- @@ -30419,7 +30767,7 @@ DROP TABLE IF EXISTS `invoiceInTax`; CREATE TABLE `invoiceInTax` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `invoiceInFk` mediumint(8) unsigned NOT NULL, - `taxCodeFk` int(10) unsigned NOT NULL, + `taxCodeFk` int(10) DEFAULT NULL, `taxableBase` decimal(10,2) NOT NULL, `expenceFk` varchar(10) CHARACTER SET utf8 NOT NULL, `foreignValue` decimal(10,2) DEFAULT NULL, @@ -30432,40 +30780,12 @@ CREATE TABLE `invoiceInTax` ( KEY `recibida_iva_gastos_id` (`expenceFk`), KEY `recibida_iva_taxTypeSageFk` (`taxTypeSageFk`), KEY `invoiceInTax_transactionTypeSageFk_idx` (`transactionTypeSageFk`), - CONSTRAINT `invoiceInTax_ibfk_2` FOREIGN KEY (`taxCodeFk`) REFERENCES `taxCode` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `invoiceInTax_ibfk_5` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInTax_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, CONSTRAINT `recibida_iva_gastos_id` FOREIGN KEY (`expenceFk`) REFERENCES `expence` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `recibida_iva_taxTypeSageFk` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_beforeInsert` BEFORE INSERT ON `invoiceInTax` FOR EACH ROW -BEGIN - DECLARE vTaxTypeSageFk INT; - DECLARE vTransactionTypeSageFk INT; - - SELECT taxTypeSageFk, transactionTypeSageFk INTO vTaxTypeSageFk,vTransactionTypeSageFk - FROM vn.supplier s - JOIN vn.invoiceIn i On i.supplierFk = s.id - WHERE i.id = NEW.invoiceInFk; - - SET NEW.taxTypeSageFk = vTaxTypeSageFk; - SET NEW.transactionTypeSageFk = vTransactionTypeSageFk; -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_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 `invoiceInTaxBookingAccount` @@ -30535,8 +30855,8 @@ DROP TABLE IF EXISTS `invoiceOut`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `invoiceOut` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `ref` varchar(15) COLLATE utf8_unicode_ci NOT NULL, - `serial` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, + `ref` varchar(20) COLLATE utf8_unicode_ci NOT NULL, + `serial` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `issued` date DEFAULT NULL, `amount` decimal(12,2) DEFAULT '0.00', `dued` datetime DEFAULT NULL, @@ -30573,10 +30893,12 @@ CREATE TABLE `invoiceOut` ( KEY `Facturas_ibfk_4_idx` (`cplusTaxBreakFk`), KEY `Facturas_ibfk_5_idx` (`cplusTrascendency477Fk`), KEY `Facturas_idx_Vencimiento` (`dued`), + KEY `invoiceOut_serial` (`serial`), CONSTRAINT `invoiceOut_ibfk_1` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceOut_ibfk_2` FOREIGN KEY (`cplusInvoiceType477Fk`) REFERENCES `cplusInvoiceType477` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceOut_ibfk_3` FOREIGN KEY (`cplusSubjectOpFk`) REFERENCES `cplusSubjectOp` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceOut_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `cplusTaxBreak` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceOut_serial` FOREIGN KEY (`serial`) REFERENCES `invoiceOutSerial` (`code`), CONSTRAINT `invoice_bank_id` FOREIGN KEY (`bankFk`) REFERENCES `bank` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -30717,6 +31039,7 @@ CREATE TABLE `invoiceOutSerial` ( `isCEE` tinyint(1) NOT NULL DEFAULT '0', `cplusInvoiceType477Fk` int(10) unsigned DEFAULT '1', `footNotes` longtext COLLATE utf8_unicode_ci, + `isRefEditable` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`code`), KEY `taxAreaFk_idx` (`taxAreaFk`), CONSTRAINT `invoiceOutSeriaTaxArea` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON UPDATE CASCADE @@ -30763,7 +31086,7 @@ CREATE TABLE `item` ( `isToPrint` tinyint(1) NOT NULL DEFAULT '0', `isDeliveryNote__` tinyint(1) NOT NULL DEFAULT '0', `taxClassFk` tinyint(4) unsigned NOT NULL DEFAULT '1', - `family` varchar(3) COLLATE utf8_unicode_ci DEFAULT 'VT', + `family` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT 'VT', `box` tinyint(1) NOT NULL DEFAULT '0', `category` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `originFk` tinyint(2) unsigned NOT NULL, @@ -30813,6 +31136,7 @@ CREATE TABLE `item` ( `stars` int(11) DEFAULT NULL, `stemMultiplier` double NOT NULL DEFAULT '1' COMMENT 'este valor multiplica las unidades y divide los precios en el procedimiento edi.ekt_load', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, + `packingOut` int(11) DEFAULT NULL COMMENT 'cantidad que cabe en una caja de verdnatura', PRIMARY KEY (`id`), UNIQUE KEY `item_supplyResponseFk_idx` (`supplyResponseFk`), KEY `Color` (`inkFk`), @@ -30828,7 +31152,9 @@ CREATE TABLE `item` ( KEY `item_id10` (`embalageCode`), KEY `item_id11` (`numberOfItemsPerCask`), KEY `item_id12` (`quality`), + KEY `item_family` (`family`), CONSTRAINT `item_expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `expence` (`id`) ON UPDATE CASCADE, + CONSTRAINT `item_family` FOREIGN KEY (`family`) REFERENCES `itemFamily` (`code`) ON UPDATE CASCADE, CONSTRAINT `item_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `origin` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_ibfk_2` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_ibfk_4` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE, @@ -30937,6 +31263,9 @@ BEGIN IF NEW.density = 0 THEN CALL util.throw('error densidad = 0'); END IF; + IF (SELECT NEW.compression < minCompressionRate FROM vn.volumeConfig vc) AND NEW.compression < OLD.compression THEN + CALL util.throw('compression too low'); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -31256,6 +31585,20 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `itemFamily` +-- + +DROP TABLE IF EXISTS `itemFamily`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemFamily` ( + `code` varchar(3) CHARACTER SET utf8 NOT NULL, + `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `itemImageQueue` -- @@ -31276,6 +31619,20 @@ CREATE TABLE `itemImageQueue` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cola para añadir las imagenes al campo vn.item.image a partir de una url'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `itemInk` +-- + +DROP TABLE IF EXISTS `itemInk`; +/*!50001 DROP VIEW IF EXISTS `itemInk`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `itemInk` ( + `longName` tinyint NOT NULL, + `inkFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `itemLabel` -- @@ -32246,7 +32603,7 @@ CREATE TABLE `itemType` ( `target` double NOT NULL DEFAULT '0.15', `topMargin` double NOT NULL DEFAULT '0.3', `profit` double NOT NULL DEFAULT '0.02', - `isFV` tinyint(3) DEFAULT '1', + `isFV__` tinyint(3) DEFAULT '1', `density` double NOT NULL DEFAULT '167' COMMENT 'Almacena el valor por defecto de la densidad en kg/m3 para el calculo de los portes aereos, en articulos se guarda la correcta', `promo` double NOT NULL DEFAULT '0', `isBox__` tinyint(4) NOT NULL DEFAULT '0', @@ -32405,6 +32762,20 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `labelReport` +-- + +DROP TABLE IF EXISTS `labelReport`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `labelReport` ( + `id` tinyint(3) unsigned NOT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `labourTree` -- @@ -32483,6 +32854,108 @@ CREATE TABLE `lungSize` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `machine` +-- + +DROP TABLE IF EXISTS `machine`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `machine` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plate` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `serialNumber` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, + `maker` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `model` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `purchased` date DEFAULT NULL, + `warehouseFk` int(11) DEFAULT NULL, + `departmentFk` int(11) DEFAULT NULL, + `type` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + `use` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + `productionYear` int(11) DEFAULT NULL, + `photo` blob, + `workerFk` int(11) DEFAULT NULL, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', + `ppeFk` int(11) DEFAULT NULL, + `supplierFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `plate` (`plate`), + UNIQUE KEY `serialNumber` (`serialNumber`), + KEY `machine_FK` (`ppeFk`), + KEY `machine_FK_1` (`workerFk`), + KEY `machine_FK_2` (`supplierFk`), + CONSTRAINT `machine_FK` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `machine_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `machine_FK_2` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Maquinaria industrial, vehículos y demás elementos amortizables'; +/*!40101 SET character_set_client = @saved_cs_client */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!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 machine_BI +BEFORE INSERT +ON machine FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; + +-- +-- Table structure for table `machineDetail` +-- + +DROP TABLE IF EXISTS `machineDetail`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `machineDetail` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `machineFk` int(11) NOT NULL, + `dated` date NOT NULL, + `action` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `value` decimal(10,2) DEFAULT NULL, + `workerFk` int(11) NOT NULL, + `dmsFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `machineDetail_FK` (`machineFk`), + KEY `machineDetail_FK_1` (`workerFk`), + KEY `machineDetail_FK_2` (`dmsFk`), + CONSTRAINT `machineDetail_FK` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `machineDetail_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `machineDetail_FK_2` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `machineDms` +-- + +DROP TABLE IF EXISTS `machineDms`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `machineDms` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `machineFk` int(11) NOT NULL, + `dmsFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `machineDms_UN` (`machineFk`,`dmsFk`), + KEY `machineDms_FK` (`dmsFk`), + CONSTRAINT `machineDms_FK` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `machineDms_FK_1` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `mail` -- @@ -32858,6 +33331,20 @@ CREATE TABLE `observationType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `occupationCode` +-- + +DROP TABLE IF EXISTS `occupationCode`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `occupationCode` ( + `code` varchar(1) CHARACTER SET utf8 NOT NULL, + `name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Código de ocupación de la seguridad social'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `orderTicket` -- @@ -33036,8 +33523,9 @@ DROP TABLE IF EXISTS `packagingConfig`; CREATE TABLE `packagingConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `upperGap` int(11) NOT NULL, + `previousPreparationMinimumSize` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Altura mínima para preparar pedidos en preparacion previa'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33805,7 +34293,7 @@ CREATE TABLE `printServerQueue` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `printerFk` tinyint(3) unsigned DEFAULT NULL, `priorityFk` tinyint(3) unsigned DEFAULT NULL, - `reportFk` tinyint(3) unsigned DEFAULT '0', + `labelReportFk` tinyint(3) unsigned DEFAULT '0', `statusFk` tinyint(3) unsigned DEFAULT '1', `started` datetime DEFAULT NULL, `finished` datetime DEFAULT NULL, @@ -33815,11 +34303,11 @@ CREATE TABLE `printServerQueue` ( `param3` text COLLATE utf8_unicode_ci, `error` text COLLATE utf8_unicode_ci, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `reportFk` tinyint(3) DEFAULT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `Id_Impresora_2` (`printerFk`,`priorityFk`,`reportFk`,`statusFk`,`param1`,`workerFk`,`param2`), + UNIQUE KEY `Id_Impresora_2` (`printerFk`,`priorityFk`,`labelReportFk`,`statusFk`,`param1`,`workerFk`,`param2`), KEY `Id_estado` (`statusFk`), KEY `Id_Impresora` (`printerFk`), - KEY `Id_Informe` (`reportFk`), KEY `Id_Prioridad` (`priorityFk`), KEY `Id_Trabajador` (`workerFk`), CONSTRAINT `printServerQueue_ibfk_3` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE, @@ -34636,6 +35124,14 @@ CREATE TABLE `routeConfig` ( `load5m3` decimal(10,4) DEFAULT NULL, `load6m3` decimal(10,4) DEFAULT NULL, `rateHoliday` decimal(5,2) DEFAULT NULL, + `plusCategory1` decimal(5,2) DEFAULT NULL, + `plusCategory2` decimal(5,2) DEFAULT NULL, + `maxSalaryCategory1` decimal(6,2) DEFAULT NULL, + `maxSalaryCategory2` decimal(6,2) DEFAULT NULL, + `distributionM3Category1` decimal(5,2) DEFAULT NULL, + `distributionM3Category2` decimal(5,2) DEFAULT NULL, + `plusCategory1Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `plusCategory2Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -34763,30 +35259,31 @@ CREATE TABLE `routeUserPercentage` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Temporary table structure for view `routesMonitor` +-- Table structure for table `routesMonitor` -- DROP TABLE IF EXISTS `routesMonitor`; -/*!50001 DROP VIEW IF EXISTS `routesMonitor`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `routesMonitor` ( - `routeFk` tinyint NOT NULL, - `name` tinyint NOT NULL, - `beachFk` tinyint NOT NULL, - `ticketPacked` tinyint NOT NULL, - `ticketFree` tinyint NOT NULL, - `ticketProduction` tinyint NOT NULL, - `packages` tinyint NOT NULL, - `note` tinyint NOT NULL, - `dated` tinyint NOT NULL, - `dockFk` tinyint NOT NULL, - `m3` tinyint NOT NULL, - `priority` tinyint NOT NULL, - `etd` tinyint NOT NULL, - `expeditionTruckFk` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `routesMonitor` ( + `routeFk` int(10) unsigned NOT NULL, + `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `beachFk` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `ticketPacked` int(11) DEFAULT NULL, + `ticketFree` int(11) DEFAULT NULL, + `ticketProduction` int(11) DEFAULT NULL, + `packages` int(11) DEFAULT NULL, + `note` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `dated` date DEFAULT NULL, + `dockFk` int(11) DEFAULT NULL, + `m3` decimal(10,1) DEFAULT NULL, + `priority` int(11) NOT NULL DEFAULT '0', + `etd` time DEFAULT NULL, + `expeditionTruckFk` int(11) DEFAULT NULL, + `m3boxes` decimal(10,1) DEFAULT NULL, + PRIMARY KEY (`routeFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `sale` @@ -34820,16 +35317,22 @@ CREATE TABLE `sale` ( /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sale_afterInsert` - AFTER INSERT ON `sale` +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER sale_afterInsert + AFTER INSERT + ON sale FOR EACH ROW -BEGIN +BEGIN + + IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN + CALL util.throw('Cannot insert a service item into a ticket'); + END IF; + CALL stock.log_add('sale', NEW.id, NULL); CALL ticket_requestRecalc(NEW.ticketFk); @@ -34857,12 +35360,17 @@ DELIMITER ; /*!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 sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sale_beforeUpdate` - BEFORE UPDATE ON `sale` +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER sale_beforeUpdate + BEFORE UPDATE + ON sale FOR EACH ROW BEGIN + + IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN + CALL util.throw('Cannot insert a service item into a ticket'); + END IF; IF NEW.discount > 100 THEN SET NEW.discount = 0; @@ -34970,9 +35478,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -35008,7 +35516,7 @@ BEGIN AND (c.itemPackingTypeFk = i.itemPackingTypeFk OR ISNULL(c.itemPackingTypeFk)) SET c.saleTotalCount = c.saleTotalCount - 1, - c.salePickedCount = c.salePickedCount - 1; + c.salePickedCount = c.salePickedCount - ABS(OLD.isPicked); END IF; END */;; @@ -35059,6 +35567,30 @@ DELIMITER ; /*!50003 SET 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 saleBuy_AI +AFTER INSERT +ON saleBuy FOR EACH ROW +BEGIN + + UPDATE vn.sale s + SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk) + WHERE s.id = NEW.saleFk; + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_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 `saleChecked` @@ -35112,6 +35644,26 @@ CREATE TABLE `saleComponent` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `saleCost` +-- + +DROP TABLE IF EXISTS `saleCost`; +/*!50001 DROP VIEW IF EXISTS `saleCost`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `saleCost` ( + `itemFk` tinyint NOT NULL, + `ticketFk` tinyint NOT NULL, + `concept` tinyint NOT NULL, + `quantity` tinyint NOT NULL, + `discount` tinyint NOT NULL, + `price` tinyint NOT NULL, + `component` tinyint NOT NULL, + `coste` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `saleFreight__` -- @@ -35271,6 +35823,7 @@ CREATE TABLE `saleTracking` ( KEY `saleTracking_idx5` (`created`), KEY `saleTracking_fk2_idx` (`actionFk`), CONSTRAINT `fgnStateFk` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE, + CONSTRAINT `saleTracking_FK` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleTracking_fk2` FOREIGN KEY (`actionFk`) REFERENCES `vncontrol`.`accion` (`accion_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -35342,6 +35895,7 @@ SET character_set_client = utf8; `client` tinyint NOT NULL, `clientTypeFk` tinyint NOT NULL, `buyer` tinyint NOT NULL, + `itemTypeFk` tinyint NOT NULL, `family` tinyint NOT NULL, `itemFk` tinyint NOT NULL, `concept` tinyint NOT NULL, @@ -35497,15 +36051,19 @@ CREATE TABLE `sector` ( `path` int(11) DEFAULT NULL, `isPreviousPrepared` tinyint(1) NOT NULL DEFAULT '0', `isPackagingArea` tinyint(1) NOT NULL DEFAULT '0', - `labelReport` int(11) DEFAULT NULL, + `labelReportFk` tinyint(3) unsigned DEFAULT NULL, `sonFk` int(11) DEFAULT NULL, `isMain` tinyint(1) NOT NULL DEFAULT '0', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `workerFk` int(11) DEFAULT NULL, + `labelReport` tinyint(3) DEFAULT NULL, + `printerFk` tinyint(3) unsigned DEFAULT NULL, PRIMARY KEY (`id`,`warehouseFk`), UNIQUE KEY `code_UNIQUE` (`code`), KEY `sector_fk1_idx` (`warehouseFk`), - CONSTRAINT `sector_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + KEY `sector_labelReport` (`labelReportFk`), + CONSTRAINT `sector_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `sector_labelReport` FOREIGN KEY (`labelReportFk`) REFERENCES `labelReport` (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -35794,6 +36352,25 @@ CREATE TABLE `sinisterDetail` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `smartTag` +-- + +DROP TABLE IF EXISTS `smartTag`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `smartTag` ( + `code` varchar(12) CHARACTER SET utf8 NOT NULL, + `shelvingFk` varchar(10) CHARACTER SET utf8 DEFAULT NULL, + `level` int(11) DEFAULT NULL, + `ticketFk` int(11) DEFAULT NULL, + KEY `ticket_fk` (`ticketFk`), + KEY `smartTag_shelving_fk` (`shelvingFk`), + CONSTRAINT `smartTag_shelving_fk` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON UPDATE CASCADE, + CONSTRAINT `smartTag_ticket_fk` FOREIGN KEY (`ticketFk`) REFERENCES `ticketCollection` (`ticketFk`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `sms` -- @@ -36194,6 +36771,7 @@ CREATE TABLE `supplierAccount` ( `bicSufix` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '', `bankEntityFk` int(10) DEFAULT NULL, `bankFk` int(11) DEFAULT NULL COMMENT 'obsoleta(comprobar)', + `beneficiary` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), KEY `fk_Proveedores_account_entity1_idx` (`bankEntityFk`), @@ -36490,7 +37068,8 @@ CREATE TABLE `taxClass` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `code` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'R', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `code_UNIQUE` (`code`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -36771,9 +37350,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -36802,7 +37381,16 @@ BEGIN `body` = CONCAT(account.myUserGetName(), ' ha modificado el ticket ', NEW.id); END IF; - + + IF !(NEW.addressFk <=> OLD.addressFk) THEN + DELETE FROM ticketObservation + WHERE ticketFk = NEW.id; + + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT NEW.id, ao.observationTypeFk, ao.description + FROM addressObservation ao + WHERE ao.addressFk = NEW.addressFk; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36846,9 +37434,11 @@ CREATE TABLE `ticketCollection` ( `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `level` int(11) DEFAULT NULL, `wagon` int(11) NOT NULL DEFAULT '0', + `smartTagFk` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `ticketCollection_fk1_idx` (`collectionFk`), KEY `ticketCollection_fk2_idx` (`ticketFk`), + KEY `ticketCollection_smartTagFk_IDX` (`smartTagFk`) USING BTREE, CONSTRAINT `ticketCollection_fk1` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketCollection_fk2` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -37086,6 +37676,34 @@ CREATE TABLE `ticketLog` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `ticketMRW` +-- + +DROP TABLE IF EXISTS `ticketMRW`; +/*!50001 DROP VIEW IF EXISTS `ticketMRW`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `ticketMRW` ( + `id_Agencia` tinyint NOT NULL, + `empresa_id` tinyint NOT NULL, + `Consignatario` tinyint NOT NULL, + `DOMICILIO` tinyint NOT NULL, + `POBLACION` tinyint NOT NULL, + `CODPOSTAL` tinyint NOT NULL, + `telefono` tinyint NOT NULL, + `movil` tinyint NOT NULL, + `IF` tinyint NOT NULL, + `Id_Ticket` tinyint NOT NULL, + `warehouse_id` tinyint NOT NULL, + `Id_Consigna` tinyint NOT NULL, + `CodigoPais` tinyint NOT NULL, + `Fecha` tinyint NOT NULL, + `province_id` tinyint NOT NULL, + `landing` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `ticketNotInvoiced` -- @@ -37207,6 +37825,26 @@ CREATE TABLE `ticketPackagingStartingStock` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `ticketPackingList` +-- + +DROP TABLE IF EXISTS `ticketPackingList`; +/*!50001 DROP VIEW IF EXISTS `ticketPackingList`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `ticketPackingList` ( + `nickname` tinyint NOT NULL, + `ticketFk` tinyint NOT NULL, + `agencyMode` tinyint NOT NULL, + `flag` tinyint NOT NULL, + `province` tinyint NOT NULL, + `itemFk` tinyint NOT NULL, + `concept` tinyint NOT NULL, + `quantity` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `ticketParking` -- @@ -37814,6 +38452,43 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `traceabilityBuy` +-- + +DROP TABLE IF EXISTS `traceabilityBuy`; +/*!50001 DROP VIEW IF EXISTS `traceabilityBuy`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `traceabilityBuy` ( + `buyFk` tinyint NOT NULL, + `quantity` tinyint NOT NULL, + `landed` tinyint NOT NULL, + `warehouseName` tinyint NOT NULL, + `entryFk` tinyint NOT NULL, + `supplierName` tinyint NOT NULL, + `itemFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `traceabilitySale` +-- + +DROP TABLE IF EXISTS `traceabilitySale`; +/*!50001 DROP VIEW IF EXISTS `traceabilitySale`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `traceabilitySale` ( + `ticketFk` tinyint NOT NULL, + `buyFk` tinyint NOT NULL, + `shipped` tinyint NOT NULL, + `nickname` tinyint NOT NULL, + `quantity` tinyint NOT NULL, + `worker` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `trainingCenter` -- @@ -38223,8 +38898,13 @@ DROP TABLE IF EXISTS `volumeConfig`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `volumeConfig` ( - `espai` decimal(10,2) DEFAULT NULL, - `carro` decimal(10,2) DEFAULT NULL + `espai` decimal(10,2) DEFAULT NULL COMMENT 'metros cúbicos', + `carro` decimal(10,2) DEFAULT NULL COMMENT 'metros cúbicos', + `dutchCompressionRate` double NOT NULL DEFAULT '1', + `standardFlowerBox` int(11) NOT NULL COMMENT 'en litros', + `minCompressionRate` decimal(10,2) DEFAULT '0.30' COMMENT 'minimo permitido por la empresa', + `ccLength` int(11) NOT NULL DEFAULT '130' COMMENT 'longitud útil para la carga de un CC, en cm', + `ccWidth` int(11) NOT NULL DEFAULT '60' COMMENT 'ancho útil para la carga en un CC, en cm' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='almacena el valor standard para volumenes convencionales de Verdnatura, en metros cúbicos'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -38293,11 +38973,16 @@ CREATE TABLE `warehouse` ( `aliasFk` smallint(5) unsigned DEFAULT NULL, `labelReport` int(11) DEFAULT NULL, `hasUbications` tinyint(1) NOT NULL DEFAULT '1', + `hasProduction` tinyint(1) NOT NULL DEFAULT '0', + `addressFk` int(11) DEFAULT NULL, + `hasMachine` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`), KEY `Id_Paises` (`countryFk`), KEY `isComparativeIdx` (`isComparative`), KEY `warehouse_ibfk_1_idx` (`aliasFk`), + KEY `warehouse_FK` (`addressFk`), + CONSTRAINT `warehouse_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `warehouse_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`), CONSTRAINT `warehouse_ibfk_2` FOREIGN KEY (`aliasFk`) REFERENCES `warehouseAlias` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -38430,7 +39115,7 @@ CREATE TABLE `worker` ( `userFk` int(10) unsigned DEFAULT NULL, `bossFk` int(11) NOT NULL DEFAULT '103', `fiDueDate` datetime DEFAULT NULL, - `hasMachineryAutorized` tinyint(2) DEFAULT '0', + `hasMachineryAuthorized` tinyint(2) DEFAULT '0', `seniority` date DEFAULT NULL, `isTodayRelative` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para el F11. Calcula los problemas de visiblidad en funcion del dia actual', `isF11Allowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Usuario autorizado para abrir el F11', @@ -38466,6 +39151,21 @@ CREATE TABLE `workerBosses` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `workerBusinessDated` +-- + +DROP TABLE IF EXISTS `workerBusinessDated`; +/*!50001 DROP VIEW IF EXISTS `workerBusinessDated`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `workerBusinessDated` ( + `dated` tinyint NOT NULL, + `business_id` tinyint NOT NULL, + `workerFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `workerCalendar` -- @@ -38547,6 +39247,23 @@ CREATE TABLE `workerDisableExcluded` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No se deshabilitan hasta la fecha especificada'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `workerDistributionCategory` +-- + +DROP TABLE IF EXISTS `workerDistributionCategory`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `workerDistributionCategory` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `workerFk` int(11) NOT NULL, + `category` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `workerDistributionCategory_workerFk_idx` (`workerFk`), + CONSTRAINT `workerDistributionCategory_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `workerDocument` -- @@ -38797,6 +39514,29 @@ CREATE TABLE `workerRelatives` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Modelo 145 IRPF apartado 2 y 3'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `workerShelving` +-- + +DROP TABLE IF EXISTS `workerShelving`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `workerShelving` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `workerFk` int(11) NOT NULL, + `shelvingFk` varchar(10) CHARACTER SET utf8 NOT NULL, + `collectionFk` int(11) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `workerShelving_shelving_fk` (`shelvingFk`), + KEY `workerShelving_FK` (`workerFk`), + KEY `workerShelving_FK_1` (`collectionFk`), + CONSTRAINT `workerShelving_collection_fk` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`), + CONSTRAINT `workerShelving_shelving_fk` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON UPDATE CASCADE, + CONSTRAINT `workerShelving_worker_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='utilizaremos el id para establecer la prioridad de los carros a asignar'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `workerSpeedExpedition` -- @@ -39672,14 +40412,14 @@ DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; /*!50003 SET @saved_cs_results = @@character_set_results */ ;; /*!50003 SET @saved_col_connection = @@collation_connection */ ;; -/*!50003 SET character_set_client = utf8 */ ;; -/*!50003 SET character_set_results = utf8 */ ;; -/*!50003 SET collation_connection = utf8_general_ci */ ;; +/*!50003 SET character_set_client = utf8mb4 */ ;; +/*!50003 SET character_set_results = utf8mb4 */ ;; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ;; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`z-sysadmin`@`%`*/ /*!50106 EVENT `printQueue_check` ON SCHEDULE EVERY 10 MINUTE STARTS '2019-11-08 00:00:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Notifica en caso de que el servidor de impresión este parado' DO BEGIN +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `printQueue_check` ON SCHEDULE EVERY 10 MINUTE STARTS '2019-11-08 01:00:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Notifica en caso de que el servidor de impresión este parado' DO BEGIN DECLARE vCurrentCount INT; DECLARE vCheckSum INT; @@ -39691,7 +40431,7 @@ DELIMITER ;; SELECT CONCAT(' ', IFNULL(pq.id, ''), ' ', IFNULL(p.path, ''),' - ', IFNULL(i.Informe, ''),' + ', IFNULL(ls.name, ''),' ', IFNULL(e.Estado, ''),' ', IFNULL(w.firstname, ''), " ", IFNULL(w.lastName, ''),' ', IFNULL(pq.`error`, ''),' @@ -39699,7 +40439,7 @@ DELIMITER ;; FROM vn.printingQueue pq LEFT JOIN vn.worker w ON w.id = pq.worker LEFT JOIN vn.printer p ON p.id = pq.printer - LEFT JOIN vn2008.Informes i ON i.Id_Informe = pq.report + LEFT JOIN vn.labelReport lr ON lr.id = pq.report JOIN vn2008.Estados e ON e.Id_Estado = pq.state LIMIT 30; @@ -39869,6 +40609,24 @@ END */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; +/*!50106 DROP EVENT IF EXISTS `zoneClosure_doRecalc` */;; +DELIMITER ;; +/*!50003 SET @saved_cs_client = @@character_set_client */ ;; +/*!50003 SET @saved_cs_results = @@character_set_results */ ;; +/*!50003 SET @saved_col_connection = @@collation_connection */ ;; +/*!50003 SET character_set_client = utf8 */ ;; +/*!50003 SET character_set_results = utf8 */ ;; +/*!50003 SET collation_connection = utf8_general_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`salix`@`10.0.%.%`*/ /*!50106 EVENT `zoneClosure_doRecalc` ON SCHEDULE AT '2021-05-25 10:32:44' ON COMPLETION NOT PRESERVE DISABLE DO CALL zoneClosure_recalc */ ;; +/*!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 `zoneGeo_doCalc` */;; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; @@ -40954,6 +41712,47 @@ DELIMITER ; /*!50003 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 `collectionExpeditionLacks` */; +/*!50003 SET @saved_cs_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 `collectionExpeditionLacks`(vCollectionFk INT) RETURNS varchar(100) CHARSET utf8 COLLATE utf8_unicode_ci + DETERMINISTIC +BEGIN + + DECLARE vExpeditionLacks BOOL; + DECLARE vAnswer VARCHAR(100) DEFAULT ''; + + SELECT (COUNT(*) > 0) INTO vExpeditionLacks + FROM vn.ticketCollection tc + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND ISNULL(e.id); + + IF vExpeditionLacks THEN + + SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer + FROM vn.ticketCollection tc + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND ISNULL(e.id); + + END IF; + + RETURN vAnswer; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 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 `currentRate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -42892,6 +43691,47 @@ DELIMITER ; /*!50003 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 `item_getPackage` */; +/*!50003 SET @saved_cs_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 `item_getPackage`(vItemFk INT) RETURNS varchar(50) CHARSET utf8 COLLATE utf8_unicode_ci + DETERMINISTIC +BEGIN + + DECLARE vDiameter INT; + DECLARE vPackageFk VARCHAR(50); + + SELECT MAX(LEFT(value,3)) INTO vDiameter + FROM vn.itemTag it + JOIN vn.tag t ON t.id = it.tagFk + WHERE it.itemFk = vItemFk + AND t.overwrite = 'diameter'; + + SELECT 8000 + (FLOOR(vc.ccLength / vDiameter) * FLOOR(vc.ccWidth / vDiameter)) + INTO vPackageFk + FROM vn.volumeConfig vc; + + INSERT IGNORE INTO vn.packaging(id, width, `depth`) + SELECT vPackageFk, + FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), + FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter)) + FROM vn.volumeConfig vc; + + RETURN vPackageFk; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `item_getVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -42924,6 +43764,7 @@ BEGIN WHERE p.id = vPackaging; RETURN vVolume; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43654,6 +44495,39 @@ BEGIN RETURN vWarehouseFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 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 `ticket_CC_volume` */; +/*!50003 SET @saved_cs_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 `ticket_CC_volume`(vTicketFk INT) RETURNS decimal(10,1) + READS SQL DATA +BEGIN + + DECLARE vCC DECIMAL(10,1); + + SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000) + INTO vCC + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.packaging p ON p.id = 'CC' + JOIN vn.volumeConfig vc + WHERE sv.ticketFk = vTicketFk; + + RETURN vCC; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43758,6 +44632,36 @@ DELIMITER ; /*!50003 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 `ticket_HasUbication` */; +/*!50003 SET @saved_cs_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 `ticket_HasUbication`(vTicketFk INT) RETURNS tinyint(1) + READS SQL DATA +BEGIN + + DECLARE hasUbication BOOL; + + SELECT COUNT(*) INTO hasUbication + FROM vn.ticket t + JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + WHERE rm.beachFk + AND t.id = vTicketFk; + + RETURN hasUbication; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 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 `till_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45005,9 +45909,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -45045,6 +45949,7 @@ BEGIN AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) AND b.price2 > 0 AND NOT b.isIgnored + AND b.quantity > 0 GROUP BY itemFk, warehouseInFk; END ;; DELIMITER ; @@ -45313,9 +46218,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -45329,7 +46234,10 @@ BEGIN */ DECLARE vLanded DATE; DECLARE vWarehouseFk INT; - + DECLARE vFallo BOOL; + DECLARE vBuyingValue DECIMAL(10,3); + DECLARE vPackageFk VARCHAR(10); + SELECT t.landed, t.warehouseInFk INTO vLanded, vWarehouseFk FROM tmp.buyRecalc br JOIN buy b ON b.id = br.id @@ -45341,13 +46249,13 @@ BEGIN -- quitado los cubos a floramondo revisar en buy_tarifas_entry UPDATE buy b - JOIN tmp.buyRecalc br ON br.id = b.id + JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id) LEFT JOIN packaging p ON p.id = b.packageFk JOIN item i ON i.id = b.itemFk JOIN entry e ON e.id = b.entryFk JOIN itemType it ON it.id = i.typeFk JOIN travel tr ON tr.id = e.travelFk - JOIN agencyMode am ON am.id = tr.agencyFk + JOIN agencyMode am ON am.id = tr.agencyFk JOIN tmp.rate r SET b.freightValue = @PF:= ROUND(IFNULL(((am.m3 * @cm3:= item_getVolume(b.itemFk, b.packageFk)) / 1000000) / b.packing,0),3), @@ -45356,7 +46264,29 @@ BEGIN b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2); - + + SELECT (b.buyingValue = b.price2), b.buyingValue , b.packageFk + INTO vFallo, vBuyingValue ,vPackageFk + FROM vn.buy b + WHERE b.id = @buyId; + + IF vFallo THEN + + CALL `vn`.`mail_insert`('cau@verdnatura.es', + NULL, + CONCAT('Fallo en buy_recalcPrices buy.id = ', @buyId), + CONCAT( ' @t3 = ', @t3, + ' @t2 = ', @t2, + ' @PF = ', @PF, + ' @EF = ', @EF, + ' @CF = ', @CF, + ' buyingValue = ', vBuyingValue, + ' packageFk = ', vPackageFk + ) + ); + + END IF; + DROP TEMPORARY TABLE tmp.rate; END ;; DELIMITER ; @@ -45742,9 +46672,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -45874,10 +46804,12 @@ proc: BEGIN LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible JOIN origin o ON o.id = i.originFk JOIN ( - SELECT MAX(price) price, itemFk, priceKg - FROM tmp.ticketComponentPrice - WHERE warehouseFk = vWarehouseFk - GROUP BY itemFk + SELECT * + FROM (SELECT price, itemFk, priceKg + FROM tmp.ticketComponentPrice + WHERE warehouseFk = vWarehouseFk + ORDER BY (rate = 2) DESC) sub + GROUP BY itemFk ) bl ON bl.itemFk = tl.itemFk WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk GROUP BY tl.itemFk @@ -46072,8 +47004,8 @@ proc: BEGIN * @param vShipped dia de salida del pedido * @param vWarehouseFk warehouse de salida del pedido * @param tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) - * - * @return tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + * @table tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + * * @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg) */ DECLARE vClientFk INT; @@ -46098,13 +47030,12 @@ proc: BEGIN DECLARE vVisibleCache INT; DECLARE vRappelComponent INT DEFAULT 44; - SELECT volume INTO vBoxVolume - FROM vn.packaging - WHERE id = '94'; + SELECT vc.standardFlowerBox * 1000 INTO vBoxVolume + FROM vn.volumeConfig vc; SELECT clientFk, isLogifloraAllowed INTO vClientFK, vIsLogifloraAllowed FROM address - WHERE id = vAddressFk; + WHERE id = vAddressFk; SELECT (c.country = 'FRANCIA' AND vWarehouseFk = vVNHWarehouseFk) INTO vIsFrenchVNHBuyer @@ -46117,14 +47048,19 @@ proc: BEGIN FROM edi.warehouseFloramondo WHERE warehouseFk = vWarehouseFk; - IF (NOT vIsLogifloraAllowed AND vVNHWarehouseFk != vWarehouseFk) + IF (NOT vIsLogifloraAllowed AND vVNHWarehouseFk != vWarehouseFk) OR (vn.isLogifloraDay(vShipped, vWarehouseFk) = FALSE) + OR (vIsFrenchVNHBuyer = FALSE AND NOW() BETWEEN '2021-05-21' AND '2021-05-25 12:00') -- Eliminar al pasar la fecha + THEN CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); DELETE tl FROM tmp.ticketLot tl JOIN item i ON i.id = tl.itemFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.entry e ON e.id = b.entryFk LEFT JOIN cache.visible v ON v.calc_id = vVisibleCache AND v.item_id = i.id LEFT JOIN (SELECT DISTINCT s.itemFk FROM vn.sale s @@ -46134,6 +47070,7 @@ proc: BEGIN AND t.shipped = vShipped AND t.zoneFk = vZoneFk) sub ON sub.itemFk = i.id WHERE (i.supplyResponseFk + AND IFNULL(e.isRaid,TRUE) AND ISNULL(sub.itemFk) AND IFNULL(v.visible,0) = 0 AND vWarehouseFk = tl.warehouseFk); @@ -46143,7 +47080,6 @@ proc: BEGIN -- Eliminem productes de la oferta que no deuen vore els francesos IF vIsFrenchVNHBuyer THEN - CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); DELETE tl FROM tmp.ticketLot tl @@ -46158,10 +47094,9 @@ proc: BEGIN AND t.addressFk = vAddressFk AND t.shipped = vShipped AND t.zoneFk = vZoneFk) sub ON sub.itemFk = i.id - WHERE mp.isEarlyBird = FALSE - AND IFNULL(sub.itemFk,0) = 0 - AND IFNULL(v.visible ,0) = 0 - ; + WHERE (mp.isEarlyBird = FALSE + AND IFNULL(sub.itemFk,0) = 0 + AND IFNULL(v.visible ,0) = 0); END IF; @@ -46175,7 +47110,9 @@ proc: BEGIN (PRIMARY KEY (itemFk, warehouseFk)) ENGINE = MEMORY SELECT - tl.itemFk, tl.warehouseFk, tl.available, + tl.itemFk, + tl.warehouseFk, + tl.available, IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) * 1.0 rate2, @minPrice := IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) * 1.0 rate3, IFNULL(@minPrice, 0) AS minPrice, @@ -46244,8 +47181,7 @@ proc: BEGIN GROUP BY tc.itemFk, warehouseFk; -- RECOBRO - - INSERT INTO tmp.ticketComponent + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(MAX(GREATEST(IFNULL(cr.priceIncreasing,0), IFNULL(cr1.priceIncreasing,0), IFNULL(cr2.priceIncreasing,0))), 0.25), 3) FROM tmp.ticketComponentBase tcb @@ -46258,7 +47194,7 @@ proc: BEGIN GROUP BY tcb.itemFk; -- Mana auto - INSERT INTO tmp.ticketComponent + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + wm.pricesModifierRate), 3) as manaAuto FROM tmp.ticketComponentBase tcb JOIN `client` c on c.id = vClientFk @@ -46266,6 +47202,8 @@ proc: BEGIN WHERE wm.isPricesModifierActivated HAVING manaAuto <> 0; + + -- Precios especiales INSERT INTO tmp.ticketComponent SELECT tcb.warehouseFk, @@ -46291,9 +47229,6 @@ proc: BEGIN LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk WHERE sp.value IS NULL; - - - DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE IF NOT EXISTS tmp.zone (INDEX (id)) ENGINE = MEMORY @@ -46341,21 +47276,23 @@ proc: BEGIN JOIN component c ON c.id = tcc.componentFk JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk WHERE c.classRate IS NULL + AND tcc.warehouseFk = vWarehouseFk GROUP BY tcc.itemFk, tcc.warehouseFk HAVING ABS(sumCost) > 0.001; - - -- Rappel cadena + + -- Rappel INSERT INTO tmp.ticketComponent SELECT tcc.warehouseFk, tcc.itemFk, vRappelComponent, SUM(tcc.cost) * ((1/(1-c.rappel/100)) -1) sumCost FROM tmp.ticketComponentCopy tcc - JOIN vn.clientChain cc ON cc.clientFk = vClientFK + JOIN vn.clientChain cc ON cc.clientFk = vClientFk JOIN vn.`chain` c ON c.id = cc.chainFk - GROUP BY tcc.itemFk, tcc.warehouseFk - HAVING ABS(sumCost) > 0.001; - + WHERE tcc.warehouseFk = vWarehouseFk + GROUP BY tcc.itemFk, tcc.warehouseFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentSum; CREATE TEMPORARY TABLE tmp.ticketComponentSum (INDEX (itemFk, warehouseFk)) @@ -46925,26 +47862,25 @@ CREATE DEFINER=`root`@`%` PROCEDURE `clientFreeze`() BEGIN /** * Congela diariamente aquellos clientes que son morosos sin recobro, - * pero que no sean trabajadores + * pero que no sean trabajadores, + * hasta que no se gire la remesa no se congelan a los clientes de giro */ - - /* - UPDATE bi.defaulters d - JOIN vn.client c ON c.id = d.client - JOIN vn.config ON TRUE - SET c.isFreezed = TRUE, frozened = CURDATE() - WHERE d.amount > config.defaultersMaxAmount - AND d.`date` = CURDATE() - AND d.frozened IS NULL; - - IF day(CURDATE()) IN (5,15,25) THEN - */ + + DECLARE vIsRemittanced BOOLEAN; + + SELECT COUNT(*) into vIsRemittanced + FROM receipt + WHERE invoiceFk LIKE 'REMESA%' + AND payed > util.firstDayOfMonth(CURDATE()) + limit 1; + UPDATE client c JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE() JOIN config ON TRUE LEFT JOIN account.`user` u ON u.id = c.id AND u.active LEFT JOIN worker w ON w.id = u.id LEFT JOIN recovery r ON r.clientFk = c.id AND r.finished IS NULL + LEFT JOIN payMethod pm ON pm.id = c.payMethodFk SET c.isFreezed = TRUE, d.frozened = CURDATE(), u.active = FALSE @@ -46952,8 +47888,7 @@ BEGIN AND c.typeFk = 'normal' AND r.id IS NULL AND w.id IS NULL - ; - -- END IF; + AND (vIsRemittanced OR pm.code <> 'bankDraft'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47538,15 +48473,19 @@ CREATE DEFINER=`root`@`%` PROCEDURE `clientPackagingOverstockReturn`(vClientFk I BEGIN DECLARE vNewTicket INT DEFAULT 0; - + DECLARE vWarehouseFk INT; -- SET vGraceDays = GREATEST(vGraceDays, 90); CALL vn.clientPackagingOverstock(vClientFk,vGraceDays); + SELECT id INTO vWarehouseFk + FROM vn.warehouse + WHERE hasConfectionTeam; + CALL vn.ticketCreateWithUser( vClientFk ,CURDATE() - ,1 -- Silla FV + ,vWarehouseFk -- Algemesi ,442 -- Verdnatura ,NULL -- address ,NULL -- agencia @@ -47777,6 +48716,56 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `client_checkBalance` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `client_checkBalance`(IN vDateTo DATETIME, IN vIsConciliated BOOL) +BEGIN + + DECLARE vDateFrom DATE; + SET vDateTo = TIMESTAMP(vDateTo,'23:59:59'); + SELECT util.firstDayOfYear(vDateTo) INTO vDateFrom; + + SELECT s.nickname, c.id , c.accountingAccount , sub1.mysql , sub1.sage, sub1.mysql - sub1.sage diference, sub1.companyFk , c.name + FROM client c + JOIN payMethod pm ON pm.id = c.payMethodFk + JOIN( SELECT sub.companyFk, sub.clientFk, ROUND(SUM(sub.mysql),2) mysql, ROUND(SUM(sub.sage),2) sage + FROM( SELECT io.companyFk, io.clientFk, -io.amount mysql, 0 sage + FROM invoiceOut io + WHERE issued BETWEEN vDateFrom AND vDateTo + UNION ALL + SELECT r.companyFk, r.clientFk, r.amountPaid, 0 sage + FROM receipt r + WHERE payed BETWEEN vDateFrom AND vDateTo + AND IF(vIsConciliated,r.isConciliate, TRUE) = TRUE + UNION ALL + SELECT empresa_id, c.id, 0, ROUND(NZ(Eurohaber) - NZ(Eurodebe),2) sage + FROM bi.XDiario_ALL xd + JOIN client c ON c.accountingAccount = xd.SUBCTA + WHERE xd.Fecha BETWEEN vDateFrom AND vDateTo + )sub + GROUP BY companyFk, clientFk + ) sub1 ON sub1.clientFk = c.id + JOIN supplier s ON s.id = sub1.companyFk + JOIN company co ON co.id = sub1.companyFk + WHERE pm.outstandingDebt + AND co.code <> 'BLK' + HAVING ABS(diference) > 0.05 + ORDER BY c.name; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `client_RandomList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47998,32 +48987,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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cmr_getByTicket`(vTicketFk INT) BEGIN + IF vTicketFk THEN + IF (SELECT count(ticketFk) FROM vn.cmr WHERE ticketFk = vTicketFk) THEN + SELECT id FROM vn.cmr WHERE ticketFk = vTicketFk; + ELSE + INSERT INTO vn.cmr(ticketFk, companyFk, addressFromFk, addressToFk, supplierFk) SELECT vTicketFk, t.companyFk, a.id, t.addressFk, ag.supplierFk FROM vn.ticket t JOIN vn.agencyMode am ON am.id = t.agencyModeFk JOIN vn.agency ag ON ag.id = am.agencyFk - JOIN vn.company cm ON cm.id = t.companyFk - JOIN vn.client c ON c.id = cm.clientFk - JOIN vn.address a ON a.clientFk = c.id AND a.isDefaultAddress + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.address a ON a.id = w.addressFk WHERE t.id = vTicketFk; + SELECT LAST_INSERT_ID(); + END IF; + ELSE + INSERT INTO vn.cmr(created) VALUES(NOW()); + SELECT LAST_INSERT_ID(); + END IF; END ;; DELIMITER ; @@ -48402,23 +49401,16 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `collectionSticker_print`(vCollectionFk INT, vSectorFk INT) BEGIN - - DECLARE vLabelReport INT; - /* - UPDATE vn.ticket t - JOIN vn.ticketCollection tc ON tc.ticketFk = t.id - SET t.notes = CONCAT('COL ',vCollectionFk,'-',tc.`level`) - WHERE tc.collectionFk = vCollectionFk; - */ + SELECT labelReport INTO vLabelReport FROM vn.sector WHERE id = vSectorFk; @@ -48841,6 +49833,8 @@ proc:BEGIN DECLARE vMaxTickets INT; DECLARE vStateFk INT; DECLARE vFirstTicketFk INT; + DECLARE vHour INT; + DECLARE vMinute INT; DECLARE vWorkerCode VARCHAR(3); DECLARE vWagon INT; DECLARE vWagonCounter INT; @@ -48857,12 +49851,15 @@ proc:BEGIN DECLARE vNotReadyCollections INT; DECLARE vSectorCode VARCHAR(20); + SELECT w.code INTO vWorkerCode + FROM vn.worker w + WHERE w.id = vn.getUser(); + -- Si hay colecciones sin terminar, sale del proceso SELECT count(*) INTO vNotReadyCollections - FROM vn.collection c - JOIN vn.state s ON s.id = c.stateFk + FROM vn.collection c WHERE c.workerFk = vn.getUser() - AND s.code = 'ON_PREPARATION' + AND c.saleTotalCount > c.salePickedCount + 1 AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); IF vMaxNotReadyCollections < vNotReadyCollections THEN @@ -48876,15 +49873,7 @@ proc:BEGIN INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk, vSectorCode FROM vn.sector WHERE id = vSectorFk; - - IF vSectorCode != 'V' THEN -- beta - - CALL vn.collection_new_beta(vSectorFk); - - LEAVE proc; - - END IF; - + IF LENGTH(vSectorCode) = 2 THEN SELECT CAST(SUBSTRING(vSectorCode,2,1) AS UNSIGNED) INTO vWagons; @@ -48897,6 +49886,8 @@ proc:BEGIN IF vIsPreviousPrepared THEN + LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion + SELECT id INTO vStateFk FROM vn.state WHERE `code` = 'PREVIOUS_PREPARATION'; @@ -48930,8 +49921,9 @@ proc:BEGIN FROM tmp.productionBuffer pb JOIN vn.state s ON s.id = pb.state WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode; - + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0; + IF hasAssignedTickets THEN UPDATE vn.collection @@ -48945,6 +49937,7 @@ proc:BEGIN JOIN vn.state s ON s.id = pb.state WHERE s.code = 'PICKER_DESIGNED' AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0 ORDER BY HH, mm, s.`order` DESC, @@ -48966,7 +49959,8 @@ proc:BEGIN END WHILE; - + CALL vn.productionControl(vWarehouseFk, 0); + ELSE SELECT COUNT(*) INTO vPrintedTickets @@ -48994,6 +49988,7 @@ proc:BEGIN JOIN vn.agency a ON a.id = am.agencyFk JOIN vn.state s ON s.id = pb.state JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' + JOIN vn.ticket t ON t.id = pb.ticketFk WHERE pb.shipped = CURDATE() AND LENGTH(pb.problem) = 0 AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) @@ -49002,7 +49997,8 @@ proc:BEGIN AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND t.created < TIMESTAMPADD(MINUTE, -10, NOW()) ORDER BY HH, mm, s.`order` DESC, @@ -49032,7 +50028,7 @@ proc:BEGIN AND NOT myUserIsSalesPersonRole ORDER BY pb.HH, pb.mm, s.`order` DESC LIMIT vMaxTickets; - + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO SELECT MIN(ticketFk) INTO vTicketToSplit @@ -49051,7 +50047,7 @@ proc:BEGIN END WHILE; END IF; - + -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección DROP TEMPORARY TABLE IF EXISTS tmp.ticket; CREATE TEMPORARY TABLE tmp.ticket @@ -49061,27 +50057,62 @@ proc:BEGIN 0 as height, 0 as shelve, 0 as wagon, - pb.productionOrder + pb.productionOrder, + pb.HH, + pb.mm FROM tmp.productionBuffer pb JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk WHERE tc.collectionFk = vCollectionFk - ORDER BY pb.productionOrder DESC, HH, mm - LIMIT vMaxTickets; + LIMIT vMaxTickets; + + -- Es importante que el primer ticket se coja en todos los casos + SET vFirstTicketFk = 0; + + SELECT ticketFk, HH, mm + INTO vFirstTicketFk, vHour, vMinute + FROM tmp.ticket + ORDER BY productionOrder DESC, HH, mm + LIMIT 1; + + -- Hay que excluir aquellos que no tengan la misma hora de preparación + DELETE + FROM tmp.ticket + WHERE HH != vHour + OR mm != vMinute; + + -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido + -- no es monoticket, excluimos a los de más de un carro + IF (SELECT (t.liters > vc.carro * 1000) + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.ticketFk = vFirstTicketFk) THEN + + DELETE + FROM tmp.ticket + WHERE ticketFk != vFirstTicketFk; + + ELSE + + DELETE t.* + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.liters > vc.carro * 1000; + + END IF; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; /* * * Construccion del tren * */ - - SELECT ticketFk - INTO vFirstTicketFk - FROM tmp.ticket - ORDER BY productionOrder DESC - LIMIT 1; - - INSERT INTO tmp.log(ticketFk) VALUES(vFirstTicketFk); - + -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. UPDATE tmp.ticket t JOIN @@ -49117,7 +50148,8 @@ proc:BEGIN cv.`lines`, cv.liters, cv.height - FROM vn.collectionVolumetry cv; + FROM vn.collectionVolumetry cv + WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H'); END WHILE; @@ -49227,6 +50259,12 @@ proc:BEGIN WHERE tc.collectionFk = vCollectionFk AND t.ticketFk IS NULL; + -- Elimina los tickets que ya estan en otra coleccion + DELETE tc.* + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND tc2.collectionFk != vCollectionFk; -- Actualiza el estado de la colección UPDATE vn.collection c @@ -49285,7 +50323,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 `collection_new_beta` */; +/*!50003 DROP PROCEDURE IF EXISTS `collection_newWithWagon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -49295,7 +50333,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `collection_new_beta`(vSectorFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `collection_newWithWagon`(vSectorFk INT, vWagons INT) proc:BEGIN DECLARE vIsPreviousPrepared BOOLEAN; @@ -49304,6 +50342,8 @@ proc:BEGIN DECLARE vMaxTickets INT; DECLARE vStateFk INT; DECLARE vFirstTicketFk INT; + DECLARE vHour INT; + DECLARE vMinute INT; DECLARE vWorkerCode VARCHAR(3); DECLARE vWagon INT; DECLARE vWagonCounter INT; @@ -49314,18 +50354,20 @@ proc:BEGIN DECLARE vPrintedTickets INT; DECLARE vMaxTicketPrinted INT; DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE vWagons INT DEFAULT 2; DECLARE hasAssignedTickets BOOLEAN; DECLARE vMaxNotReadyCollections INT DEFAULT 0; DECLARE vNotReadyCollections INT; DECLARE vSectorCode VARCHAR(20); + SELECT w.code INTO vWorkerCode + FROM vn.worker w + WHERE w.id = vn.getUser(); + -- Si hay colecciones sin terminar, sale del proceso SELECT count(*) INTO vNotReadyCollections - FROM vn.collection c - JOIN vn.state s ON s.id = c.stateFk + FROM vn.collection c WHERE c.workerFk = vn.getUser() - AND s.code = 'ON_PREPARATION' + AND c.saleTotalCount > c.salePickedCount + 1 AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); IF vMaxNotReadyCollections < vNotReadyCollections THEN @@ -49339,7 +50381,7 @@ proc:BEGIN INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk, vSectorCode FROM vn.sector WHERE id = vSectorFk; - + IF LENGTH(vSectorCode) = 2 THEN SELECT CAST(SUBSTRING(vSectorCode,2,1) AS UNSIGNED) INTO vWagons; @@ -49352,6 +50394,8 @@ proc:BEGIN IF vIsPreviousPrepared THEN + LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion + SELECT id INTO vStateFk FROM vn.state WHERE `code` = 'PREVIOUS_PREPARATION'; @@ -49369,12 +50413,6 @@ proc:BEGIN FROM account.user u JOIN account.role r ON r.id = u.role WHERE u.id = vn.getUser(); - - -- Obtenemos el código del usuario - SELECT w.code - INTO vWorkerCode - FROM vn.worker w - WHERE w.id = account.myUser_getId(); -- Se obtiene nº de colección y el buffer con los pedidos preparables INSERT INTO vn.collection @@ -49391,8 +50429,9 @@ proc:BEGIN FROM tmp.productionBuffer pb JOIN vn.state s ON s.id = pb.state WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode; - + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0; + IF hasAssignedTickets THEN UPDATE vn.collection @@ -49406,11 +50445,12 @@ proc:BEGIN JOIN vn.state s ON s.id = pb.state WHERE s.code = 'PICKER_DESIGNED' AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0 ORDER BY HH, mm, s.`order` DESC, pb.m3 DESC; - + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO SELECT MIN(ticketFk) INTO vTicketToSplit @@ -49425,9 +50465,12 @@ proc:BEGIN DELETE FROM tmp.ticketToSplit WHERE ticketFk = vTicketToSplit; + DROP TEMPORARY TABLE tmp.ticketIPT; + END WHILE; - + CALL vn.productionControl(vWarehouseFk, 0); + ELSE SELECT COUNT(*) INTO vPrintedTickets @@ -49455,6 +50498,7 @@ proc:BEGIN JOIN vn.agency a ON a.id = am.agencyFk JOIN vn.state s ON s.id = pb.state JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' + JOIN vn.ticket t ON t.id = pb.ticketFk WHERE pb.shipped = CURDATE() AND LENGTH(pb.problem) = 0 AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) @@ -49463,7 +50507,8 @@ proc:BEGIN AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND t.created < TIMESTAMPADD(MINUTE, -10, NOW()) ORDER BY HH, mm, s.`order` DESC, @@ -49509,10 +50554,12 @@ proc:BEGIN DELETE FROM tmp.ticketToSplit WHERE ticketFk = vTicketToSplit; + DROP TEMPORARY TABLE tmp.ticketIPT; + END WHILE; END IF; - + -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección DROP TEMPORARY TABLE IF EXISTS tmp.ticket; CREATE TEMPORARY TABLE tmp.ticket @@ -49522,27 +50569,62 @@ proc:BEGIN 0 as height, 0 as shelve, 0 as wagon, - pb.productionOrder + pb.productionOrder, + pb.HH, + pb.mm FROM tmp.productionBuffer pb JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk WHERE tc.collectionFk = vCollectionFk - ORDER BY pb.productionOrder DESC, HH, mm - LIMIT vMaxTickets; + LIMIT vMaxTickets; + + -- Es importante que el primer ticket se coja en todos los casos + SET vFirstTicketFk = 0; + + SELECT ticketFk, HH, mm + INTO vFirstTicketFk, vHour, vMinute + FROM tmp.ticket + ORDER BY productionOrder DESC, HH, mm + LIMIT 1; + + -- Hay que excluir aquellos que no tengan la misma hora de preparación + DELETE + FROM tmp.ticket + WHERE HH != vHour + OR mm != vMinute; + + -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido + -- no es monoticket, excluimos a los de más de un carro + IF (SELECT (t.liters > vc.carro * 1000) + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.ticketFk = vFirstTicketFk) THEN + + DELETE + FROM tmp.ticket + WHERE ticketFk != vFirstTicketFk; + + ELSE + + DELETE t.* + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.liters > vc.carro * 1000; + + END IF; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; /* * * Construccion del tren * */ - - SELECT ticketFk - INTO vFirstTicketFk - FROM tmp.ticket - ORDER BY productionOrder DESC - LIMIT 1; - - INSERT INTO tmp.log(ticketFk) VALUES(vFirstTicketFk); - + -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. UPDATE tmp.ticket t JOIN @@ -49564,7 +50646,7 @@ proc:BEGIN cv.`lines`, cv.liters, cv.height - FROM vn.collectionVolumetry_Paloma cv; -- beta + FROM vn.collectionVolumetry cv; SET vWagonCounter = 1; @@ -49578,7 +50660,8 @@ proc:BEGIN cv.`lines`, cv.liters, cv.height - FROM vn.collectionVolumetry_Paloma cv; -- beta + FROM vn.collectionVolumetry cv + WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H'); END WHILE; @@ -49688,6 +50771,12 @@ proc:BEGIN WHERE tc.collectionFk = vCollectionFk AND t.ticketFk IS NULL; + -- Elimina los tickets que ya estan en otra coleccion + DELETE tc.* + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND tc2.collectionFk != vCollectionFk; -- Actualiza el estado de la colección UPDATE vn.collection c @@ -49737,432 +50826,7 @@ proc:BEGIN END IF; - DROP TEMPORARY TABLE tmp.ticketIPT; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `collection_new__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `collection_new__`(vSectorFk INT) -proc:BEGIN - - DECLARE vIsPreviousPrepared BOOLEAN; - DECLARE vCollectionFk INT; - DECLARE vWarehouseFk INT; - DECLARE vMaxTickets INT; - DECLARE vStateFk INT; - DECLARE vFirstTicketFk INT; - DECLARE vWorkerCode VARCHAR(3); - DECLARE vWagon INT; - DECLARE vWagonCounter INT; - DECLARE vShelve INT; - DECLARE vTicket INT; - DECLARE myUserIsSalesPersonRole BOOLEAN; - DECLARE vPrintedTickets INT; - DECLARE vMaxTicketPrinted INT; - DECLARE vSectorCode VARCHAR(1); - DECLARE vWagons INT DEFAULT 2; - DECLARE hasAssignedTickets BOOLEAN; - - - -- Si existe una coleccion sin finalizar, la devuelve - /* - SELECT MAX(c.id) INTO vCollectionFk - FROM vn.collection c - JOIN vn.state s ON s.id = c.stateFk - WHERE c.workerFk = vn.getUser() - AND s.code = 'ON_PREPARATION' - AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); - - IF vCollectionFk THEN - - SELECT vCollectionFk; - - LEAVE proc; - - END IF; - */ - SET vMaxTicketPrinted = 15 * vWagons; - SET vMaxTickets = 5 * vWagons; - - -- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando - SELECT isPreviousPrepared, warehouseFk, code - INTO vIsPreviousPrepared, vWarehouseFk, vSectorCode - FROM vn.sector - WHERE id = vSectorFk; - - IF vIsPreviousPrepared THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE `code` = 'PREVIOUS_PREPARATION'; - ELSE - - SELECT id INTO vStateFk - FROM vn.state - WHERE `code` = 'ON_PREPARATION'; - - END IF; - - -- Averiguamos si es comercial el usuario - SELECT (r.name = 'salesPerson') - INTO myUserIsSalesPersonRole - FROM account.user u - JOIN account.role r ON r.id = u.role - WHERE u.id = vn.getUser(); - - -- Obtenemos el código del usuario - SELECT w.code - INTO vWorkerCode - FROM vn.worker w - WHERE w.id = account.myUser_getId(); - - -- Se obtiene nº de colección y el buffer con los pedidos preparables - INSERT INTO vn.collection - SET workerFk = account.myUser_getId(), - itemPackingTypeFk = vSectorCode; - - SELECT LAST_INSERT_ID() INTO vCollectionFk; - - CALL vn.productionControl(vWarehouseFk, 0); - - -- Comprobamos si hay tickets asignados. En ese caso, nos centramos exclusivamente en esos tickets - -- y los sacamos independientemente de problemas o tamaños - SELECT COUNT(*) INTO hasAssignedTickets - FROM tmp.productionBuffer pb - JOIN vn.state s ON s.id = pb.state - WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode - AND (pb.H > 0 AND ISNULL(pb.collectionH) - OR pb.V > 0 AND ISNULL(pb.collectionV) - OR pb.F > 0 AND ISNULL(pb.collectionF) - OR pb.P > 0 AND ISNULL(pb.collectionP)); - - IF hasAssignedTickets THEN - - UPDATE vn.collection - SET itemPackingTypeFk = NULL - WHERE id = vCollectionFk; - - INSERT INTO vn.ticketCollection(ticketFk, collectionFk) - SELECT pb.ticketFk, - vCollectionFk - FROM tmp.productionBuffer pb - JOIN vn.state s ON s.id = pb.state - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode - AND (pb.H > 0 AND ISNULL(pb.collectionH) - OR pb.V > 0 AND ISNULL(pb.collectionV) - OR pb.F > 0 AND ISNULL(pb.collectionF) - OR pb.P > 0 AND ISNULL(pb.collectionP)) - ORDER BY HH, - mm, - s.`order` DESC, - pb.m3 DESC; - - ELSE - - SELECT COUNT(*) INTO vPrintedTickets - FROM tmp.productionBuffer pb - JOIN vn.state s ON s.id = pb.state - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - WHERE pb.shipped = CURDATE() - AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) - AND s.isPreparable - AND (pb.H > 0 AND vSectorCode = 'H' AND ISNULL(pb.collectionH) - OR pb.V > 0 AND vSectorCode = 'V' AND ISNULL(pb.collectionV) - OR pb.F > 0 AND vSectorCode = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vSectorCode = 'P' AND ISNULL(pb.collectionP)); - - SET vMaxTicketPrinted = vMaxTicketPrinted - vPrintedTickets; - - -- AutoPRINT - - IF vMaxTicketPrinted > vMaxTickets THEN - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT s2.id, pb.ticketFk, vn.getUser() - FROM tmp.productionBuffer pb - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - JOIN vn.state s ON s.id = pb.state - JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' - WHERE pb.shipped = CURDATE() - AND LENGTH(pb.problem) = 0 - AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) - AND (s.isPrintable OR s.isPreparable ) - AND (pb.m3 > 0.05 OR s.isOK) - AND (pb.H > 0 AND vSectorCode = 'H' AND ISNULL(pb.collectionH) - OR pb.V > 0 AND vSectorCode = 'V' AND ISNULL(pb.collectionV) - OR pb.F > 0 AND vSectorCode = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vSectorCode = 'P' AND ISNULL(pb.collectionP)) - ORDER BY HH, - mm, - s.`order` DESC, - pb.m3 DESC - LIMIT vMaxTicketPrinted; - - END IF; - - -- Se seleccionan los primeros tickets, asignando colección para dejarlos bloqueados a otros sacadores. - - INSERT INTO vn.ticketCollection(ticketFk, collectionFk) - SELECT pb.ticketFk, - vCollectionFk - FROM tmp.productionBuffer pb - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - JOIN vn.ticketStateToday tst ON tst.ticket = pb.ticketFk - JOIN vn.state s ON s.id = tst.state - WHERE ( pb.H > 0 AND vSectorCode = 'H' AND ISNULL(pb.collectionH) - OR pb.V > 0 AND vSectorCode = 'V' AND ISNULL(pb.collectionV) - OR pb.F > 0 AND vSectorCode = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vSectorCode = 'P' AND ISNULL(pb.collectionP)) - AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) - AND LENGTH(pb.problem) = 0 - AND s.isPreparable - AND NOT myUserIsSalesPersonRole - ORDER BY pb.HH, pb.mm - LIMIT vMaxTickets; - - END IF; - --- SELECT vMaxTicketPrinted , vMaxTickets, vPrintedTickets, myUserIsSalesPersonRole, vCollectionFk, vSectorCode; - --- SELECT ticketFk, collectionFk FROM vn.ticketCollection tc WHERE tc.collectionFk = vCollectionFk; - - -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - SELECT pb.ticketFk, - pb.`lines`, - pb.m3 * 1000 liters, - 0 as height, - 0 as shelve, - 0 as wagon - FROM tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk - WHERE tc.collectionFk = vCollectionFk; - - /* - * - * Construccion del tren - * - */ - - SELECT ticketFk - INTO vFirstTicketFk - FROM tmp.ticket - LIMIT 1; - - -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. - UPDATE tmp.ticket t - JOIN - ( SELECT MAX(i.size) maxHeigth, - tc.ticketFk - FROM vn.ticketCollection tc - JOIN vn.sale s ON s.ticketFk = tc.ticketFk - JOIN vn.item i ON i.id = s.itemFk - WHERE i.itemPackingTypeFk = 'V' - AND tc.collectionFk = vCollectionFk - GROUP BY tc.ticketFk) sub ON sub.ticketFk = t.ticketFk - SET t.height = IFNULL(sub.maxHeigth,0); - - -- Vamos a generar una tabla con todas las posibilidades de asignacion de pedido - DROP TEMPORARY TABLE IF EXISTS tmp.wagonsVolumetry; - CREATE TEMPORARY TABLE tmp.wagonsVolumetry - SELECT cv.`level` as shelve, - 1 as wagon, - cv.`lines`, - cv.liters, - cv.height - FROM vn.collectionVolumetry cv; - - SET vWagonCounter = 1; - - WHILE vWagonCounter < vWagons DO - - SET vWagonCounter = vWagonCounter + 1; - - INSERT INTO tmp.wagonsVolumetry(shelve, wagon, `lines`, liters, height) - SELECT cv.`level` as shelve, - vWagonCounter as wagon, - cv.`lines`, - cv.liters, - cv.height - FROM vn.collectionVolumetry cv; - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelve; - CREATE TEMPORARY TABLE tmp.ticketShelve - SELECT ticketFk, shelve, wagon, linesDif, LitersDif, heightDif - FROM ( - SELECT t.ticketFk, - wv.shelve, - wv.wagon, - CAST(wv.`lines` AS SIGNED) - t.`lines` as linesDif, - CAST(wv.liters AS SIGNED) - t.liters as litersDif, - CAST(wv.height AS SIGNED) - t.height as heightDif - FROM tmp.wagonsVolumetry wv - JOIN tmp.ticket t - ORDER BY (t.ticketFk = vFirstTicketFk) DESC, linesDif - ) sub - WHERE linesDif >= 0 - AND litersDif >= 0 - AND heightDif >= 0 - ORDER BY linesDif; - - -- Insertamos una opcion virtual para carro completo. Todo ticket tiene que poder entrar en un carro completo.... - INSERT INTO tmp.ticketShelve(ticketFk, shelve, wagon, linesDif, LitersDif, heightDif) - SELECT t.ticketFk, 0, wv.wagon, 999, 999,999 - FROM tmp.ticket t - JOIN tmp.wagonsVolumetry wv - GROUP BY t.ticketFk, wv.wagon; - - SET vWagonCounter = 0; - - WHILE vWagonCounter < vWagons DO - - SET vWagonCounter = vWagonCounter + 1; - - -- Asignamos la primera balda util al primer pedido - IF vWagonCounter = 1 THEN - - SELECT shelve INTO vShelve - FROM tmp.ticketShelve - WHERE ticketFk = vFirstTicketFk - AND wagon = vWagonCounter - ORDER BY heightDif, litersDif, linesDif - LIMIT 1; - - ELSE - - SELECT shelve, ticketFk INTO vShelve, vFirstTicketFk - FROM tmp.ticketShelve - WHERE wagon = vWagonCounter - ORDER BY heightDif, litersDif, linesDif - LIMIT 1; - - END IF; - - IF vShelve > 0 THEN - - UPDATE tmp.ticket - SET shelve = vShelve, - wagon = vWagonCounter - WHERE ticketFk = vFirstTicketFk; - - DELETE FROM tmp.ticketShelve - WHERE ticketFk = vFirstTicketFk - OR (shelve = vShelve AND wagon = vWagonCounter); - - WHILE (SELECT COUNT(*) FROM tmp.ticketShelve WHERE wagon = vWagonCounter) DO - - SELECT ticketFk, shelve - INTO vTicket, vShelve - FROM tmp.ticketShelve - WHERE wagon = vWagonCounter - LIMIT 1; - - UPDATE tmp.ticket - SET shelve = vShelve, - wagon = vWagonCounter - WHERE ticketFk = vTicket; - - DELETE FROM tmp.ticketShelve - WHERE ticketFk = vTicket - OR (shelve = vShelve AND wagon = vWagonCounter); - - END WHILE; - - ELSE - - UPDATE tmp.ticket - SET shelve = 1, wagon = vWagonCounter - WHERE ticketFk = vFirstTicketFk; - - DELETE FROM tmp.ticketShelve - WHERE ticketFk = vFirstTicketFk - AND wagon != vWagonCounter; - - END IF; - - END WHILE; - - -- Eliminamos los que se han quedado sin balda - DELETE FROM tmp.ticket WHERE shelve = 0; - - -- Elimina los tickets bloqueados que no se van a preparar - DELETE tc.* - FROM vn.ticketCollection tc - LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND t.ticketFk IS NULL; - - -- Actualiza el estado de la colección - UPDATE vn.collection c - JOIN vn.state st ON st.code = 'ON_PREPARATION' - SET c.stateFk = st.id - WHERE c.id = vCollectionFk; - - -- Asigna las bandejas - UPDATE vn.ticketCollection tc - JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk - SET tc.level = t.shelve, tc.wagon = t.wagon; - - -- Actualiza el estado de los tickets - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT vStateFk, ticketFk, account.myUser_getId() - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vCollectionFk; - - -- Aviso para la preparacion previa - INSERT INTO vn.ticketDown(ticketFk, collectionFk) - SELECT tc.ticketFk, tc.collectionFk - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vCollectionFk; - - IF (SELECT count(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk) THEN - - CALL vn.salesMerge_byCollection(vCollectionFk); - - UPDATE vn.collection c - JOIN (SELECT count(*) saleTotalCount - FROM vn.ticketCollection tc - JOIN vn.sale s ON s.ticketFk = tc.ticketFk - JOIN vn.item i ON i.id = s.itemFk - WHERE tc.collectionFk = vCollectionFk - AND s.quantity > 0 - AND (i.itemPackingTypeFk = vSectorCode OR ISNULL(vSectorCode)) - ) sub - SET c.saleTotalCount = sub.saleTotalCount - WHERE c.id = vCollectionFk; - - SELECT vCollectionFk; - - ELSE - - DELETE FROM vn.collection WHERE id = vCollectionFk; - SELECT NULL; - - END IF; + DROP TEMPORARY TABLE tmp.ticketToSplit; END ;; DELIMITER ; @@ -53093,6 +53757,147 @@ BEGIN AND t.warehouseFk = vWarehouseFk AND s.itemFk = vItemFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `fustControl` */; +/*!50003 SET @saved_cs_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 `fustControl`(vFromDated DATE, vToDated DATE) +BEGIN + + DECLARE vSijsnerClientFk INT DEFAULT 19752; + + DECLARE vDateStart DATETIME; + DECLARE vDateEnd DATETIME; + + SET vDateStart = vFromDated; + SET vDateEnd = util.Dayend(vToDated); + + SELECT p.id FustCode, + CAST(sent.stucks AS DECIMAL(10,0)) FH, + CAST(tp.stucks AS DECIMAL(10,0)) Tickets, + CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, + CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo + FROM vn.packaging p + LEFT JOIN ( + SELECT FustCode, sum(fustQuantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,b.packageFk) FustCode, s.quantity / b.packing AS fustQuantity + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk + JOIN vn.buy b ON b.id = lb.buy_id + JOIN vn.packaging p ON p.id = b.packageFk + LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA') sub + GROUP BY FustCode) sent ON sent.FustCode = p.id + LEFT JOIN ( + SELECT FustCode, sum(quantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA' + AND t.clientFk != vSijsnerClientFk + AND tp.quantity > 0) sub + GROUP BY FustCode) tp ON tp.FustCode = p.id + LEFT JOIN ( + SELECT FustCode, sum(quantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND t.clientFk = vSijsnerClientFk) sub + GROUP BY FustCode) sj ON sj.FustCode = p.id + WHERE sent.stucks + OR tp.stucks + OR sj.stucks; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `fustControlDetail` */; +/*!50003 SET @saved_cs_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 `fustControlDetail`(vFromDated DATE, vToDated DATE) +BEGIN + + DECLARE vSijsnerClientFk INT DEFAULT 19752; + + DECLARE vDateStart DATETIME; + DECLARE vDateEnd DATETIME; + + SET vDateStart = vFromDated; + SET vDateEnd = util.Dayend(vToDated); + + SELECT a.nickname shopName, + a.city , + IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, + tp.quantity, + tp.ticketFk, + CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk + WHERE t.shipped BETWEEN '2021-05-04' AND '2021-05-06' + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA' + AND t.clientFk != vSijsnerClientFk + AND tp.quantity > 0; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53245,9 +54050,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -53264,7 +54069,7 @@ SELECT w.id, LEFT JOIN vn2008.profile_labour_payroll AS plp ON pp.pid=plp.profile_id LEFT JOIN (SELECT MAX(business_id) AS bimax, client_id FROM postgresql.business GROUP BY client_id) AS pbv ON pbv.client_id = plp.profile_id LEFT JOIN postgresql.business_labour AS pbl ON pbl.business_id = pbv.bimax - LEFT JOIN vn2008.department AS pd ON pd.department_id = pbl.department_id + LEFT JOIN vn.department AS pd ON pd.id = pbl.department_id LEFT JOIN postgresql.workcenter AS pwc ON pwc.workcenter_id=pbl.workcenter_id LEFT JOIN vn.user u ON u.id=w.userFK LEFT JOIN vn.routeLoadWorker rl ON rl.workerFk = w.id @@ -54268,6 +55073,261 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInBookingMain`(vInvoiceInId INT) +BEGIN + DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2); + DECLARE vBookNumber,vSerialNumber INT; + DECLARE vRate DECIMAL(10,4); + + CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber); + + SELECT SUM(iit.taxableBase * IF( i.serial= 'R' AND ti.Iva <> 'HP DEVENGADO 21 ISP', 1 +(ti.PorcentajeIva/100),1)), + SUM(iit.foreignValue * IF( i.serial= 'R', 1 + (ti.PorcentajeIva/100),1)), + iit.taxableBase/iit.foreignValue + INTO vTotalAmount, vTotalAmountDivisa, vRate + FROM newInvoiceIn i + JOIN invoiceInTax iit ON iit.invoiceInFk = i.id + LEFT JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk; + + CALL vn.ledger_next(vBookNumber); + + -- Apunte del proveedor + + INSERT INTO vn2008.XDiario(ASIEN, + FECHA, + SUBCTA, + EUROHABER, + CONCEPTO, + CAMBIO, + HABERME, + NFACTICK, + CLAVE, + empresa_id + ) + SELECT + vBookNumber, + n.bookEntried, + s.supplierAccount, + vTotalAmount EUROHABER, + n.conceptWithSupplier, + vRate, + vTotalAmountDivisa, + n.invoicesCount, + vInvoiceInId, + n.companyFk + FROM newInvoiceIn n + JOIN newSupplier s; + + -- Línea de Gastos + INSERT INTO vn2008.XDiario ( ASIEN, + FECHA, + SUBCTA, + CONTRA, + EURODEBE, + EUROHABER, + CONCEPTO, + CAMBIO, + DEBEME, + HABERME, + NFACTICK, + empresa_id + ) + SELECT vBookNumber ASIEN, + n.bookEntried FECHA, + IF(e.isWithheld , LPAD(RIGHT(s.supplierAccount,5),10,iit.expenceFk),iit.expenceFk) SUBCTA, + s.supplierAccount CONTRA, + IF(e.isWithheld AND iit.taxableBase < 0, NULL, ROUND(SUM(iit.taxableBase),2)) EURODEBE, + IF(e.isWithheld AND iit.taxableBase < 0,ROUND(SUM(-iit.taxableBase),2),NULL) EUROHABER, + n.conceptWithSupplier CONCEPTO, + vRate, + IF(e.isWithheld,NULL,ABS(ROUND(SUM(iit.foreignValue),2))) DEBEME, + IF(e.isWithheld,ABS(ROUND(SUM(iit.foreignValue),2)),NULL) HABERME, + n.invoicesCount NFACTICK, + n.companyFk empresa_id + FROM newInvoiceIn n + JOIN newSupplier s + JOIN invoiceInTax iit ON iit.invoiceInFk = n.id + JOIN (SELECT * FROM expence e GROUP BY e.id)e ON e.id = iit.expenceFk + WHERE e.name != 'Suplidos Transitarios nacionales' + GROUP BY iit.expenceFk; + + -- Líneas de IVA + + INSERT INTO vn2008.XDiario( ASIEN, + FECHA, + SUBCTA, + CONTRA, + EURODEBE, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + AUXILIAR, + SERIE, + TIPOOPE, + FECHA_EX, + FECHA_OP, + NFACTICK, + FACTURAEX, + L340, + LRECT349, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + TERIDNIF, + TERNIF, + TERNOM, + FECREGCON, + empresa_id + ) + SELECT vBookNumber ASIEN, + n.bookEntried FECHA, + IF(n.expenceFkDeductible>0, n.expenceFkDeductible, ti.CuentaIvaSoportado) SUBCTA, + s.supplierAccount CONTRA, + SUM(ROUND(ti.PorcentajeIva * it.taxableBase / 100 /* + 0.0001*/, 2)) EURODEBE, + SUM(it.taxableBase) BASEEURO, + GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, + vSerialNumber FACTURA, + ti.PorcentajeIva IVA, + IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR, + n.serial SERIE, + ttr.ClaveOperacionDefecto, + n.issued FECHA_EX, + n.operated FECHA_OP, + n.invoicesCount NFACTICK, + n.supplierRef FACTURAEX, + TRUE L340, + (isSameCountry OR NOT isUeeMember) LRECT349, + n.cplusTrascendency472Fk TIPOCLAVE, + n.cplusTaxBreakFk TIPOEXENCI, + n.cplusSubjectOpFk TIPONOSUJE, + n.cplusInvoiceType472Fk TIPOFACT, + n.cplusRectificationTypeFk TIPORECTIF, + iis.cplusTerIdNifFk TERIDNIF, + s.nif AS TERNIF, + s.name AS TERNOM, + n.booked FECREGCON, + n.companyFk + FROM newInvoiceIn n + JOIN newSupplier s + JOIN invoiceInTax it ON n.id = it.invoiceInFk + JOIN sage.TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk + JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = it.transactionTypeSageFk + JOIN invoiceInSerial iis ON iis.code = n.serial + JOIN (SELECT * FROM expence e GROUP BY e.id)e ON e.id = it.expenceFk + LEFT JOIN (SELECT eWithheld.id + FROM invoiceInTax hold + JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld + WHERE hold.invoiceInFk = vInvoiceInId LIMIT 1 + ) eWithheld ON TRUE + WHERE it.taxTypeSageFk IS NOT NULL + AND it.taxTypeSageFk NOT IN (22, 90) + GROUP BY ti.PorcentajeIva, e.id; + + -- Línea iva inversor sujeto pasivo + + INSERT INTO vn2008.XDiario( ASIEN, + FECHA, + SUBCTA, + CONTRA, + EUROHABER, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + AUXILIAR, + SERIE, + TIPOOPE, + FECHA_EX, + FECHA_OP, + NFACTICK, + FACTURAEX, + L340, + LRECT349, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + TERIDNIF, + TERNIF, + TERNOM, + empresa_id + ) + SELECT vBookNumber ASIEN, + n.bookEntried FECHA, + ti.CuentaIvaRepercutido SUBCTA, + s.supplierAccount CONTRA, + SUM(ROUND(ti.PorcentajeIva * it.taxableBase / 100,2)) EUROHABER, + ROUND(SUM(it.taxableBase),2) BASEEURO, + GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, + vSerialNumber FACTURA, + ti.PorcentajeIva IVA, + '*' AUXILIAR, + n.serial SERIE, + ttr.ClaveOperacionDefecto, + n.issued FECHA_EX, + n.operated FECHA_OP, + n.invoicesCount NFACTICK, + n.supplierRef FACTURAEX, + FALSE L340, + (isSameCountry OR NOT isUeeMember) LRECT349, + 1 TIPOCLAVE, + n.cplusTaxBreakFk TIPOEXENCI, + n.cplusSubjectOpFk TIPONOSUJE, + n.cplusInvoiceType472Fk TIPOFACT, + n.cplusRectificationTypeFk TIPORECTIF, + iis.cplusTerIdNifFk TERIDNIF, + s.nif AS TERNIF, + s.name AS TERNOM, + n.companyFk + FROM newInvoiceIn n + JOIN newSupplier s + JOIN invoiceInTax it ON n.id = it.invoiceInFk + JOIN sage.TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk + JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = it.transactionTypeSageFk + JOIN invoiceInSerial iis ON iis.code = n.serial + JOIN (SELECT * FROM expence e GROUP BY e.id)e ON e.id = it.expenceFk + WHERE ti.Iva = 'HP DEVENGADO 21 ISP' OR MID(s.account, 4, 1) = '1' + GROUP BY ti.PorcentajeIva, e.id; + + -- Actualización del registro original + UPDATE invoiceIn ii + JOIN newInvoiceIn ni ON ii.id = ni.id + SET ii.serialNumber = vSerialNumber, + ii.isBooked = TRUE; + + -- Problemas derivados de la precisión en los decimales al calcular los impuestos + UPDATE XDiario + SET EURODEBE = EURODEBE - + (SELECT IF(ABS(sub.difference) = 0.01, sub.difference, 0) + FROM(SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference + FROM XDiario + WHERE ASIEN = vBookNumber + )sub + ) + WHERE ASIEN = vBookNumber + AND EURODEBE <> 0 + ORDER BY id DESC + LIMIT 1; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `invoiceInBookingMain__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInBookingMain__`(vInvoiceInId INT) BEGIN DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2); DECLARE vBookNumber,vSerialNumber INT; @@ -54533,263 +55593,6 @@ BEGIN ORDER BY id DESC LIMIT 1;*/ -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `invoiceInBookingMain__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInBookingMain__`(vInvoiceInId INT) -BEGIN - DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2); - DECLARE vBookNumber,vSerialNumber INT; - DECLARE vRate DECIMAL(10,4); - DECLARE vSerial VARCHAR(2); - - CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber); - - SELECT serial - INTO vSerial - FROM newInvoiceIn; - - SELECT SUM(iit.taxableBase * IF(vSerial = 'R' AND tc.`type` <> 'I', 1 +(tc.rate/100),1)), - SUM(iit.foreignValue * IF(vSerial = 'R', 1 +(tc.rate/100),1)), - iit.taxableBase/iit.foreignValue - INTO vTotalAmount, vTotalAmountDivisa, vRate - FROM newInvoiceIn i - JOIN invoiceInTax iit ON iit.invoiceInFk = i.id - JOIN taxCode tc ON iit.taxCodeFk = tc.id; - - CALL vn.ledger_next(vBookNumber); - - -- Apunte del proveedor - - INSERT INTO vn2008.XDiario( - ASIEN, - FECHA, - SUBCTA, - EUROHABER, - CONCEPTO, - CAMBIO, - HABERME, - NFACTICK, - CLAVE, - empresa_id) - SELECT - vBookNumber, - n.bookEntried, - s.supplierAccount, - vTotalAmount EUROHABER, - n.conceptWithSupplier, - vRate, - vTotalAmountDivisa, - n.invoicesCount, - vInvoiceInId, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s; - - -- ----------------------------------------------------------- Linea de Gastos - INSERT INTO vn2008.XDiario (ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - EUROHABER, - CONCEPTO, - CAMBIO, - DEBEME, - HABERME, - NFACTICK, - empresa_id - ) - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - IF(e.isWithheld , LPAD(RIGHT(s.supplierAccount,5),10,iit.expenceFk),iit.expenceFk) SUBCTA, - s.supplierAccount CONTRA, - IF(e.isWithheld AND iit.taxableBase < 0, NULL, ROUND(SUM(iit.taxableBase),2)) EURODEBE, - IF(e.isWithheld AND iit.taxableBase < 0,ROUND(SUM(-iit.taxableBase),2),NULL) EUROHABER, - n.conceptWithSupplier CONCEPTO, - vRate, - IF(e.isWithheld,NULL,ABS(ROUND(SUM(iit.foreignValue),2))) DEBEME, - IF(e.isWithheld,ABS(ROUND(SUM(iit.foreignValue),2)),NULL) HABERME, - n.invoicesCount NFACTICK, - n.companyFk empresa_id - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax iit ON iit.invoiceInFk = n.id - JOIN taxCode tc ON tc.id = iit.taxCodeFk - JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk - WHERE iit.expenceFk != 5660000002 - GROUP BY iit.expenceFk; - - -- -------------------------------------------------------------------- - -- ------- Lineas de IVA --------------- - -- -------------------------------------------------------------------- - - INSERT INTO vn2008.XDiario( ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - TIPOOPE, - FECHA_EX, - FECHA_OP, - NFACTICK, - FACTURAEX, - L340, - LRECT349, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - FECREGCON, - empresa_id - ) - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - tc.code SUBCTA, - s.supplierAccount CONTRA, - SUM(ROUND(tc.rate/100 * it.taxableBase/* + 0.0001*/, 2)) EURODEBE, - SUM(it.taxableBase) BASEEURO, - GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, - vSerialNumber FACTURA, - tc.rate IVA, - IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR, - n.serial SERIE, - tt.TIPOOPE, - n.issued FECHA_EX, - n.operated FECHA_OP, - n.invoicesCount NFACTICK, - n.supplierRef FACTURAEX, - TRUE L340, - (isSameCountry OR NOT isUeeMember) LRECT349, - n.cplusTrascendency472Fk TIPOCLAVE, - n.cplusTaxBreakFk TIPOEXENCI, - n.cplusSubjectOpFk TIPONOSUJE, - n.cplusInvoiceType472Fk TIPOFACT, - n.cplusRectificationTypeFk TIPORECTIF, - iis.cplusTerIdNifFk TERIDNIF, - s.nif AS TERNIF, - s.name AS TERNOM, - n.booked FECREGCON, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax it ON n.id = it.invoiceInFk - JOIN taxCode tc ON tc.id = it.taxCodeFk - JOIN taxType tt ON tt.id = tc.taxTypeFk - JOIN invoiceInSerial iis ON iis.code = tt.serial - JOIN expence e ON e.id = it.expenceFk - AND e.taxTypeFk = tc.taxTypeFk - LEFT JOIN (SELECT eWithheld.id - FROM invoiceInTax hold - JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld - WHERE hold.invoiceInFk = vInvoiceInId LIMIT 1 - ) eWithheld ON TRUE - WHERE tc.type != '-' - AND tc.isActive - GROUP BY tc.rate, e.id; - - -- Linea iva inversor sujeto pasivo - - INSERT INTO vn2008.XDiario( ASIEN, - FECHA, - SUBCTA, - CONTRA, - EUROHABER, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - TIPOOPE, - FECHA_EX, - FECHA_OP, - NFACTICK, - FACTURAEX, - L340, - LRECT349, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - empresa_id - ) - - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - tcLink.code SUBCTA, - s.supplierAccount CONTRA, - SUM(ROUND(tcLink.rate/100*it.taxableBase + 0.0001,2)) EUROHABER, - ROUND(SUM(it.taxableBase),2) BASEEURO, - GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, - vSerialNumber FACTURA, - tcLink.rate IVA, - '*' AUXILIAR, - n.serial SERIE, - tt.TIPOOPE, - n.issued FECHA_EX, - n.operated FECHA_OP, - n.invoicesCount NFACTICK, - n.supplierRef FACTURAEX, - FALSE L340, - (isSameCountry OR NOT isUeeMember) LRECT349, - 1 TIPOCLAVE, - n.cplusTaxBreakFk TIPOEXENCI, - n.cplusSubjectOpFk TIPONOSUJE, - n.cplusInvoiceType472Fk TIPOFACT, - n.cplusRectificationTypeFk TIPORECTIF, - iis.cplusTerIdNifFk TERIDNIF, - s.nif AS TERNIF, - s.name AS TERNOM, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax it ON n.id = it.invoiceInFk - JOIN taxCode tc ON tc.id = it.taxCodeFk - JOIN taxType tt ON tt.id = tc.taxTypeFk - JOIN invoiceInSerial iis ON iis.code = tt.serial - JOIN taxCode tcLink ON tcLink.link = tc.link - AND tc.id != tcLink.id - AND tc.link - JOIN expence e ON e.id = it.expenceFk - AND e.taxTypeFk = tc.taxTypeFk - WHERE tc.isActive - AND (tc.type in('S','I') OR MID(s.supplierAccount,4,1) = '1') - GROUP BY tcLink.rate, e.id; - - -- Actualización del registro original - UPDATE invoiceIn ii - JOIN newInvoiceIn ni ON ii.id = ni.id - SET ii.serialNumber = vSerialNumber, - ii.isBooked = TRUE; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55047,6 +55850,83 @@ BEGIN SET ii.serialNumber = vSerialNumber, ii.isBooked = TRUE; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `invoiceInDueDay_calculate` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInDueDay_calculate`(vInvoiceInFk INT) +BEGIN + + IF !(SELECT COUNT(*) + FROM invoiceInDueDay iid + WHERE iid.invoiceInFk = vInvoiceInFk) THEN + + INSERT INTO invoiceInDueDay (invoiceInFk, + dueDated, + amount, + foreignValue) + SELECT vInvoiceInFk, + IF(payDay, vn2008.next_venc(issued, detalle, payDay),TIMESTAMPADD(DAY, detalle, issued)), + IF((@cont:=@cont + 1) < cont, TRUNCATE(venc / cont, 2),venc-(TRUNCATE(venc / cont, 2) * (cont - 1))), + IF(@cont < cont, TRUNCATE(foreignValue / cont, 2), foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) + FROM ( + SELECT SUM((1 + (ti.PorcentajeIva / 100)*(s.countryFk = s2.countryFk)) * iit.taxableBase)/COUNT(DISTINCT(pdd.detalle)) venc, + SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detalle)) foreignValue, + s.payDemFk, + ii.companyFk, + COUNT(DISTINCT(pdd.detalle)) cont, + s.payDay, + ii.issued + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + JOIN sage.TiposIva AS ti ON ti.CodigoIva= iit.taxTypeSageFk + JOIN supplier s ON s.id = ii.supplierFk + JOIN supplier s2 ON s2.id = ii.companyFk + JOIN vn2008.pay_dem_det pdd ON pdd.id = s.payDemFk + WHERE ii.id = vInvoiceInFk + GROUP BY ii.id + ) sub + JOIN (SELECT @cont:=0) sub2 + JOIN vn2008.pay_dem_det pdd ON pdd.id = sub.payDemFk + GROUP BY detalle; + END IF; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `invoiceInDueDay_recalc` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInDueDay_recalc`(vInvoiceInFk INT) +BEGIN + + DELETE FROM invoiceInDueDay + WHERE invoiceInFk = vInvoiceInFk; + + CALL invoiceInDueDay_calculate(vInvoiceInFk); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55098,6 +55978,109 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `invoiceInTax_getFromDua` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInTax_getFromDua`(vDuaFk INT) +BEGIN + + DECLARE done BOOL DEFAULT FALSE; + DECLARE vInvoiceInFk INT; + + DECLARE rs CURSOR FOR + SELECT invoiceInFk + FROM entry e + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + FETCH rs INTO vInvoiceInFk; + + WHILE NOT done DO + + CALL invoiceInTax_getFromEntries(vInvoiceInFk); + CALL invoiceInDueDay_calculate(vInvoiceInFk); + + FETCH rs INTO vInvoiceInFk; + + END WHILE; + + CLOSE rs; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `invoiceInTax_getFromEntries` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `invoiceInTax_getFromEntries`(IN vId INT) +BEGIN + DECLARE vRate DOUBLE DEFAULT 1; + DECLARE vDated DATE; + DECLARE vExpenceFk VARCHAR(10); + + SELECT MAX(rr.dated) INTO vDated + FROM referenceRate rr + JOIN invoiceIn ii ON ii.id = vId + WHERE rr.dated <= ii.issued + AND rr.currencyFk = ii.currencyFk ; + + IF vDated THEN + SELECT `value` INTO vRate + FROM referenceRate + WHERE dated = vDated; + END IF; + + SELECT id INTO vExpenceFk + FROM vn.expence + WHERE `name` = 'Adquisición mercancia Extracomunitaria' + GROUP BY id + LIMIT 1; + + DELETE FROM invoiceInTax + WHERE invoiceInFk = vId; + + INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, foreignValue, taxTypeSageFk, transactionTypeSageFk) + SELECT ii.id, + SUM(b.buyingValue * b.quantity) / IFNULL(vRate,1) taxableBase, + vExpenceFk, + IF(ii.currencyFk = 1,NULL,SUM(b.buyingValue * b.quantity )) divisa, + taxTypeSageFk, + transactionTypeSageFk + FROM invoiceIn ii + JOIN entry e ON e.invoiceInFk = ii.id + JOIN supplier s ON s.id = e.supplierFk + JOIN buy b ON b.entryFk = e.id + LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk + AND rr.dated = ii.issued + WHERE ii.id = vId + HAVING taxableBase IS NOT NULL; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutAgain` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -55750,10 +56733,11 @@ BEGIN LEFT JOIN sale s ON s.ticketFk = t.id LEFT JOIN ticketService ts ON ts.ticketFk = t.id; - IF vIsAnySaleToInvoice OR vIsAnyServiceToInvoice THEN + IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) + AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) + THEN -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial INSERT INTO invoiceOut ( ref, @@ -55869,13 +56853,13 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `invoiceOut_newFromTicket`(vTicketFk INT, vSerial CHAR(1), vTaxArea VARCHAR(25), OUT vInvoiceId INT) +CREATE DEFINER=`root`@`%` PROCEDURE `invoiceOut_newFromTicket`(vTicketFk INT, vSerial CHAR(1), vTaxArea VARCHAR(25), vRef VARCHAR(25), OUT vInvoiceId INT) BEGIN /** * Factura un ticket @@ -55885,6 +56869,7 @@ BEGIN * en la mayoria de los casos poner NULL * @return vInvoiceId */ + DECLARE vIsRefEditable BOOLEAN; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; @@ -55895,6 +56880,19 @@ BEGIN CALL invoiceFromTicket(vTicketFk); CALL invoiceOut_new(vSerial, CURDATE(), vTaxArea, vInvoiceId); + IF vRef IS NOT NULL THEN + SELECT isRefEditable INTO vIsRefEditable + FROM invoiceOutSerial + WHERE code = vSerial; + IF NOT vIsRefEditable THEN + CALL util.throw('serial non editable'); + END IF; + + UPDATE invoiceOut + SET `ref` = vRef + WHERE id = vInvoiceId; + END IF; + IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN CALL invoiceOutBooking(vInvoiceId); IF account.myUser_getId() IS NOT NULL THEN @@ -57163,12 +58161,15 @@ BEGIN i.value8, (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, a.available, - IFNULL(ip.counter,0) counter + IFNULL(ip.counter,0) counter, + IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity FROM vn.item i JOIN cache.available a ON a.item_id = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 - LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id WHERE a.calc_id = vCalcFk AND available > 0 AND IF(vShowType,i.typeFk = vTypeFk,true) @@ -58338,18 +59339,12 @@ BEGIN DECLARE vCalcVisibleFk INT; - DECLARE vWarehouseFk INT; - DECLARE vSectorFk INt; - DECLARE vFatherSectorFk INT; + DECLARE vWarehouseFk INT DEFAULT 60; + -- DECLARE vSectorFk INt; + -- DECLARE vFatherSectorFk INT; -- Eliminar cuando tengamos programador de Android - SET vSectorFk = 37; - SET vFatherSectorFk = 38; - - SELECT s.warehouseFk INTO vWarehouseFk - FROM vn.sector s - WHERE s.id = vSectorFk; - + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); SELECT * FROM ( @@ -58367,128 +59362,59 @@ BEGIN CONCAT(i.longName,' ',i.size,' ',IFNULL(i.subName,'') ) longName, '' size, CONCAT(iss.parkingCode , ' ', iss.shelvingFk) producer, - SUM(IF(s.id = vFatherSectorFk, IFNULL(iss.visible,0), 0)) upstairs, - SUM(IF(s.id = vSectorFk, IFNULL(iss.visible,0), 0)) downstairs, + 0 upstairs, + SUM(IFNULL(iss.visible,0)) downstairs, IF(it.isPackaging, null, IFNULL(v.visible,0)) as visible, - vSectorFk as sectorFk - FROM vn.itemShelvingStock iss - JOIN vn.sector s ON s.id = iss.sectorFk - JOIN vn.item i on i.id = iss.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk - WHERE iss.sectorFk IN (vSectorFk, vFatherSectorFk) - AND it.workerFk = vWorkerFk - GROUP BY itemFk + 0 as sectorFk + FROM vn.itemShelvingStock iss + JOIN vn.sector s ON s.id = iss.sectorFk + JOIN vn.item i on i.id = iss.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk + WHERE s.warehouseFk = vWarehouseFk + AND it.workerFk = vWorkerFk + GROUP BY itemFk ) sub LEFT JOIN (SELECT s.itemFk , sum(s.quantity) as pendiente - FROM vn.sale s - LEFT JOIN vn.saleTracking st ON st.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.client c on c.id = t.clientFk - WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) - AND ISNULL(st.saleFk) - AND c.isOfficial - GROUP BY s.itemFk) sub2 ON sub2.itemFk = sub.itemFk - ORDER BY producer) sub3 - WHERE nicho - ; - - - - - - /* - DECLARE vCalcVisibleFk INT; - DECLARE vCalcAvailableFk INT; - DECLARE vWarehouseFk INT; - DECLARE vSectorFk INt; - DECLARE vFatherSectorFk INT; - - -- Eliminar cuando tengamos programador de Android - SET vSectorFk = 37; - SET vFatherSectorFk = 38; - - SELECT s.warehouseFk INTO vWarehouseFk - FROM vn.sector s - WHERE s.id = vSectorFk; - - CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); - - SELECT * FROM ( - SELECT sub.itemFk, - sub.longName, - CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, - CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer, - sub.upstairs, - sub.downstairs, - sub.visible, - sub.sectorFk, - CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho - FROM ( - SELECT sub4.itemFk, - CONCAT(sub4.longName,' ',sub4.size,' ',IFNULL(sub4.subName,'') ) longName, - '' `size`, - CONCAT(sub4.parkingCode , ' ', sub4.shelvingFk) producer, - SUM(IF(sub4.sectorFk = vFatherSectorFk, IFNULL(sub4.visible,0), 0)) upstairs, - SUM(IF(sub4.sectorFk = vSectorFk, IFNULL(sub4.visible,0), 0)) downstairs, - IFNULL(sub4.visible,0) as visible, - sub4.sectorFk - FROM - ( - - SELECT iss.itemFk, - iss.parkingCode , - iss.shelvingFk , - iss.visible , - iss.sectorFk, - i.longName, - i.`size`, - i.subName - FROM vn.itemShelvingStock iss - JOIN vn.item i on i.id = iss.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk - WHERE iss.sectorFk IN (vSectorFk, vFatherSectorFk) - AND it.workerFk = vWorkerFk - - UNION ALL - - SELECT v.item_id , - NULL, - NULL, - v.visible, - vSectorFk, - i.longName, - i.`size`, - i.subName - FROM cache.visible v - JOIN vn.item i on i.id = v.item_id - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id - WHERE v.calc_id = vCalcVisibleFk - AND iss.sectorFk IN (vSectorFk, vFatherSectorFk) - AND it.workerFk = vWorkerFk - AND iss.itemFk IS NULL - - ) sub4 - JOIN vn.sector s ON s.id = sub4.sectorFk - GROUP BY sub4.itemFk - ) sub - LEFT JOIN (SELECT s.itemFk , sum(s.quantity) as pendiente - FROM vn.sale s - LEFT JOIN vn.saleTracking st ON st.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.client c on c.id = t.clientFk - WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) - AND ISNULL(st.saleFk) - AND c.isOfficial - GROUP BY s.itemFk) sub2 ON sub2.itemFk = sub.itemFk - ORDER BY producer) sub3 - WHERE nicho - ; - */ - - + FROM vn.sale s + LEFT JOIN vn.saleTracking st ON st.saleFk = s.id + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.client c on c.id = t.clientFk + WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND ISNULL(st.saleFk) + AND c.isOfficial + GROUP BY s.itemFk) sub2 ON sub2.itemFk = sub.itemFk + + UNION ALL + + SELECT v.item_id , + i.longName, + CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, + 0, + 0, + v.visible, + 0, + v.visible AS nicho + FROM cache.visible v + JOIN vn.item i ON i.id = v.item_id + JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id + LEFT JOIN (SELECT s.itemFk , sum(s.quantity) as pendiente + FROM vn.sale s + LEFT JOIN vn.saleTracking st ON st.saleFk = s.id + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.client c on c.id = t.clientFk + WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND ISNULL(st.saleFk) + AND c.isOfficial + GROUP BY s.itemFk) sub5 ON sub5.itemFk = v.item_id + WHERE v.calc_id = vCalcVisibleFk + AND ISNULL(iss.itemFk) + AND it.workerFk = vWorkerFk) sub3 + WHERE nicho + ORDER BY producer; + END ;; DELIMITER ; @@ -58615,17 +59541,17 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingTicketSource` */; +/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingTicketSource__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `itemShelvingTicketSource`(vTicketFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `itemShelvingTicketSource__`(vTicketFk INT) BEGIN DECLARE vCalcFk INT; DECLARE vWarehouseFk INT; @@ -61597,9 +62523,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -61618,8 +62544,9 @@ BEGIN DECLARE vWarehouse INT DEFAULT 13; DECLARE vComponentCost INT DEFAULT 28; DECLARE vGraceDate DATE; + DECLARE vDateEnd DATE; - SET vGraceDays = IF(vIsAllInvoiceable,0,30); + SET vGraceDays = IF(vIsAllInvoiceable ,0, 30); SET vGraceDate = TIMESTAMPADD(DAY, - vGraceDays, vDate); /* Clientes especiales: @@ -61633,8 +62560,9 @@ BEGIN SET vGraceDays = 365; END IF; - - /* Fin clientes especiales */ + /* Fin clientes especiales */ + + SET vDateEnd = DATE_ADD(vDate, INTERVAL 1 DAY); DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoice; @@ -61647,7 +62575,7 @@ BEGIN FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk JOIN ticket t ON t.id = tp.ticketFk - WHERE t.shipped BETWEEN vDateStart AND vDate + WHERE t.shipped BETWEEN vDateStart AND vDateEnd AND t.clientFk = vClient; DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoicePositives; @@ -61658,15 +62586,24 @@ BEGIN GROUP BY itemFk HAVING totalQuantity > 0; - SELECT GREATEST(COUNT(*),vIsAllInvoiceable) + SELECT COUNT(*) INTO vIsInvoiceable FROM tmp.packageToInvoicePositives; IF vIsInvoiceable THEN - CALL vn.ticketCreateWithUser(vClient, vDate, vWarehouse, vCompany, NULL, NULL, NULL, vDate, account.userGetId(), vNewTicket); + CALL ticketCreateWithUser(vClient, + vDateEnd, + vWarehouse, + vCompany, + NULL, + NULL, + NULL, + vDateEnd, + account.userGetId(), + vNewTicket); - INSERT INTO ticketPackaging( + INSERT INTO ticketPackaging( ticketFk, packagingFk, quantity, @@ -62019,7 +62956,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `parking_algemesi`(vFromRow INT, vToRow INT, vSectorFk INT, vLetter VARCHAR(1), vPickingOrder INT) +CREATE DEFINER=`root`@`%` PROCEDURE `parking_algemesi`(vFromRow INT, vToRow INT, vSectorFk INT, vLetter VARCHAR(1), vPickingOrder INT, vTrolleysByLine INT) BEGIN DECLARE vRow INT; @@ -62034,7 +62971,7 @@ BEGIN SET i = 1; - WHILE i <= 4 DO + WHILE i <= vTrolleysByLine DO SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); @@ -62058,7 +62995,7 @@ BEGIN SET i = 1; - WHILE i <= 4 DO + WHILE i <= vTrolleysByLine DO SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); @@ -62168,6 +63105,46 @@ BEGIN END WHILE; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `parking_setOrder` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!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 `parking_setOrder`(vWarehouseFk INT) +BEGIN + + /* + * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor + */ + + UPDATE vn.parking p + JOIN ( + SELECT code, + @orden := @orden + 10 AS po + FROM ( + SELECT c.prepOrder, + p.code, + @orden := 0, + IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , + CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication + FROM vn.parking p + JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci + WHERE s.warehouseFk = vWarehouseFk) sub + ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code + SET p.pickingOrder = sub2.po; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62219,7 +63196,7 @@ BEGIN JOIN vn.workerJourney wj ON w.userFk = wj.userFk JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id - JOIN vn2008.department d ON bl.department_id = d.department_id + JOIN vn.department d ON bl.department_id = d.id JOIN postgresql.business_labour_payroll blp ON bl.business_id = blp.business_id JOIN postgresql.business b ON b.business_id = wj.businessFk LEFT JOIN @@ -62327,25 +63304,27 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `previousPreparationSticker_get`(vTicketFk INT) BEGIN - SELECT t.id ticketFk, - p.code as location, - t.observations, - IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour, - IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute , - i.itemPackingTypeFk , - count(*) items - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = 38 - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.shelving sh ON sh.code = t.id - LEFT JOIN vn.parking p ON p.id = sh.parkingFk - WHERE t.id = vTicketFk + SELECT t.id ticketFk, + p.code as location, + t.observations, + IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour, + IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute , + i.itemPackingTypeFk , + count(*) items + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + -- JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = 38 + JOIN vn.saleTracking st ON st.saleFk = s.id + JOIN vn.state ss ON ss.id = st.stateFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.shelving sh ON sh.code = t.id + LEFT JOIN vn.parking p ON p.id = sh.parkingFk + WHERE t.id = vTicketFk + AND ss.code = 'PREVIOUS_PREPARATION' + AND st.isChecked = FALSE GROUP BY i.itemPackingTypeFk ; - - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62400,7 +63379,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 `productionControl` */; +/*!50003 DROP PROCEDURE IF EXISTS `prod` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -62410,7 +63389,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `productionControl`(vWarehouseFk INT, vScopeDays INT) +CREATE DEFINER=`root`@`%` PROCEDURE `prod`(vWarehouseFk INT, vScopeDays INT) proc: BEGIN DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(CURDATE())); @@ -62449,10 +63428,10 @@ proc: BEGIN , t.packages , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure - , MINUTE(t.shipped) as mm + , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm , t.routeFk , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona - , a.nickname addressNickname + , t.nickname addressNickname , a.postalCode , a.city , p.name province @@ -62556,25 +63535,261 @@ proc: BEGIN JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk JOIN vn.collection c ON c.id = tc.collectionFk SET pb.collectionH = c.id - WHERE pb.H AND (c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk)); + WHERE c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk); UPDATE tmp.productionBuffer pb JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk JOIN vn.collection c ON c.id = tc.collectionFk SET pb.collectionV = c.id - WHERE pb.V AND (c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk)); + WHERE c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk); UPDATE tmp.productionBuffer pb JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk JOIN vn.collection c ON c.id = tc.collectionFk SET pb.collectionF = c.id - WHERE pb.F AND (c.itemPackingTypeFk = 'F' OR ISNULL(c.itemPackingTypeFk)); + WHERE c.itemPackingTypeFk = 'F' OR ISNULL(c.itemPackingTypeFk); UPDATE tmp.productionBuffer pb JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk JOIN vn.collection c ON c.id = tc.collectionFk SET pb.collectionP = c.id - WHERE pb.P AND (c.itemPackingTypeFk = 'P' OR ISNULL(c.itemPackingTypeFk)); + WHERE c.itemPackingTypeFk = 'P' OR ISNULL(c.itemPackingTypeFk); + + -- Cajas + ALTER TABLE tmp.productionBuffer + ADD Cajas DOUBLE DEFAULT NULL; + /* + -- Problemas por ticket + UPDATE tmp.productionBuffer pb + JOIN tmp.ticketProblems tp ON tp.ticketFk = pb.ticketFk + SET pb.problem = CAST(CONCAT( IFNULL(tp.itemShortage,''), + IFNULL(tp.itemDelay,''), + IF(tp.isFreezed,' CONGELADO',''), + IF(tp.risk,' RIESGO',''), + IF(tp.hasTicketRequest, ' COD 100',''), + IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), + IF(tp.componentLack,' COMPONENTES', '') + ) as char(255)); + */ + -- Refresca la caché para el cierre dinámico de agencias + -- CALL cache.departure_timing(vWarehouseFk); +/* + -- Tickets de recogida + REPLACE tmp.productionBuffer( + shipped + , ticketFk + , agency + , clientFk + , addressNickname + , state + , workerCode + , alertLevel + , warehouseFk + ) + SELECT DATE(t.shipped) + , t.id + , am.name + , t.clientFk + , a.nickname + , s.id as state + , w.code + , ifnull(tls.alertLevel,0) alert_level + , vWarehouseFk + FROM vn.ticket t + JOIN vn.address a on a.id = t.addressFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = am.id + LEFT JOIN vn.ticketState tls on tls.ticket = t.id + LEFT JOIN vn.state s ON s.id = tls.state + LEFT JOIN vn.worker w on w.id = tls.worker + WHERE t.shipped between TIMESTAMPADD(WEEK,-1,CURDATE()) AND util.dayend(TIMESTAMPADD(DAY,-1,CURDATE())) + AND wp.warehouse_id = vWarehouseFk; +*/ + DROP TEMPORARY TABLE tmp.productionTicket; + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `productionControl` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `productionControl`(vWarehouseFk INT, vScopeDays INT) +proc: BEGIN + + DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(CURDATE())); + + DECLARE vIsTodayRelative BOOLEAN; + + SELECT isTodayRelative INTO vIsTodayRelative + FROM vn.worker + WHERE userFk = vn.getUser(); + + CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,CURDATE()), vEndingDate); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT * FROM tmp.productionTicket; + + CALL vn.prepareClientList(); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems; + CREATE TEMPORARY TABLE tmp.ticketGetProblems + (INDEX (ticketFk)) ENGINE = MEMORY + SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped + FROM tmp.productionTicket tt + JOIN vn.ticket t ON t.id = tt.ticketFk; + + CALL vn.ticketGetProblems(vIsTodayRelative); + + DROP TEMPORARY TABLE IF EXISTS tmp.productionBuffer; + CREATE TEMPORARY TABLE tmp.productionBuffer + (PRIMARY KEY(ticketFk)) + ENGINE = MEMORY + SELECT tt.ticketFk + , tt.clientFk + , t.warehouseFk + , t.nickname + , t.packages + , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH + , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure + , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm + , t.routeFk + , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona + , t.nickname addressNickname + , a.postalCode + , a.city + , p.name province + , CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency + , am.id agencyModeFk + , 0 AS `lines` + , CAST( 0 AS DECIMAL(5,2)) AS m3 + , CAST( 0 AS DECIMAL(5,2)) AS preparationRate + , "" as problem + , IFNULL(tls.state,2) AS state + , w.code workerCode + , DATE(t.shipped) shipped + , wk.code AS salesPersonCode + , p.id provinceFk + , tls.productionOrder + , ifnull(tls.alertLevel,0) alertLevel + , t.isBoxed as palletized + , rg.deviceId ubicacion + , tlu.lastUpdated + -- , tls.updated lastUpdated + , ifnull(st.graphCategory,0) graphCategory + , pk.code as parking + , 0 AS H + , 0 AS V + , 0 AS F + , 0 AS P + , st.isOk + , ag.isOwn + FROM tmp.productionTicket tt + JOIN vn.ticket t on tt.ticketFk = t.id + LEFT JOIN vn.ticketStateToday tst ON tst.ticket = t.id + LEFT JOIN vn.state st ON st.id = tst.state + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk + JOIN vn.address a on a.id = t.addressFk + LEFT JOIN vn.province p on p.id = a.provinceFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.agency ag ON ag.id = am.agencyFk + LEFT JOIN vn.ticketState tls on tls.ticket = tt.ticketFk + LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk + LEFT JOIN vn.worker w on w.id = tls.worker + LEFT JOIN vn.routeGate rg ON rg.routeFk = t.routeFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND date(t.shipped) = zc.dated + LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id + LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk + WHERE t.warehouseFk = vWarehouseFk + AND am.deliveryMethodFk IN (1,2,3); + + ALTER TABLE tmp.productionBuffer + CHANGE COLUMN `problem` `problem` VARCHAR(255), + ADD COLUMN `collectionH` INT, + ADD COLUMN `collectionV` INT, + ADD COLUMN `collectionF` INT, + ADD COLUMN `collectionP` INT; + + -- Líneas y volumen por ticket + UPDATE tmp.productionBuffer pb + JOIN ( + SELECT tt.ticketFk, + COUNT(*) as `lines`, + sum(sv.volume) as m3, + IFNULL(sum(IF(sv.isPicked,sv.volume,0)) / sum(sv.volume),0) as rate + FROM tmp.productionTicket tt + JOIN vn.saleVolume sv on sv.ticketFk = tt.ticketFk + GROUP BY tt.ticketFk + ) m on m.ticketFk = pb.ticketFk + SET pb.`lines` = m.`lines`, + pb.m3 = m.m3, + pb.preparationRate = m.rate; + + DELETE FROM tmp.productionBuffer + WHERE `lines`= 0; + + -- Lineas por linea de encajado + UPDATE tmp.productionBuffer pb + JOIN ( SELECT ticketFk, + sum(sub.H) H, + sum(sub.V) V, + sum(sub.F) F, + sum(sub.P) P + FROM ( + SELECT t.ticketFk, + sum(i.itemPackingTypeFk = 'H') H, + sum(i.itemPackingTypeFk = 'V') V, + sum(i.itemPackingTypeFk = 'F') F, + sum(i.itemPackingTypeFk = 'P') P + FROM tmp.productionTicket t + JOIN vn.sale s ON s.ticketFk = t.ticketFk + JOIN vn.item i ON i.id = s.itemFk + GROUP BY t.ticketFk, i.itemPackingTypeFk) sub + GROUP BY ticketFk + ) sub2 ON sub2.ticketFk = pb.ticketFk + SET pb.H = sub2.H, + pb.V = sub2.V, + pb.F = sub2.F, + pb.P = sub2.P; + + -- Colecciones segun tipo de encajado + UPDATE tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk + JOIN vn.collection c ON c.id = tc.collectionFk + SET pb.collectionH = c.id + WHERE c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk); + + UPDATE tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk + JOIN vn.collection c ON c.id = tc.collectionFk + SET pb.collectionV = c.id + WHERE c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk); + + UPDATE tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk + JOIN vn.collection c ON c.id = tc.collectionFk + SET pb.collectionF = c.id + WHERE c.itemPackingTypeFk = 'F' OR ISNULL(c.itemPackingTypeFk); + + UPDATE tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk + JOIN vn.collection c ON c.id = tc.collectionFk + SET pb.collectionP = c.id + WHERE c.itemPackingTypeFk = 'P' OR ISNULL(c.itemPackingTypeFk); -- Cajas ALTER TABLE tmp.productionBuffer @@ -62588,7 +63803,8 @@ proc: BEGIN IF(tp.isFreezed,' CONGELADO',''), IF(tp.risk,' RIESGO',''), IF(tp.hasTicketRequest, ' COD 100',''), - IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA') + IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), + IF(tp.componentLack,' COMPONENTES', '') ) as char(255)); -- Refresca la caché para el cierre dinámico de agencias @@ -62649,7 +63865,13 @@ CREATE DEFINER=`root`@`%` PROCEDURE `productionControl__`(vWarehouseFk INT, vSco proc: BEGIN DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(CURDATE())); - + + DECLARE vIsTodayRelative BOOLEAN; + + SELECT isTodayRelative INTO vIsTodayRelative + FROM vn.worker + WHERE userFk = vn.getUser(); + CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,CURDATE()), vEndingDate); DROP TEMPORARY TABLE IF EXISTS tmp.ticket; @@ -62665,7 +63887,7 @@ proc: BEGIN FROM tmp.productionTicket tt JOIN vn.ticket t ON t.id = tt.ticketFk; - CALL vn.ticketGetProblems(); + CALL vn.ticketGetProblems(vIsTodayRelative); DROP TEMPORARY TABLE IF EXISTS tmp.productionBuffer; CREATE TEMPORARY TABLE tmp.productionBuffer @@ -62678,10 +63900,10 @@ proc: BEGIN , t.packages , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure - , MINUTE(t.shipped) as mm + , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm , t.routeFk , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona - , a.nickname addressNickname + , t.nickname addressNickname , a.postalCode , a.city , p.name province @@ -62876,7 +64098,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `productionSectorList`(vSectorFk INT) BEGIN - + /* DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; CREATE TEMPORARY TABLE tmp.clientGetDebt SELECT DISTINCT t.clientFk @@ -62884,7 +64106,15 @@ BEGIN JOIN vn.itemShelvingAvailable isa ON isa.ticketFk = t.id; CALL vn.clientGetDebt(CURDATE()); - + */ + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM vn.sector + WHERE id = vSectorFk; + + CALL vn.productionControl(vWarehouseFk, 0); + SELECT 0,999999,0 INTO @sameTicket, @ticket, @litrosTicket; SELECT @litrosTicket := IF(sub.ticketFk = @ticket, @litrosTicket + Litros, Litros) as LitrosTicket, @@ -62903,16 +64133,21 @@ BEGIN i.subName, CAST(isa.physicalVolume * 1000 AS DECIMAL(10,0)) as Litros FROM vn.itemShelvingAvailable isa - JOIN vn.item i ON i.id = isa.itemFk - JOIN vn.sector s ON s.id = isa.sectorFk AND s.warehouseFk = isa.warehouseFk - JOIN vn.ticket t ON t.id = isa.ticketFk - JOIN vn.client c ON c.id = t.clientFk - JOIN tmp.risk r ON r.clientFk = c.id - WHERE IF(s.isPreviousPreparedByPacking, (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), TRUE) - -- AND isa.isPreviousPreparable = TRUE + JOIN vn.item i ON i.id = isa.itemFk + JOIN vn.sector s ON s.id = isa.sectorFk AND s.warehouseFk = isa.warehouseFk + JOIN vn.ticket t ON t.id = isa.ticketFk + JOIN vn.client c ON c.id = t.clientFk + -- JOIN tmp.risk r ON r.clientFk = c.id + JOIN tmp.productionBuffer pb ON pb.ticketFk = t.id + JOIN vn.packagingConfig pc + WHERE IF(s.isPreviousPreparedByPacking, + i.`size` > pc.previousPreparationMinimumSize + AND isa.packing > 1 + AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), + TRUE) AND isa.sectorFk = vSectorFk AND isa.quantity > 0 - AND r.risk < c.credit + 10 + AND pb.problem = "" GROUP BY saleFk HAVING isa.quantity <= totalAvailable ) sub2 @@ -63581,7 +64816,7 @@ BEGIN LEFT(IF(t.routeFk IS null, am.name, zo.name ),12) agencyDescription, am.name, t.clientFk, - '' notes, + count(*) notes, w.code workerCode, tt.labelCount, IF(HOUR(t.shipped),TIME(t.shipped),TIME(zo.HOUR)) as horaagencia, @@ -63610,7 +64845,7 @@ BEGIN LEFT(IF(t.routeFk IS null, am.name, zo.name ),12) agencyDescription, am.name, t.clientFk, - '' notes, + CAST(IF(ic.code = 'plant', CONCAT(MAX(i.size),' cm'),count(*)) AS CHAR) notes, w.code workerCode, tt.labelCount, IF(HOUR(t.shipped),TIME(t.shipped),TIME(zo.HOUR)) as horaagencia, @@ -63619,6 +64854,9 @@ BEGIN FROM vn.ticket t JOIN vn.ticketCollection tc ON tc.ticketFk = t.id JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk JOIN vn.collection c ON c.id = tc.collectionFk JOIN vn.worker w ON w.id = c.workerFk JOIN vn.agencyMode am on am.id = t.agencyModeFk @@ -63681,17 +64919,17 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `routeGateAsign` */; +/*!50003 DROP PROCEDURE IF EXISTS `routeGateAsign__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `routeGateAsign`(vDevice VARCHAR(30), vRouteFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `routeGateAsign__`(vDevice VARCHAR(30), vRouteFk INT) BEGIN /* UPDATE routeGate @@ -63767,6 +65005,42 @@ BEGIN rg.ready = IF(rg.freeTickets, FALSE, rg.ready); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `routeGate_assignDevice` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `routeGate_assignDevice`(vDevice VARCHAR(30), vRouteFk INT) +BEGIN +/** + * Asigna el dispositivo la ruta + * + * @param vDevice Dispositivo a remplazar + * @param vRouteFk Ruta a la cual asignarlo + */ + IF ISNULL(vDevice) THEN + + DELETE FROM routeGate + WHERE routeFk = vRouteFk; + + ELSE + + REPLACE routeGate(routeFk, deviceId) + VALUES(vRouteFk, vDevice); + + END IF; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -63880,9 +65154,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -63890,11 +65164,13 @@ CREATE DEFINER=`root`@`%` PROCEDURE `routeUpdateM3`(vRoute INT) BEGIN UPDATE vn.route r - JOIN (SELECT routeFk, SUM(volume) AS m3 - FROM saleVolume - WHERE routeFk = vRoute - ) v ON v.routeFk = r.id - SET r.m3 = v.m3; + LEFT JOIN ( + SELECT routeFk, SUM(volume) AS m3 + FROM saleVolume + WHERE routeFk = vRoute + ) v ON v.routeFk = r.id + SET r.m3 = IFNULL(v.m3,0) + WHERE r.id =vRoute; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64100,7 +65376,7 @@ BEGIN JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE s.id = vSaleFk - AND ic.code = 'pets') THEN + AND ic.code = 'fruit') THEN INSERT INTO vn.saleBuy (saleFk, buyFk) VALUES(vSaleFk, vBuyFk); @@ -66431,6 +67707,61 @@ 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 `supplier_checkBalance` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `supplier_checkBalance`(IN vDateTo DATETIME, IN vIsConciliated BOOL) +BEGIN + + DECLARE vDateFrom DATE; + SET vDateTo = TIMESTAMP(vDateTo,'23:59:59'); + SELECT util.firstDayOfYear(vDateTo) INTO vDateFrom; + + SELECT c.code, s.id , s.account, mysql, sage, mysql - sage difference, sub1.companyFk, s.name + FROM supplier s + JOIN ( SELECT companyFk, supplierFk, ROUND(SUM(mysql),2) mysql, ROUND(SUM(sage),2) sage + FROM ( SELECT companyFk, supplierFk, -SUM(iid.amount) as mysql, 0 sage + FROM invoiceInDueDay iid + JOIN invoiceIn ii ON ii.id = iid.invoiceInFk + WHERE IFNULL(ii.bookEntried, ii.issued) BETWEEN vDateFrom AND vDateTo + AND ii.isBooked + GROUP BY ii.id + UNION ALL + SELECT p.companyFk, p.supplierFk, p.amount, 0 + FROM payment p + JOIN payMethod pm ON pm.id = p.payMethodFk + WHERE p.received BETWEEN vDateFrom AND vDateTo + AND IF(vIsConciliated, p.isConciliated, TRUE) = TRUE + AND NOT pm.code <=>'previousBalance' + UNION ALL + SELECT se.companyFk, se.supplierFk, - se.amount, 0 + FROM supplierExpense se + WHERE se.dated BETWEEN vDateFrom AND vDateTo + AND IF(vIsConciliated, se.isConciliated, TRUE) = TRUE + UNION ALL + SELECT xd.empresa_id, s.id, 0, ROUND(NZ(Eurodebe)-NZ(Eurohaber),2) + FROM bi.XDiario_ALL xd + JOIN supplier s ON s.account = xd.SUBCTA + WHERE xd.Fecha BETWEEN vDateFrom AND vDateTo + ) sub + GROUP BY companyFk, supplierFk + ) sub1 ON sub1.supplierFk = s.id + JOIN company c ON c.id = sub1.companyFk + HAVING ABS(difference) > 0.05 + ORDER BY s.name; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -66605,7 +67936,7 @@ BEGIN WHERE s.ticketFk = vTicketOld GROUP BY s.itemFk; CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddress, vAgencyMode, vWarehouse); + CALL catalog_componentCalculate(vZoneFk, vAddress, vShipped, vWarehouse); -- Bionizamos lineas con Preu = 0 DROP TEMPORARY TABLE IF EXISTS tmp.sale; @@ -67123,7 +68454,36 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosure` */; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureAgencyListAdd` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 `ticketClosureAgencyListAdd`(vAgencyModeFk INT) +BEGIN +/** + * Prepara un listado de agencias sobre los que se realizará el cierre. + * Es necesario llamar al procedimiento por cada agencia. + * + * @param vAgencyModeFk Id almacén + */ + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.ticketClosureAgencyList ( + `agencyModeFk` INT, + PRIMARY KEY(agencyModeFk)) ENGINE = MEMORY; + + INSERT INTO tmp.ticketClosureAgencyList(agencyModeFk) VALUES(vAgencyModeFk); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureAgencyList__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -67133,7 +68493,300 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosure`() +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureAgencyList__`(vWarehouseFk INT, vDateTo DATE) +BEGIN +/** + * Inserta los tickets de todos los almacenes en la tabla temporal + * para ser cerrados. + * + * @param vWarehouseFk Id del almacén + * @param vDate Fecha del cierre + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + INNER JOIN ticket t ON t.id = e.ticketFk + INNER JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + WHERE + ts.alertLevel = 2 + AND t.warehouseFk = vWarehouseFk + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + DROP TEMPORARY TABLE tmp.ticketClosureAgencyList; + + CALL ticketClosure(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureMultiWarehouse__` */; +/*!50003 SET @saved_cs_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 `ticketClosureMultiWarehouse__`(vDateTo DATE) +BEGIN +/** + * Inserta los tickets de todos los almacenes en la tabla temporal + * para ser cerrados. + * + * @param vDate Fecha del cierre + */ + DECLARE vDateToEndDay DATETIME DEFAULT util.dayEnd(vDateTo); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + INNER JOIN ticket t ON t.id = e.ticketFk + INNER JOIN warehouse w ON w.id = t.warehouseFk AND hasComission + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + WHERE + ts.alertLevel = 2 + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticketClosure(); + + INSERT INTO mail (sender, replyTo, subject, body) + SELECT 'jgallego@verdnatura.es', 'jgallego@verdnatura.es', 'Tickets enrutados y NO preparados', + GROUP_CONCAT(ticketFk) tickets + FROM ticket t + JOIN ticketState ts ON t.id = ts.ticketFk + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE shipped BETWEEN vDateTo AND vDateToEndDay + AND al.code NOT IN('DELIVERED','PACKED') + AND t.routeFk + HAVING tickets IS NOT NULL; + + DROP TEMPORARY TABLE tmp.ticketClosure; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureMultiWarehouse__2` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureMultiWarehouse__2`(vDateTo DATE) +BEGIN +/** + * Inserta los tickets de todos los almacenes en la tabla temporal + * para ser cerrados. + * + * @param vDate Fecha del cierre + */ + DECLARE vDateToEndDay DATETIME DEFAULT util.dayEnd(vDateTo); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + INNER JOIN ticket t ON t.id = e.ticketFk + INNER JOIN warehouse w ON w.id = t.warehouseFk AND hasComission + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + WHERE + ts.alertLevel = 2 + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticketClosure(); + + -- cau 15033 + UPDATE ticket t + JOIN ticketState ts ON t.id = ts.ticketFk + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN zone z ON z.id = t.zoneFk + SET t.routeFk = NULL + WHERE shipped BETWEEN vDateTo AND vDateToEndDay + AND al.code NOT IN('DELIVERED','PACKED') + AND t.routeFk + AND z.`name` LIKE '%MADRID%'; + + DROP TEMPORARY TABLE tmp.ticketClosure; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureRoute__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureRoute__`( vRouteFk INT) +BEGIN +/** + * Inserta los tickets de la ruta en la tabla temporal + * para ser cerrados. + * + * @param vWarehouseFk Almacén a cerrar + * @param vRouteFk Ruta a cerrar + * @param vDate Fecha del cierre + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + INNER JOIN ticket t ON t.id = e.ticketFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + WHERE + ts.alertLevel = 2 + AND t.routeFk = vRouteFk + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticketClosure(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureTicket__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureTicket__`(vTicketFk INT) +BEGIN + +/** + * @deprecated Use ticket_closeByTicket() + * Inserta el ticket en la tabla temporal + * para ser cerrado. + * + * @param vTicketFk Id del ticket + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + INNER JOIN ticket t ON t.id = e.ticketFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + WHERE + ts.alertLevel = 2 + AND t.id = vTicketFk + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticketClosure(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureWarehouse__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureWarehouse__`(vWarehouseFk INT, vDateTo DATE) +BEGIN +/** + * Inserta los tickets del almacen en la tabla temporal + * para ser cerrados. + * + * @param vWarehouseFk Almacén a cerrar + * @param vDate Fecha del cierre + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE ticketClosure ENGINE = MEMORY( + SELECT + t.id AS ticketFk + FROM expedition e + INNER JOIN ticket t ON t.id = e.ticketFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + WHERE + ts.alertLevel = 2 + AND t.warehouseFk = vWarehouseFk + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticketClosure(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketClosure__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosure__`() BEGIN /** * @deprecated Use ticket_close() @@ -67253,328 +68906,6 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureAgencyList` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 `ticketClosureAgencyList`(vWarehouseFk INT, vDateTo DATE) -BEGIN -/** - * Inserta los tickets de todos los almacenes en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Id del almacén - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - INNER JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.warehouseFk = vWarehouseFk - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - DROP TEMPORARY TABLE tmp.ticketClosureAgencyList; - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureAgencyListAdd` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 `ticketClosureAgencyListAdd`(vAgencyModeFk INT) -BEGIN -/** - * Prepara un listado de agencias sobre los que se realizará el cierre. - * Es necesario llamar al procedimiento por cada agencia. - * - * @param vAgencyModeFk Id almacén - */ - CREATE TEMPORARY TABLE IF NOT EXISTS tmp.ticketClosureAgencyList ( - `agencyModeFk` INT, - PRIMARY KEY(agencyModeFk)) ENGINE = MEMORY; - - INSERT INTO tmp.ticketClosureAgencyList(agencyModeFk) VALUES(vAgencyModeFk); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureMultiWarehouse` */; -/*!50003 SET @saved_cs_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 `ticketClosureMultiWarehouse`(vDateTo DATE) -BEGIN -/** - * Inserta los tickets de todos los almacenes en la tabla temporal - * para ser cerrados. - * - * @param vDate Fecha del cierre - */ - DECLARE vDateToEndDay DATETIME DEFAULT util.dayEnd(vDateTo); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - INNER JOIN warehouse w ON w.id = t.warehouseFk AND hasComission - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - -- cau 15033 - UPDATE ticket t - JOIN ticketState ts ON t.id = ts.ticketFk - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - JOIN zone z ON z.id = t.zoneFk - SET t.routeFk = NULL - WHERE shipped BETWEEN vDateTo AND vDateToEndDay - AND al.code NOT IN('DELIVERED','PACKED') - AND t.routeFk - AND z.`name` LIKE '%MADRID%'; - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureMultiWarehouse__` */; -/*!50003 SET @saved_cs_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 `ticketClosureMultiWarehouse__`(vDateTo DATE) -BEGIN -/** - * Inserta los tickets de todos los almacenes en la tabla temporal - * para ser cerrados. - * - * @param vDate Fecha del cierre - */ - DECLARE vDateToEndDay DATETIME DEFAULT util.dayEnd(vDateTo); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - INNER JOIN warehouse w ON w.id = t.warehouseFk AND hasComission - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - INSERT INTO mail (sender, replyTo, subject, body) - SELECT 'jgallego@verdnatura.es', 'jgallego@verdnatura.es', 'Tickets enrutados y NO preparados', - GROUP_CONCAT(ticketFk) tickets - FROM ticket t - JOIN ticketState ts ON t.id = ts.ticketFk - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE shipped BETWEEN vDateTo AND vDateToEndDay - AND al.code NOT IN('DELIVERED','PACKED') - AND t.routeFk - HAVING tickets IS NOT NULL; - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureRoute` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 `ticketClosureRoute`( vRouteFk INT) -BEGIN -/** - * Inserta los tickets de la ruta en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Almacén a cerrar - * @param vRouteFk Ruta a cerrar - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.routeFk = vRouteFk - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureTicket` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureTicket`(vTicketFk INT) -BEGIN - -/** - * @deprecated Use ticket_closeByTicket() - * Inserta el ticket en la tabla temporal - * para ser cerrado. - * - * @param vTicketFk Id del ticket - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.id = vTicketFk - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureWarehouse` */; -/*!50003 SET @saved_cs_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 `ticketClosureWarehouse`(vWarehouseFk INT, vDateTo DATE) -BEGIN -/** - * Inserta los tickets del almacen en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Almacén a cerrar - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE ticketClosure ENGINE = MEMORY( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.warehouseFk = vWarehouseFk - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCollection_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68353,7 +69684,205 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`(vIsTodayRelative BOOLEAN) +CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`(IN vIsTodayRelative TINYINT(1)) +BEGIN +/** + * Hay una versión en salix que machacará toda esta función/procedimiento avisa + * a joan de los cambios que quieres hacer. + * + */ + DECLARE vWarehouse INT; + DECLARE vDate DATE; + DECLARE vAvailableCache INT; + DECLARE vDone INT DEFAULT 0; + DECLARE vComponentCount INT; + + DECLARE vCursor CURSOR FOR + SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, CURDATE(), date(tt.shipped)) + FROM tmp.ticketGetProblems tt + WHERE DATE(tt.shipped) BETWEEN CURDATE() + AND TIMESTAMPADD(DAY, IF(vIsTodayRelative, 9.9, 1.9), CURDATE()); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems; + CREATE TEMPORARY TABLE tmp.ticketProblems ( + ticketFk INT(11) PRIMARY KEY, + isFreezed INTEGER(1) DEFAULT 0, + risk DECIMAL(10,2) DEFAULT 0, + hasTicketRequest INTEGER(1) DEFAULT 0, + isAvailable INTEGER(1) DEFAULT 1, + itemShortage VARCHAR(250), + isTaxDataChecked INTEGER(1) DEFAULT 1, + itemDelay VARCHAR(250), + componentLack INTEGER(1) + ) ENGINE = MEMORY; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketList; + CREATE TEMPORARY TABLE tmp.ticketList + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT tp.ticketFk, c.id clientFk + FROM tmp.ticketGetProblems tp + JOIN vn.client c ON c.id = tp.clientFk; + + SELECT COUNT(*) INTO vComponentCount + FROM vn.component c + WHERE c.isRequired; + + INSERT INTO tmp.ticketProblems(ticketFk, componentLack) + SELECT tl.ticketFk, (COUNT(DISTINCT s.id) * vComponentCount > COUNT(c.id)) + FROM tmp.ticketList tl + JOIN vn.sale s ON s.ticketFk = tl.ticketFk + LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id + LEFT JOIN vn.component c ON c.id = sc.componentFk AND c.isRequired + GROUP BY tl.ticketFk; + + INSERT INTO tmp.ticketProblems(ticketFk, isFreezed) + SELECT DISTINCT tl.ticketFk, 1 + FROM tmp.ticketList tl + JOIN vn.client c ON c.id = tl.clientFk + WHERE c.isFreezed + ON DUPLICATE KEY UPDATE + isFreezed = c.isFreezed; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + (PRIMARY KEY (clientFk)) + ENGINE = MEMORY + SELECT DISTINCT clientFk + FROM tmp.ticketList; + + CALL clientGetDebt(CURDATE()); + + INSERT INTO tmp.ticketProblems(ticketFk, risk) + SELECT DISTINCT tl.ticketFk, r.risk + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.agencyMode a ON t.agencyModeFk = a.id + JOIN tmp.risk r ON r.clientFk = t.clientFk + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.clientConfig cc + WHERE r.risk - cc.riskTolerance > c.credit + 10 + AND a.isRiskFree = FALSE + ON DUPLICATE KEY UPDATE + risk = r.risk; + + INSERT INTO tmp.ticketProblems(ticketFk, hasTicketRequest) + SELECT DISTINCT tl.ticketFk, 1 + FROM tmp.ticketList tl + JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk + WHERE tr.isOK IS NULL AND tr.saleFk IS NOT NULL + ON DUPLICATE KEY UPDATE + hasTicketRequest = 1; + + OPEN vCursor; + + WHILE NOT vDone + DO + FETCH vCursor INTO vWarehouse, vDate; + + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); + + INSERT INTO tmp.ticketProblems(ticketFk, isAvailable) + SELECT tl.ticketFk, 0 + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + WHERE date(t.shipped) = vDate + AND it.categoryFk != 6 + AND IFNULL(av.available, 0) < 0 + AND s.isPicked = FALSE + AND NOT i.generic + AND vWarehouse = t.warehouseFk + GROUP BY tl.ticketFk + ON DUPLICATE KEY UPDATE + isAvailable = 0; +/* + INSERT INTO tmp.ticketProblems(ticketFk, itemShortage) + SELECT ticketFk, problem + FROM ( + SELECT tl.ticketFk, CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache + WHERE IFNULL(av.available, 0) < 0 + AND s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND it.categoryFk != 6 + AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) + AND NOT i.generic + AND CURDATE() = vDate + AND t.warehouseFk = vWarehouse + GROUP BY tl.ticketFk LIMIT 1) sub + ON DUPLICATE KEY UPDATE + itemShortage = sub.problem; +*/ + INSERT INTO tmp.ticketProblems(ticketFk, itemDelay) + SELECT ticketFk, problem + FROM ( + SELECT tl.ticketFk, GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' ') problem + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + WHERE s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND it.categoryFk != 6 + AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) + AND NOT i.generic + AND CURDATE() = vDate + AND t.warehouseFk = vWarehouse + GROUP BY tl.ticketFk LIMIT 1) sub + ON DUPLICATE KEY UPDATE + itemDelay = sub.problem; + END WHILE; + + CLOSE vCursor; + + INSERT INTO tmp.ticketProblems(ticketFk, isTaxDataChecked) + SELECT DISTINCT tl.ticketFk, FALSE + FROM tmp.ticketList tl + JOIN vn.client c ON c.id = tl.clientFk + WHERE c.isTaxDataChecked= FALSE + ON DUPLICATE KEY UPDATE + isTaxDataChecked = FALSE; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.ticketList; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketGetProblems__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 `ticketGetProblems__`(vIsTodayRelative BOOLEAN) BEGIN DECLARE vWarehouse INT; @@ -68515,188 +70044,6 @@ BEGIN tmp.clientGetDebt, tmp.ticketList; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketGetProblems__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 `ticketGetProblems__`() -BEGIN - - DECLARE vWarehouse INT; - DECLARE vDate DATE; - DECLARE vAvailableCache INT; - DECLARE vVisibleCache INT; - DECLARE vDone INT DEFAULT 0; - - DECLARE vCursor CURSOR FOR - SELECT DISTINCT tt.warehouseFk, date(tt.shipped) - FROM tmp.ticketGetProblems tt - WHERE DATE(tt.shipped) BETWEEN CURDATE() - AND TIMESTAMPADD(DAY, 1.9, CURDATE()); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems; - CREATE TEMPORARY TABLE tmp.ticketProblems ( - ticketFk INT(11) PRIMARY KEY, - isFreezed INTEGER(1) DEFAULT 0, - risk DECIMAL(10,2) DEFAULT 0, - hasTicketRequest INTEGER(1) DEFAULT 0, - isAvailable INTEGER(1) DEFAULT 1, - itemShortage VARCHAR(250), - isTaxDataChecked INTEGER(1) DEFAULT 1, - itemDelay VARCHAR(250) - ) ENGINE = MEMORY; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketList; - CREATE TEMPORARY TABLE tmp.ticketList - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT tp.ticketFk, c.id clientFk - FROM tmp.ticketGetProblems tp - JOIN vn.client c ON c.id = tp.clientFk; - - INSERT INTO tmp.ticketProblems(ticketFk, isFreezed) - SELECT DISTINCT tl.ticketFk, 1 - FROM tmp.ticketList tl - JOIN vn.client c ON c.id = tl.clientFk - WHERE c.isFreezed; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - (PRIMARY KEY (clientFk)) - ENGINE = MEMORY - SELECT DISTINCT clientFk - FROM tmp.ticketList; - - CALL clientGetDebt(CURDATE()); - - INSERT INTO tmp.ticketProblems(ticketFk, risk) - SELECT DISTINCT tl.ticketFk, r.risk - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.agencyMode a ON t.agencyModeFk = a.id - JOIN tmp.risk r ON r.clientFk = t.clientFk - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.clientConfig cc - WHERE r.risk - cc.riskTolerance > c.credit + 10 - AND a.isRiskFree = FALSE - ON DUPLICATE KEY UPDATE - risk = r.risk; - - INSERT INTO tmp.ticketProblems(ticketFk, hasTicketRequest) - SELECT DISTINCT tl.ticketFk, 1 - FROM tmp.ticketList tl - JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk - WHERE tr.isOK IS NULL AND tr.saleFk IS NOT NULL - ON DUPLICATE KEY UPDATE - hasTicketRequest = 1; - - OPEN vCursor; - - WHILE NOT vDone - DO - FETCH vCursor INTO vWarehouse, vDate; - - CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouse); - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); - - INSERT INTO tmp.ticketProblems(ticketFk, isAvailable) - SELECT tl.ticketFk, 0 - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - WHERE date(t.shipped) = vDate - AND it.categoryFk != 6 - AND IFNULL(av.available, 0) < 0 - AND s.isPicked = FALSE - AND NOT i.generic - AND vWarehouse = t.warehouseFk - GROUP BY tl.ticketFk - ON DUPLICATE KEY UPDATE - isAvailable = 0; - - INSERT INTO tmp.ticketProblems(ticketFk, itemShortage) - SELECT ticketFk, problem - FROM ( - SELECT tl.ticketFk, CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN cache.visible v ON i.id = v.item_id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - WHERE IFNULL(av.available, 0) < 0 - AND s.quantity > IFNULL(v.visible, 0) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND date(t.shipped) = vDate - AND NOT i.generic - AND CURDATE() = vDate - AND t.warehouseFk = vWarehouse - GROUP BY tl.ticketFk) sub - ON DUPLICATE KEY UPDATE - itemShortage = sub.problem; - - INSERT INTO tmp.ticketProblems(ticketFk, itemDelay) - SELECT ticketFk, problem - FROM ( - SELECT tl.ticketFk, CONCAT('R: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN cache.visible v ON i.id = v.item_id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - WHERE IFNULL(av.available, 0) >= 0 - AND s.quantity > IFNULL(v.visible, 0) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND date(t.shipped) = vDate - AND NOT i.generic - AND CURDATE() = vDate - AND t.warehouseFk = vWarehouse - GROUP BY tl.ticketFk) sub - ON DUPLICATE KEY UPDATE - itemDelay = sub.problem; - END WHILE; - - CLOSE vCursor; - - INSERT INTO tmp.ticketProblems(ticketFk, isTaxDataChecked) - SELECT DISTINCT tl.ticketFk, FALSE - FROM tmp.ticketList tl - JOIN vn.client c ON c.id = tl.clientFk - WHERE c.isTaxDataChecked= FALSE - ON DUPLICATE KEY UPDATE - isTaxDataChecked = FALSE; - - DROP TEMPORARY TABLE - tmp.clientGetDebt, - tmp.ticketList; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69720,7 +71067,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticketToPrePrepare`(IN vIdTicket INT, IN viewAll BOOL, IN vSectorFk INT) BEGIN @@ -69789,12 +71136,8 @@ IF viewAll IS true THEN AND s.code = 'PREVIOUS_PREPARATION' ORDER BY p.pickingOrder, p.column ASC; - END IF;/* -ELSE - SELECT * - FROM vn.ticketToPrepare ttp - WHERE ttp.Id_Ticket = vIdTicket; -*/ + END IF; + END IF; END ;; DELIMITER ; @@ -70065,6 +71408,38 @@ BEGIN AND t.shipped BETWEEN vDateStart AND vDateEnd GROUP BY s.ticketFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticket_administrativeCopy` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT) +BEGIN + + INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) + SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed + FROM vn.ticket t + JOIN vn.warehouse w ON w.name = 'INVENTARIO' + WHERE t.id = vOriginalTicket; + + SELECT LAST_INSERT_ID() INTO vNewTicket; + + INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) + SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount + FROM vn.sale s + WHERE s.ticketFk = vOriginalTicket; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70153,9 +71528,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -70176,7 +71551,9 @@ BEGIN zoneFk, zonePrice, zoneBonus, - routeFk + routeFk, + priority, + hasPriority ) SELECT clientFk, @@ -70190,7 +71567,9 @@ BEGIN zoneFk, zonePrice, zoneBonus, - routeFk + routeFk, + priority, + hasPriority FROM ticket WHERE id = vOriginalTicket; @@ -70211,9 +71590,6 @@ BEGIN FROM vncontrol.inter WHERE Id_Ticket = vOriginalTicket ORDER BY odbc_date; - - - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70789,7 +72165,7 @@ BEGIN AND t.refFk IS NULL GROUP BY e.ticketFk); - CALL ticket_close(); + CALL ticket_close(vTicketFk); DROP TEMPORARY TABLE tmp.ticketClosure; END ;; @@ -70806,23 +72182,18 @@ DELIMITER ; /*!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 sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_componentMakeUpdate`( - vTicketFk INT, - vClientFk INT, - vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, - vWarehouseFk TINYINT, - vCompanyFk SMALLINT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption INT) +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_componentMakeUpdate`(IN vTicketFk INT, IN vClientFk INT, IN vAgencyModeFk INT, + IN vAddressFk INT, IN vZoneFk INT, IN vWarehouseFk TINYINT, + IN vCompanyFk SMALLINT, IN vShipped DATETIME, + IN vLanded DATE, IN vIsDeleted TINYINT(1), + IN vHasToBeUnrouted TINYINT(1), IN vOption INT) BEGIN /** + * Hay una versión en salix que machacará toda esta función/procedimiento avisa + * a carlosjr de los cambios que quieres hacer. + * * Modifica en el ticket los campos que se le pasan por parámetro * y cambia sus componentes * @@ -71238,6 +72609,124 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticket_DelayTruck` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_DelayTruck`(vWarehouserFk INT, vHour INT, vMinute INT) +BEGIN + + DECLARE done INT DEFAULT FALSE; + DECLARE vTicketFk INT; + DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + CALL vn.productionControl(vWarehouserFk,0) ; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT ticketFk + FROM tmp.productionBuffer + WHERE shipped = curdate() + AND problem LIKE '%I:%' + AND (HH <= vHour OR HH = vHour AND mm < vMinute) + AND alertLevel = 0; + + OPEN cur1; + + read_loop: LOOP + + FETCH cur1 INTO vTicketFk; + + IF done THEN + LEAVE read_loop; + END IF; + + CALL vn.ticket_DelayTruckSplit(vTicketFk); + + END LOOP; + + CLOSE cur1; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticket_DelayTruckSplit` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_DelayTruckSplit`(vTicketFk INT) +BEGIN + + /* + * Splita las lineas de ticket que no estan ubicadas + * + */ + + DECLARE vNewTicketFk INT; + DECLARE vTotalLines INT; + DECLARE vLinesToSplit INT; + + DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit; + + SELECT COUNT(*) INTO vTotalLines + FROM vn.sale + WHERE ticketFk = vTicketFk; + + CREATE TEMPORARY TABLE tmp.SalesToSplit + SELECT s.id saleFk + FROM vn.ticket t + JOIN vn.sale s ON t.id = s.ticketFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = s.itemFk AND issw.warehouseFk = t.warehouseFk + WHERE s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND t.id = vTicketFk; + + SELECT COUNT(*) INTO vLinesToSplit + FROM tmp.SalesToSplit; + + IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN + + SET vNewTicketFk = vTicketFk; + + ELSE + + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); + + UPDATE vn.sale s + JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id + SET s.ticketFk = vNewTicketFk; + + END IF; + + CALL vn.ticketStateUpdate(vNewTicketFk, 'FIXING'); + + DROP TEMPORARY TABLE tmp.SalesToSplit; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -72049,6 +73538,61 @@ BEGIN 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 `ticket_splitPackingComplete` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_splitPackingComplete`(vTicketFk INT, vSectorFk INT) +BEGIN + + DECLARE vNeedToSplit BOOLEAN; + DECLARE vNewTicketFk INT; + + DROP TEMPORARY TABLE IF EXISTS tmpSale; + + CREATE TEMPORARY TABLE tmpSale + SELECT DISTINCT s.id + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = vSectorFk + JOIN vn.packagingConfig pc + WHERE t.id = vTicketFk + AND ( s.quantity MOD IFNULL(iss.packing,1) != 0 + OR + IFNULL(iss.packing,1) = 1 + OR + i.`size` <= pc.previousPreparationMinimumSize + ); + + SELECT COUNT(*) + INTO vNeedToSplit + FROM tmpSale; + + IF vNeedToSplit THEN + + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); + + UPDATE vn.sale s + JOIN vn.tmpSale ts ON ts.id = s.id + SET s.ticketFk = vNewTicketFk; + + END IF; + + DROP TEMPORARY TABLE tmpSale; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72808,6 +74352,38 @@ BEGIN JOIN vn.itemType it ON it.id = i.typeFk WHERE tr.id = vTravelFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `travelVolume_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 `travelVolume_get`(vFromDated DATE, vToDated DATE, vWarehouseFk INT) +BEGIN + + SELECT tr.landed Fecha, + a.name Agencia, + count(DISTINCT e.id) numEntradas, + FLOOR(sum(item_getVolume(b.itemFk, b.packageFk) * b.stickers / 1000000 )) AS m3 + FROM vn.travel tr + JOIN vn.agencyMode a ON a.id = tr.agencyFk + JOIN vn.entry e ON e.travelFk = tr.id + JOIN vn.buy b ON b.entryFk = e.id + WHERE tr.landed BETWEEN vFromDated AND vToDated + AND e.isRaid = FALSE + AND tr.warehouseInFk = vWarehouseFk + GROUP BY tr.landed , a.name ; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76469,6 +78045,278 @@ BEGIN */ DROP TEMPORARY TABLE IF EXISTS tmp.workerSalaryRoleDelivery; + CREATE TEMPORARY TABLE tmp.workerSalaryRoleDelivery + SELECT w.id workerFk, + r.created dated, + r.id, + SUM(t.packages) packages, + CAST(time_to_sec(TIMEDIFF( DATE_FORMAT(r.finished, '%H:%i:%s'),DATE_FORMAT(r.time, '%H:%i:%s'))) / (60 * 60) AS DECIMAL(10, 1)) hours , + r.kmEnd-r.kmStart km, + r.m3 m3Delivery, + CAST(r.m3/loadWorker AS DECIMAL(10,2)) m3Load, + CAST(rc.m3Distribution*m3 AS DECIMAL(10,2)) amountDelivery, + CASE loadWorker + WHEN 1 THEN CAST(r.m3/ loadWorker*rc.load1m3 AS DECIMAL(10,2)) + WHEN 2 THEN CAST(r.m3/ loadWorker*rc.load2m3 AS DECIMAL(10,2)) + WHEN 3 THEN CAST(r.m3/ loadWorker*rc.load3m3 AS DECIMAL(10,2)) + WHEN 4 THEN CAST(r.m3/ loadWorker*rc.load4m3 AS DECIMAL(10,2)) + WHEN 5 THEN CAST(r.m3/ loadWorker*rc.load5m3 AS DECIMAL(10,2)) + ELSE CAST(r.m3/ loadWorker*rc.load6m3 AS DECIMAL(10,2)) + END amountLoad, + rc.kmRate*(r.kmEnd-r.kmStart) amountKm, + CAST('' AS CHAR(45)) description, + CAST( 0 AS DECIMAL(10,2)) extra, + CAST( 0 AS DECIMAL(10,2)) maxSalary + FROM ticket t + LEFT JOIN route r ON t.routeFk = r.id + LEFT JOIN worker w ON w.id = r.workerFk + LEFT JOIN routeConfig rc ON TRUE + LEFT JOIN (SELECT rw.routeFk, COUNT(rw.workerFk) loadWorker + FROM routeLoadWorker rw + JOIN routeLoadWorker rw2 ON rw.routeFk = rw2.routeFk AND rw2.workerFk = vWorkerFk + GROUP BY rw2.routeFk + ) sub ON sub.routeFk=r.id + WHERE r.created BETWEEN vDateFrom AND vDateTo AND w.id = vWorkerFk + GROUP BY r.id; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + id, + packages, + km, + m3Load, + amountLoad) + SELECT w.id , + r.created , + r.id, + SUM(t.packages) , + r.kmEnd-r.kmStart , + CAST(r.m3/loadWorker AS DECIMAL(10,2)) , + CASE loadWorker + WHEN 1 THEN CAST(r.m3/ loadWorker*rc.load1m3 AS DECIMAL(10,2)) + WHEN 2 THEN CAST(r.m3/ loadWorker*rc.load2m3 AS DECIMAL(10,2)) + WHEN 3 THEN CAST(r.m3/ loadWorker*rc.load3m3 AS DECIMAL(10,2)) + WHEN 4 THEN CAST(r.m3/ loadWorker*rc.load4m3 AS DECIMAL(10,2)) + WHEN 5 THEN CAST(r.m3/ loadWorker*rc.load5m3 AS DECIMAL(10,2)) + ELSE CAST(r.m3/ loadWorker*rc.load6m3 AS DECIMAL(10,2)) + END + FROM (SELECT rw.routeFk, COUNT(rw.workerFk) loadWorker + FROM routeLoadWorker rw + JOIN routeLoadWorker rw2 ON rw.routeFk = rw2.routeFk AND rw2.workerFk = vWorkerFk + GROUP BY rw2.routeFk) sub + LEFT JOIN route r ON sub.routeFk = r.id + LEFT JOIN ticket t ON t.routeFk = r.id + LEFT JOIN worker w ON w.id = r.workerFk + LEFT JOIN routeConfig rc ON TRUE + WHERE r.created BETWEEN vDateFrom AND vDateTo AND w.id <> vWorkerFk + GROUP BY r.id; + + INSERT INTO tmp.workerSalaryRoleDelivery(workerFk, + dated, + description, + extra) + SELECT workerFk, + dated, + GROUP_CONCAT(ra.name) , + CAST(SUM(rc.price) AS DECIMAL(9,2)) + FROM routeComplement rc + JOIN routeAction ra ON rc.routeActionFk=ra.id + WHERE dated BETWEEN vDateFrom AND vDateTo AND workerFk=vWorkerFk + GROUP BY dated; + + CALL timeBusiness_calculateByWorker(vWorkerFk, vDateFrom, vDateTo); + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + description, + extra) + SELECT w.id, + tb.dated, + tb.type COLLATE utf8_general_ci, + CASE + WHEN tb.type = 'Vacaciones 1/2 día' OR tb.type = 'Permiso retribuido 1/2 día' + THEN CAST(((12 * blp.importepactado) / (52 * tb.hoursWeek)) * 4 AS DECIMAL(10,2)) + WHEN tb.type = 'Vacaciones' OR tb.type = 'Baja enfermedad común' OR tb.type = 'Permiso retribuido' OR tb.type = 'Festivo' + THEN CAST(((12 * blp.importepactado) / (52 * tb.hoursWeek)) * 8 AS DECIMAL(10,2)) + END + FROM worker w + JOIN tmp.timeBusinessCalculate tb ON tb.userFk = w.id + JOIN postgresql.business_labour_payroll blp ON blp.business_id = tb.businessFk + JOIN time tm ON tm.dated = tb.dated + WHERE tb.dated BETWEEN vDateFrom AND vDateTo AND + w.id = vWorkerFk AND + tb.type IN ('Vacaciones 1/2 día', 'Vacaciones', 'Baja enfermedad común','Festivo','Permiso retribuido 1/2 día','Permiso retribuido') + GROUP BY tb.dated; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + m3Delivery, + amountLoad, + description) + SELECT wdc.workerFk , + r.created, + SUM(r.m3) , + CASE + WHEN wdc.category = 1 + THEN CAST(SUM(r.m3) * rc.distributionM3Category1 AS DECIMAL (10,2)) + WHEN wdc.category = 2 + THEN CAST(SUM(r.m3) * rc.distributionM3Category2 AS DECIMAL (10,2)) + END amountLoad, + 'Gestión de la distribución' description + FROM route r + JOIN agencyMode am ON am.id= r.agencyModeFk + JOIN agency a ON a.id = am.agencyFk + JOIN workerDistributionCategory wdc ON wdc.workerFk = vWorkerFk + JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, CURDATE()) AND wl.workerFk = wdc.workerFk AND a.workCenterFk = wl.workCenterFk + JOIN department v ON v.id = departmentFk + JOIN routeConfig rc + WHERE r.m3>0 AND created BETWEEN vDateFrom AND vDateTo AND + am.name NOT LIKE "REC_%" AND + v.name= "REPARTO" + GROUP BY r.created; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + m3Delivery, + amountLoad, + description) + SELECT sub.workerFk, + r.created, + SUM(r.m3), + CAST( (SUM(r.m3)*sub.percentage /100) * rc.m3Palletization AS DECIMAL (10,2) ), + 'Gestión de paletizado' + FROM route r + JOIN agencyMode am ON am.id= r.agencyModeFk + JOIN agency a ON a.id = am.agencyFk + JOIN (SELECT percentage,workerFk ,dated + FROM routeUserPercentage ru + WHERE workerFk = vWorkerFk AND ru.dated <= vDateTo + ORDER BY dated DESC LIMIT 1 + ) sub + JOIN routeConfig rc + JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, CURDATE()) AND + wl.workerFk = sub.workerFk + JOIN department v ON v.id = departmentFk + WHERE r.m3>0 AND + r.created BETWEEN vDateFrom AND vDateTo AND + am.name NOT LIKE "REC_%" AND + v.name= "PALETIZADO" + GROUP BY r.created; + + DROP TEMPORARY TABLE IF EXISTS tmp.daysToRateHoliday; + CREATE TEMPORARY TABLE tmp.daysToRateHoliday + SELECT * + FROM tmp.workerSalaryRoleDelivery tb + WHERE (tb.description IN ('Festivo') OR dayofweek(tb.dated)=1) AND tb.extra = 0 ; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk,dated,id,packages,hours,km,m3Delivery,m3Load,amountDelivery,amountLoad,AmountKm,description, extra) + SELECT workerFk, + dated, + d.id, + packages, + hours, + km, + m3Delivery, + m3Load, + amountDelivery * r.rateHoliday, + amountLoad * r.rateHoliday, + AmountKm * r.rateHoliday, + CONCAT('Plus festivo: ',description), + extra + FROM tmp.daysToRateHoliday d + LEFT JOIN routeConfig r ON TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.daysToDelete; + CREATE TEMPORARY TABLE tmp.daysToDelete + SELECT dated + FROM tmp.workerSalaryRoleDelivery d + WHERE d.description IN ('Baja enfermedad común'); + + DELETE d + FROM tmp.workerSalaryRoleDelivery d + JOIN tmp.daysToDelete dd on dd.dated = d.dated + WHERE d.description NOT IN ('Baja enfermedad común'); + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk,dated,id,packages,hours,km,m3Delivery,m3Load,amountDelivery,amountLoad,AmountKm,description, extra) + SELECT workerFk, + dated, + d.id, + packages, + hours, + km, + m3Delivery, + m3Load, + amountDelivery * r.rateHoliday, + amountLoad * r.rateHoliday, + AmountKm * r.rateHoliday, + CONCAT('Plus festivo: ', description), + extra + FROM tmp.daysToRateHoliday d + LEFT JOIN routeConfig r ON TRUE; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + description, + extra, + maxSalary) + SELECT wdc.workerFk , + CONCAT(YEAR(t.dated),'-', MONTH(t.dated),'-01') , + CASE + WHEN wdc.category = 1 + THEN rc.plusCategory1Concept + WHEN wdc.category = 2 + THEN rc.plusCategory2Concept + END, + CASE + WHEN wdc.category = 1 + THEN CAST(rc.plusCategory1 AS DECIMAL (10,2)) + WHEN wdc.category = 2 + THEN CAST(rc.plusCategory2 AS DECIMAL (10,2)) + END, + CASE + WHEN wdc.category = 1 + THEN CAST(rc.maxSalaryCategory1 AS DECIMAL (10,2)) + WHEN wdc.category = 2 + THEN CAST(rc.maxSalaryCategory2 AS DECIMAL (10,2)) + END + FROM worker w + JOIN workerDistributionCategory wdc ON wdc.workerFk = w.id + JOIN routeConfig rc + JOIN time t on t.dated BETWEEN vDateFrom AND vDateTo + WHERE w.id = vWorkerFk + GROUP BY MONTH(t.dated), YEAR(t.dated); + + DROP TEMPORARY TABLE tmp.daysToRateHoliday; + DROP TEMPORARY TABLE tmp.daysToDelete; + DROP TEMPORARY TABLE tmp.timeBusinessCalculate; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `worker_calculateSalaryRoleDelivery__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `worker_calculateSalaryRoleDelivery__`(vWorkerFk INTEGER,vDateFrom DATE,vDateTo DATE) +BEGIN +/** + * Calcula el salario de trabajadores para los departamentos de reparto, paletizado + * + * @param vDateFrom + * @param vDateTo + * @param vWorkerFk + * @return tmp.workerSalaryRoleDelivery + */ + DROP TEMPORARY TABLE IF EXISTS tmp.workerSalaryRoleDelivery; + CREATE TEMPORARY TABLE tmp.workerSalaryRoleDelivery SELECT w.id workerFk, r.created dated, @@ -76813,9 +78661,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -76826,13 +78674,14 @@ BEGIN CREATE TEMPORARY TABLE tmp.total ENGINE = MEMORY - SELECT tt.workerFk, Count(tt.ticketFk) AS CuentaDeId_Ticket - FROM state s - JOIN ticketTracking tt ON s.id = tt.stateFk - JOIN ticket t ON tt.ticketFk = t.id - JOIN worker w ON tt.workerFk = w.id - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND s.code = vStateCode - GROUP BY tt.workerFk; + SELECT st.workerFk, Count(t.id) AS CuentaDeId_Ticket + FROM state ss + JOIN vn.saleTracking st ON st.stateFk = ss.id + JOIN vn.sale s ON s.id = st.saleFk + JOIN ticket t ON s.ticketFk = t.id + JOIN worker w ON st.workerFk = w.id + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND ss.code = vStateCode + GROUP BY st.workerFk; SELECT w.code, w.firstName, w.lastName, CAST(tmp.total.CuentaDeId_Ticket AS DECIMAL(10,0)) AS Totaltickets, CAST(sub.CuentaDeTicketFk AS DECIMAL(10,0)) AS Fallos FROM tmp.total @@ -77733,6 +79582,40 @@ proc: BEGIN CLOSE cCur; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zone_ETD_byTime` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zone_ETD_byTime`() +BEGIN + + SET @m := 0; + + DROP TEMPORARY TABLE IF EXISTS tmpZone; + CREATE TEMPORARY TABLE tmpZone + SELECT remainingVolume, + hourTheoretical, + @m := @m + minutesLess totalMinutes + FROM zoneEstimatedDelivery ze + WHERE ze.remainingVolume + ORDER BY ze.hourTheoretical DESC; + + SELECT * FROM tmpZone; + + DROP TABLE tmpZone; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -79439,6 +81322,25 @@ USE `bs`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `packingSpeed` +-- + +/*!50001 DROP TABLE IF EXISTS `packingSpeed`*/; +/*!50001 DROP VIEW IF EXISTS `packingSpeed`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `packingSpeed` AS select hour(`e`.`created`) AS `hora`,minute(`e`.`created`) AS `minuto`,ifnull(`p`.`volume`,((`p`.`width` * `p`.`height`) * `p`.`depth`)) AS `cm3`,`t`.`warehouseFk` AS `warehouse_id`,`e`.`created` AS `odbc_date` from ((`vn`.`expedition` `e` join `vn`.`packaging` `p` on((`p`.`id` = `e`.`packagingFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) where (`e`.`created` between curdate() and `util`.`dayend`(curdate())) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `v_ventas__` -- @@ -79489,6 +81391,25 @@ USE `cache`; USE `edi`; +-- +-- Final view structure for view `errorList` +-- + +/*!50001 DROP TABLE IF EXISTS `errorList`*/; +/*!50001 DROP VIEW IF EXISTS `errorList`*/; +/*!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 `errorList` AS select `po`.`id` AS `id`,`c`.`name` AS `name`,`i`.`longName` AS `longName`,`po`.`quantity` AS `quantity`,left(`po`.`error`,4) AS `stock`,`po`.`error` AS `error`,`po`.`deliveryInformationID` AS `deliveryInformationID`,`po`.`supplyResponseID` AS `supplyResponseID`,`po`.`OrderTradeLineDateTime` AS `OrderTradeLineDateTime`,`po`.`EndUserPartyGLN` AS `EndUserPartyGLN` from ((`edi`.`putOrder` `po` left join `vn`.`client` `c` on((`c`.`id` = `po`.`EndUserPartyGLN`))) left join `vn`.`item` `i` on((`i`.`supplyResponseFk` = `po`.`supplyResponseID`))) where ((`po`.`OrderTradeLineDateTime` > (curdate() + interval -(12) hour)) and (`po`.`OrderStatus` = 3) and (left(`po`.`error`,4) <> '(0) ')) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Current Database: `hedera` -- @@ -80034,7 +81955,7 @@ USE `sage`; /*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `invoiceInList` AS select `vn`.`invoiceIn`.`id` AS `id`,`vn`.`invoiceIn`.`supplierRef` AS `supplierRef`,`vn`.`invoiceIn`.`serial` AS `serial`,`vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`issued` AS `issued`,`vn`.`invoiceIn`.`isVatDeductible` AS `isVatDeductible`,`vn`.`invoiceIn`.`serialNumber` AS `serialNumber` from `vn`.`invoiceIn` where (`vn`.`invoiceIn`.`issued` >= (date_format(curdate(),'%Y-01-01') + interval -(1) year)) union all select `vn`.`dua`.`id` AS `id`,`vn`.`dua`.`code` AS `code`,'D' AS `D`,442 AS `442`,`vn`.`dua`.`issued` AS `issued`,0 AS `FALSE`,`vn`.`dua`.`id` AS `serialNumber` from `vn`.`dua` */; +/*!50001 VIEW `invoiceInList` AS select `vn`.`invoiceIn`.`id` AS `id`,`vn`.`invoiceIn`.`supplierRef` AS `supplierRef`,`vn`.`invoiceIn`.`serial` AS `serial`,`vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`issued` AS `issued`,if((`vn`.`invoiceIn`.`expenceFkDeductible` > 0),1,0) AS `isVatDeductible`,`vn`.`invoiceIn`.`serialNumber` AS `serialNumber` from `vn`.`invoiceIn` where (`vn`.`invoiceIn`.`issued` >= (date_format(curdate(),'%Y-01-01') + interval -(1) year)) union all select `vn`.`dua`.`id` AS `id`,`vn`.`dua`.`code` AS `code`,'D' AS `D`,`c`.`id` AS `supplierFk`,`vn`.`dua`.`issued` AS `issued`,0 AS `FALSE`,`vn`.`dua`.`id` AS `serialNumber` from (`vn`.`dua` join `vn`.`company` `c` on((`c`.`code` = 'VNL'))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80424,6 +82345,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `collectionSmartTag` +-- + +/*!50001 DROP TABLE IF EXISTS `collectionSmartTag`*/; +/*!50001 DROP VIEW IF EXISTS `collectionSmartTag`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `collectionSmartTag` AS select `st`.`code` AS `code`,`tc`.`ticketFk` AS `ticketFk`,`tc`.`level` AS `level`,`tc`.`wagon` AS `wagon`,`st`.`shelvingFk` AS `shelvingFk`,`tc`.`collectionFk` AS `collectionFk`,`am`.`name` AS `agencyFk`,`t`.`clientFk` AS `clientFk` from (((((`ticketCollection` `tc` join `smartTag` `st` on((`st`.`code` = (`tc`.`smartTagFk` collate utf8_general_ci)))) join `ticket` `t` on((`t`.`id` = `tc`.`ticketFk`))) join `collection` `c` on((`c`.`id` = `tc`.`collectionFk`))) join `worker` `w` on((`w`.`id` = `c`.`workerFk`))) join `agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `componentRate__` -- @@ -80685,7 +82625,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionCommon` AS select `et`.`id` AS `truckFk`,`et`.`ETD` AS `etd`,ifnull(ucase(`et`.`description`),'SIN ESCANEAR') AS `description`,`es`.`palletFk` AS `palletFk`,`t`.`routeFk` AS `routeFk`,`es`.`id` AS `scanFk`,`e`.`id` AS `expeditionFk`,`r`.`expeditionTruckFk` AS `expeditionTruckFk`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `lastPacked`,`t`.`id` AS `ticketFk` from (((((`vn`.`ticket` `t` left join `vn`.`expedition` `e` on((`t`.`id` = `e`.`ticketFk`))) left join `vn`.`expeditionScan` `es` on((`e`.`id` = `es`.`expeditionFk`))) left join `vn`.`expeditionPallet` `ep` on((`es`.`palletFk` = `ep`.`id`))) left join `vn`.`routesMonitor` `r` on((`r`.`routeFk` = `t`.`routeFk`))) left join `vn`.`expeditionTruck` `et` on((`et`.`id` = `r`.`expeditionTruckFk`))) where ((`t`.`shipped` >= curdate()) and (`t`.`routeFk` <> 0)) */; +/*!50001 VIEW `expeditionCommon` AS select `et`.`id` AS `truckFk`,`et`.`ETD` AS `etd`,ifnull(ucase(`et`.`description`),'SIN ESCANEAR') AS `description`,`es`.`palletFk` AS `palletFk`,`t`.`routeFk` AS `routeFk`,`es`.`id` AS `scanFk`,`e`.`id` AS `expeditionFk`,`r`.`expeditionTruckFk` AS `expeditionTruckFk`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `lastPacked`,`t`.`id` AS `ticketFk` from (((((`expeditionTruck` `et` left join `routesMonitor` `r` on((`et`.`id` = `r`.`expeditionTruckFk`))) left join `ticket` `t` on((`r`.`routeFk` = `t`.`routeFk`))) left join `expedition` `e` on((`t`.`id` = `e`.`ticketFk`))) left join `expeditionScan` `es` on((`e`.`id` = `es`.`expeditionFk`))) left join `expeditionPallet` `ep` on((`es`.`palletFk` = `ep`.`id`))) where (`et`.`ETD` >= curdate()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80704,7 +82644,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionPallet_Print` AS select `et2`.`description` AS `truck`,`t`.`routeFk` AS `routeFk`,`r`.`description` AS `zone`,count(`es`.`id`) AS `eti`,`ep`.`id` AS `palletFk`,(`et`.`id` <=> `rm`.`expeditionTruckFk`) AS `isMatch`,`t`.`warehouseFk` AS `warehouseFk` from (((((((`vn`.`expeditionTruck` `et` join `vn`.`expeditionPallet` `ep` on((`ep`.`truckFk` = `et`.`id`))) join `vn`.`expeditionScan` `es` on((`es`.`palletFk` = `ep`.`id`))) join `vn`.`expedition` `e` on((`e`.`id` = `es`.`expeditionFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `vn`.`route` `r` on((`r`.`id` = `t`.`routeFk`))) left join `vn2008`.`Rutas_monitor` `rm` on((`rm`.`Id_Ruta` = `r`.`id`))) left join `vn`.`expeditionTruck` `et2` on((`et2`.`id` = `rm`.`expeditionTruckFk`))) where (`ep`.`isPrint` = 0) group by `ep`.`id`,`t`.`routeFk` */; +/*!50001 VIEW `expeditionPallet_Print` AS select `et2`.`description` AS `truck`,`t`.`routeFk` AS `routeFk`,`r`.`description` AS `zone`,count(`es`.`id`) AS `eti`,`ep`.`id` AS `palletFk`,(`et`.`id` <=> `rm`.`expeditionTruckFk`) AS `isMatch`,`t`.`warehouseFk` AS `warehouseFk`,if((`r`.`created` > (curdate() + interval 1 day)),ucase(dayname(`r`.`created`)),NULL) AS `nombreDia` from (((((((`vn`.`expeditionTruck` `et` join `vn`.`expeditionPallet` `ep` on((`ep`.`truckFk` = `et`.`id`))) join `vn`.`expeditionScan` `es` on((`es`.`palletFk` = `ep`.`id`))) join `vn`.`expedition` `e` on((`e`.`id` = `es`.`expeditionFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `vn`.`route` `r` on((`r`.`id` = `t`.`routeFk`))) left join `vn2008`.`Rutas_monitor` `rm` on((`rm`.`Id_Ruta` = `r`.`id`))) left join `vn`.`expeditionTruck` `et2` on((`et2`.`id` = `rm`.`expeditionTruckFk`))) where (`ep`.`isPrint` = 0) group by `ep`.`id`,`t`.`routeFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80723,7 +82663,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionRoute_Monitor` AS select `r`.`id` AS `routeFk`,count(distinct if(isnull(`e`.`id`),`t`.`id`,NULL)) AS `tickets`,count(distinct `e`.`id`) AS `expeditions`,count(distinct `es`.`id`) AS `scanned`,max(`e`.`created`) AS `lastPacked` from ((((((`vn`.`route` `r` join `vn`.`routesMonitor` `rm` on((`r`.`id` = `rm`.`routeFk`))) join `vn`.`expeditionTruck` `et` on((`et`.`id` = `rm`.`expeditionTruckFk`))) join `vn`.`ticket` `t` on((`t`.`routeFk` = `r`.`id`))) left join `vn`.`expedition` `e` on((`e`.`ticketFk` = `t`.`id`))) left join `vn`.`expeditionScan` `es` on((`es`.`expeditionFk` = `e`.`id`))) left join `vn`.`stowaway` `st` on((`st`.`id` = `t`.`id`))) where ((`et`.`ETD` >= curdate()) and isnull(`st`.`id`)) group by `r`.`id` */; +/*!50001 VIEW `expeditionRoute_Monitor` AS select `r`.`id` AS `routeFk`,count(distinct if(isnull(`e`.`id`),`t`.`id`,NULL)) AS `tickets`,count(distinct `e`.`id`) AS `expeditions`,count(distinct `es`.`id`) AS `scanned`,max(`e`.`created`) AS `lastPacked`,`r`.`created` AS `created` from ((((((`route` `r` left join `routesMonitor` `rm` on((`r`.`id` = `rm`.`routeFk`))) left join `expeditionTruck` `et` on((`et`.`id` = `rm`.`expeditionTruckFk`))) join `ticket` `t` on((`t`.`routeFk` = `r`.`id`))) left join `expedition` `e` on((`e`.`ticketFk` = `t`.`id`))) left join `expeditionScan` `es` on((`es`.`expeditionFk` = `e`.`id`))) left join `stowaway` `st` on((`st`.`id` = `t`.`id`))) where ((`r`.`created` >= `util`.`yesterday`()) and isnull(`st`.`id`)) group by `r`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80742,7 +82682,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionRoute_freeTickets` AS select `t`.`routeFk` AS `routeFk`,`tss`.`ticket` AS `ticket`,`s`.`name` AS `code`,`w`.`name` AS `almacen`,`tss`.`updated` AS `updated` from ((((`vn`.`ticketStateToday` `tss` join `vn`.`ticket` `t` on((`t`.`id` = `tss`.`ticket`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`state` `s` on((`s`.`id` = `tss`.`state`))) left join `vn`.`stowaway` `st` on((`st`.`id` = `t`.`id`))) where ((ifnull(`t`.`packages`,0) = 0) and isnull(`st`.`id`)) */; +/*!50001 VIEW `expeditionRoute_freeTickets` AS select `t`.`routeFk` AS `routeFk`,`tss`.`ticket` AS `ticket`,`s`.`name` AS `code`,`w`.`name` AS `almacen`,`tss`.`updated` AS `updated`,`p`.`code` AS `parkingCode` from ((((((`vn`.`ticketState` `tss` join `vn`.`ticket` `t` on((`t`.`id` = `tss`.`ticket`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`state` `s` on((`s`.`id` = `tss`.`state`))) left join `vn`.`stowaway` `st` on((`st`.`id` = `t`.`id`))) left join `vn`.`ticketParking` `tp` on((`tp`.`ticketFk` = `t`.`id`))) left join `vn`.`parking` `p` on((`p`.`id` = `tp`.`parkingFk`))) where ((ifnull(`t`.`packages`,0) = 0) and isnull(`st`.`id`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80766,6 +82706,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `expeditionSticker` +-- + +/*!50001 DROP TABLE IF EXISTS `expeditionSticker`*/; +/*!50001 DROP VIEW IF EXISTS `expeditionSticker`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = 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 `expeditionSticker` AS select `e`.`id` AS `expeditionFk`,`e`.`ticketFk` AS `ticketFk`,`t`.`addressFk` AS `addressFk`,`t`.`clientFk` AS `clientFk`,`a`.`street` AS `street`,`a`.`postalCode` AS `postalCode`,`a`.`city` AS `city`,`a`.`nickname` AS `nickname`,concat('R(',right(`t`.`routeFk`,4),')') AS `routeFk`,`rm`.`beachFk` AS `beachFk`,if(`t`.`routeFk`,replace(`z`.`name`,'ZONA ','Z'),`am`.`name`) AS `zona`,`p`.`name` AS `province`,ifnull(`a`.`mobile`,`a`.`phone`) AS `phone` from (((((((`expedition` `e` join `ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) left join `routesMonitor` `rm` on((`rm`.`routeFk` = `t`.`routeFk`))) left join `beach` `b` on((`b`.`id` = `rm`.`beachFk`))) left join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) join `agencyMode` `am` on((`t`.`agencyModeFk` = `am`.`id`))) */; +/*!50001 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 `expeditionTimeExpended` -- @@ -80799,7 +82758,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `description`,count(distinct if(isnull(`e`.`expeditionFk`),`e`.`ticketFk`,NULL)) AS `ticketsSinBultos`,count(distinct `e`.`palletFk`) AS `pallets`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionFk`) AS `expeditions`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `vn`.`expeditionCommon` `e` group by `e`.`truckFk` order by `fallos` desc,`e`.`etd` */; +/*!50001 VIEW `expeditionTruck_Control` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `description`,count(distinct if(isnull(`e`.`expeditionFk`),`e`.`ticketFk`,NULL)) AS `ticketsSinBultos`,count(distinct `e`.`palletFk`) AS `pallets`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionFk`) AS `expeditions`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk` order by `fallos` desc,`e`.`etd` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80818,7 +82777,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control_Detail` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionTruckFk`) AS `destinos`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `vn`.`expeditionCommon` `e` group by `e`.`truckFk`,`e`.`palletFk` order by `fallos` desc,`e`.`etd`,`e`.`truckFk` */; +/*!50001 VIEW `expeditionTruck_Control_Detail` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionTruckFk`) AS `destinos`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk`,`e`.`palletFk` order by `fallos` desc,`e`.`etd`,`e`.`truckFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -80837,7 +82796,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control_Detail_Pallet` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,`e`.`routeFk` AS `route`,count(distinct `e`.`scanFk`) AS `scans`,`et`.`description` AS `destinos`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,`e`.`expeditionTruckFk` AS `expeditionTruckFk`,max(`e`.`lastPacked`) AS `lastPacked` from (`vn`.`expeditionCommon` `e` left join `vn`.`expeditionTruck` `et` on((`et`.`id` = `e`.`expeditionTruckFk`))) group by `e`.`truckFk`,`e`.`palletFk`,`e`.`routeFk` order by `fallos` desc,`e`.`palletFk` */; +/*!50001 VIEW `expeditionTruck_Control_Detail_Pallet` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,`e`.`routeFk` AS `route`,count(distinct `e`.`scanFk`) AS `scans`,`et`.`description` AS `destinos`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,`e`.`expeditionTruckFk` AS `expeditionTruckFk`,max(`e`.`lastPacked`) AS `lastPacked` from (`expeditionCommon` `e` left join `expeditionTruck` `et` on((`et`.`id` = `e`.`expeditionTruckFk`))) group by `e`.`truckFk`,`e`.`palletFk`,`e`.`routeFk` order by `fallos` desc,`e`.`palletFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -81184,6 +83143,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `itemInk` +-- + +/*!50001 DROP TABLE IF EXISTS `itemInk`*/; +/*!50001 DROP VIEW IF EXISTS `itemInk`*/; +/*!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 `itemInk` AS select `i`.`longName` AS `longName`,`i`.`inkFk` AS `inkFk` from (`item` `i` join `ink` on((`ink`.`id` = `i`.`inkFk`))) where `ink`.`isRealColor` group by `i`.`longName` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `itemPlacementSupplyList` -- @@ -81502,7 +83480,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `lastHourProduction` AS select `t`.`warehouseFk` AS `warehouseFk`,greatest(10,cast(sum(`sv`.`volume`) as decimal(5,1))) AS `m3` from (((((((`vn`.`saleTracking` `st` join `vn`.`saleVolume` `sv` on((`sv`.`saleFk` = `st`.`saleFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `sv`.`ticketFk`))) join `vn`.`state` `s` on((`s`.`id` = `st`.`stateFk`))) join `account`.`user` `u` on((`u`.`id` = `st`.`workerFk`))) join `account`.`role` `r` on((`r`.`id` = `u`.`role`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`warehouseAlias` `wa` on((`wa`.`id` = `w`.`aliasFk`))) where ((`st`.`created` > (now() + interval -(1) hour)) and (`s`.`code` = 'CHECKED') and (`r`.`name` <> 'salesPerson') and (`wa`.`name` = 'Silla')) */; +/*!50001 VIEW `lastHourProduction` AS select `t`.`warehouseFk` AS `warehouseFk`,cast(sum((ifnull(`p`.`volume`,((`p`.`width` * `p`.`height`) * `p`.`depth`)) / 1000000)) as decimal(5,1)) AS `m3` from (((`warehouse` `w` join `ticket` `t` on((`t`.`warehouseFk` = `w`.`id`))) left join `expedition` `e` on((`t`.`id` = `e`.`ticketFk`))) left join `packaging` `p` on((`p`.`id` = `e`.`packagingFk`))) where (`e`.`created` between (now() - interval 1 hour) and now()) group by `t`.`warehouseFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -81793,20 +83771,20 @@ USE `vn`; /*!50001 SET collation_connection = @saved_col_connection */; -- --- Final view structure for view `routesMonitor` +-- Final view structure for view `saleCost` -- -/*!50001 DROP TABLE IF EXISTS `routesMonitor`*/; -/*!50001 DROP VIEW IF EXISTS `routesMonitor`*/; +/*!50001 DROP TABLE IF EXISTS `saleCost`*/; +/*!50001 DROP VIEW IF EXISTS `saleCost`*/; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `routesMonitor` AS select `vn2008`.`Rutas_monitor`.`Id_Ruta` AS `routeFk`,`vn2008`.`Rutas_monitor`.`name` AS `name`,`vn2008`.`Rutas_monitor`.`Ubicacion` AS `beachFk`,`vn2008`.`Rutas_monitor`.`pedidosEncajados` AS `ticketPacked`,`vn2008`.`Rutas_monitor`.`pedidosLibres` AS `ticketFree`,`vn2008`.`Rutas_monitor`.`pedidosProduccion` AS `ticketProduction`,`vn2008`.`Rutas_monitor`.`bultos` AS `packages`,`vn2008`.`Rutas_monitor`.`notas` AS `note`,`vn2008`.`Rutas_monitor`.`fecha` AS `dated`,`vn2008`.`Rutas_monitor`.`dockFk` AS `dockFk`,`vn2008`.`Rutas_monitor`.`m3` AS `m3`,`vn2008`.`Rutas_monitor`.`priority` AS `priority`,`vn2008`.`Rutas_monitor`.`etd` AS `etd`,`vn2008`.`Rutas_monitor`.`expeditionTruckFk` AS `expeditionTruckFk` from `vn2008`.`Rutas_monitor` */; +/*!50001 VIEW `saleCost` AS select `s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`s`.`discount` AS `discount`,`s`.`price` AS `price`,`c`.`name` AS `component`,`sc`.`value` AS `coste` from (((`sale` `s` join `saleComponent` `sc` on((`sc`.`saleFk` = `s`.`id`))) join `component` `c` on((`c`.`id` = `sc`.`componentFk`))) join `componentType` `ct` on((`ct`.`id` = `c`.`typeFk`))) where (`ct`.`type` = 'coste') */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -81901,7 +83879,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleValue` AS select `wh`.`name` AS `warehouse`,`c`.`name` AS `client`,`c`.`typeFk` AS `clientTypeFk`,`u`.`name` AS `buyer`,`it`.`name` AS `family`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,(((`b`.`buyingValue` + `b`.`freightValue`) + `b`.`comissionValue`) + `b`.`packageValue`) AS `cost`,((((`b`.`buyingValue` + `b`.`freightValue`) + `b`.`comissionValue`) + `b`.`packageValue`) * `s`.`quantity`) AS `value`,`tm`.`year` AS `year`,`tm`.`week` AS `week` from (((((((((`vn`.`sale` `s` join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemType` `it` on((`it`.`id` = `i`.`typeFk`))) join `account`.`user` `u` on((`u`.`id` = `it`.`workerFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`client` `c` on((`c`.`id` = `t`.`clientFk`))) join `vn`.`warehouse` `wh` on((`wh`.`id` = `t`.`warehouseFk`))) join `vn`.`time` `tm` on((`tm`.`dated` = cast(`t`.`shipped` as date)))) join `cache`.`last_buy` `lb` on(((`lb`.`item_id` = `i`.`id`) and (`lb`.`warehouse_id` = `wh`.`id`)))) join `vn`.`buy` `b` on((`b`.`id` = `lb`.`buy_id`))) where `wh`.`isManaged` */; +/*!50001 VIEW `saleValue` AS select `wh`.`name` AS `warehouse`,`c`.`name` AS `client`,`c`.`typeFk` AS `clientTypeFk`,`u`.`name` AS `buyer`,`it`.`id` AS `itemTypeFk`,`it`.`name` AS `family`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,(((`b`.`buyingValue` + `b`.`freightValue`) + `b`.`comissionValue`) + `b`.`packageValue`) AS `cost`,((((`b`.`buyingValue` + `b`.`freightValue`) + `b`.`comissionValue`) + `b`.`packageValue`) * `s`.`quantity`) AS `value`,`tm`.`year` AS `year`,`tm`.`week` AS `week` from (((((((((`vn`.`sale` `s` join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemType` `it` on((`it`.`id` = `i`.`typeFk`))) join `account`.`user` `u` on((`u`.`id` = `it`.`workerFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`client` `c` on((`c`.`id` = `t`.`clientFk`))) join `vn`.`warehouse` `wh` on((`wh`.`id` = `t`.`warehouseFk`))) join `vn`.`time` `tm` on((`tm`.`dated` = cast(`t`.`shipped` as date)))) join `cache`.`last_buy` `lb` on(((`lb`.`item_id` = `i`.`id`) and (`lb`.`warehouse_id` = `wh`.`id`)))) join `vn`.`buy` `b` on((`b`.`id` = `lb`.`buy_id`))) where (`wh`.`isManaged` <> 0) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -81920,7 +83898,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleVolume` AS select `s`.`ticketFk` AS `ticketFk`,`s`.`id` AS `saleFk`,round(((`ic`.`cm3delivery` * `s`.`quantity`) / 1000),0) AS `litros`,`t`.`routeFk` AS `routeFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,((`s`.`quantity` * `ic`.`cm3delivery`) / 1000000) AS `volume`,((`s`.`quantity` * `ic`.`grams`) / 1000) AS `physicalWeight`,(((`s`.`quantity` * `ic`.`cm3delivery`) * greatest(`i`.`density`,167)) / 1000000) AS `weight`,((`s`.`quantity` * `ic`.`cm3delivery`) / 1000000) AS `physicalVolume`,(((`s`.`quantity` * `ic`.`cm3delivery`) * ifnull(`t`.`zonePrice`,`z`.`price`)) / `cb`.`volume`) AS `freight`,`t`.`zoneFk` AS `zoneFk`,`t`.`clientFk` AS `clientFk`,`s`.`isPicked` AS `isPicked` from (((((`sale` `s` join `item` `i` on((`i`.`id` = `s`.`itemFk`))) join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) join `packaging` `cb` on((`cb`.`id` = '94'))) join `itemCost` `ic` on(((`ic`.`itemFk` = `s`.`itemFk`) and (`ic`.`warehouseFk` = `t`.`warehouseFk`)))) where (`s`.`quantity` > 0) */; +/*!50001 VIEW `saleVolume` AS select `s`.`ticketFk` AS `ticketFk`,`s`.`id` AS `saleFk`,round(((`ic`.`cm3delivery` * `s`.`quantity`) / 1000),0) AS `litros`,`t`.`routeFk` AS `routeFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,((`s`.`quantity` * `ic`.`cm3delivery`) / 1000000) AS `volume`,((`s`.`quantity` * `ic`.`grams`) / 1000) AS `physicalWeight`,(((`s`.`quantity` * `ic`.`cm3delivery`) * greatest(`i`.`density`,167)) / 1000000) AS `weight`,((`s`.`quantity` * `ic`.`cm3delivery`) / 1000000) AS `physicalVolume`,(((`s`.`quantity` * `ic`.`cm3delivery`) * ifnull(`t`.`zonePrice`,`z`.`price`)) / (`vc`.`standardFlowerBox` * 1000)) AS `freight`,`t`.`zoneFk` AS `zoneFk`,`t`.`clientFk` AS `clientFk`,`s`.`isPicked` AS `isPicked` from (((((`sale` `s` join `item` `i` on((`i`.`id` = `s`.`itemFk`))) join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) join `volumeConfig` `vc`) join `itemCost` `ic` on(((`ic`.`itemFk` = `s`.`itemFk`) and (`ic`.`warehouseFk` = `t`.`warehouseFk`)))) where (`s`.`quantity` > 0) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82115,6 +84093,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `ticketMRW` +-- + +/*!50001 DROP TABLE IF EXISTS `ticketMRW`*/; +/*!50001 DROP VIEW IF EXISTS `ticketMRW`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketMRW` AS select `Tickets`.`Id_Agencia` AS `id_Agencia`,`Tickets`.`empresa_id` AS `empresa_id`,`Consignatarios`.`consignatario` AS `Consignatario`,`Consignatarios`.`domicilio` AS `DOMICILIO`,`Consignatarios`.`poblacion` AS `POBLACION`,`Consignatarios`.`codPostal` AS `CODPOSTAL`,`Consignatarios`.`telefono` AS `telefono`,`Consignatarios`.`movil` AS `movil`,`Clientes`.`if` AS `IF`,`Tickets`.`Id_Ticket` AS `Id_Ticket`,`Tickets`.`warehouse_id` AS `warehouse_id`,`Consignatarios`.`id_consigna` AS `Id_Consigna`,`Paises`.`Codigo` AS `CodigoPais`,`Tickets`.`Fecha` AS `Fecha`,`province`.`province_id` AS `province_id`,`Tickets`.`landing` AS `landing` from ((((`vn2008`.`Clientes` join `vn2008`.`Consignatarios` on((`Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente`))) join `vn2008`.`Tickets` on((`Consignatarios`.`id_consigna` = `Tickets`.`Id_Consigna`))) join `vn2008`.`province` on((`Consignatarios`.`province_id` = `province`.`province_id`))) join `vn2008`.`Paises` on((`province`.`Paises_Id` = `Paises`.`Id`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `ticketNotInvoiced` -- @@ -82134,6 +84131,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `ticketPackingList` +-- + +/*!50001 DROP TABLE IF EXISTS `ticketPackingList`*/; +/*!50001 DROP VIEW IF EXISTS `ticketPackingList`*/; +/*!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 `ticketPackingList` AS select `t`.`nickname` AS `nickname`,`t`.`id` AS `ticketFk`,`am`.`name` AS `agencyMode`,`am`.`flag` AS `flag`,`p`.`name` AS `province`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity` from ((((`ticket` `t` join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) join `agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) left join `sale` `s` on((`s`.`ticketFk` = `t`.`id`))) */; +/*!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 `ticketPreviousPreparingList` -- @@ -82248,6 +84264,44 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `traceabilityBuy` +-- + +/*!50001 DROP TABLE IF EXISTS `traceabilityBuy`*/; +/*!50001 DROP VIEW IF EXISTS `traceabilityBuy`*/; +/*!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 `traceabilityBuy` AS select `b`.`id` AS `buyFk`,`b`.`quantity` AS `quantity`,`tr`.`landed` AS `landed`,`w`.`name` AS `warehouseName`,`b`.`entryFk` AS `entryFk`,`s`.`name` AS `supplierName`,`b`.`itemFk` AS `itemFk` from ((((`buy` `b` join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `traceabilitySale` +-- + +/*!50001 DROP TABLE IF EXISTS `traceabilitySale`*/; +/*!50001 DROP VIEW IF EXISTS `traceabilitySale`*/; +/*!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 `traceabilitySale` AS select `s`.`ticketFk` AS `ticketFk`,`sb`.`buyFk` AS `buyFk`,`t`.`shipped` AS `shipped`,`t`.`nickname` AS `nickname`,`s`.`quantity` AS `quantity`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `worker` from (((`saleBuy` `sb` join `sale` `s` on((`s`.`id` = `sb`.`saleFk`))) join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `worker` `w` on((`w`.`id` = `sb`.`workerFk`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `user` -- @@ -82267,6 +84321,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `workerBusinessDated` +-- + +/*!50001 DROP TABLE IF EXISTS `workerBusinessDated`*/; +/*!50001 DROP VIEW IF EXISTS `workerBusinessDated`*/; +/*!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 `workerBusinessDated` AS select `t`.`dated` AS `dated`,`b`.`business_id` AS `business_id`,`w`.`id` AS `workerFk` from ((((`vn`.`time` `t` left join `postgresql`.`business` `b` on((`t`.`dated` between `b`.`date_start` and ifnull(`b`.`date_end`,curdate())))) left join `postgresql`.`profile` `pr` on((`b`.`client_id` = `pr`.`profile_id`))) left join `postgresql`.`person` `p` on((`pr`.`person_id` = `p`.`person_id`))) left join `vn`.`worker` `w` on((`p`.`id_trabajador` = `w`.`id`))) where (`t`.`dated` > (curdate() + interval -(2) year)) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `workerCalendar` -- @@ -82509,7 +84582,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,cast((curdate() + interval ((hour(`zc`.`hour`) * 60) + minute(`zc`.`hour`)) minute) as time) AS `hourTheoretical`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `totalVolume`,cast(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0)) as decimal(5,1)) AS `remainingVolume`,greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) AS `speed`,cast((`zc`.`hour` + interval ((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute) as time) AS `hourEffective`,floor(((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)))) AS `minutesLess`,cast((`zc`.`hour` + interval ((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute) as time) AS `etc` from ((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `s` on((`s`.`id` = `tst`.`state`))) join `vn`.`saleVolume` `sv` on((`sv`.`ticketFk` = `t`.`id`))) left join `vn`.`lastHourProduction` `lhp` on((`lhp`.`warehouseFk` = `t`.`warehouseFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`warehouseAlias` `wa` on((`wa`.`id` = `w`.`aliasFk`))) left join `vn`.`zoneClosure` `zc` on(((`zc`.`zoneFk` = `t`.`zoneFk`) and (`zc`.`dated` = curdate())))) left join `cache`.`departure_limit` `dl` on(((`dl`.`warehouse_id` = `t`.`warehouseFk`) and (`dl`.`fecha` = curdate())))) where ((`w`.`hasConfectionTeam` = 1) and (cast(`t`.`shipped` as date) = curdate())) group by `t`.`zoneFk` */; +/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,cast((curdate() + interval ((hour(ifnull(`zc`.`hour`,`z`.`hour`)) * 60) + minute(ifnull(`zc`.`hour`,`z`.`hour`))) minute) as time) AS `hourTheoretical`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `totalVolume`,cast(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0)) as decimal(5,1)) AS `remainingVolume`,greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) AS `speed`,cast((`zc`.`hour` + interval ((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute) as time) AS `hourEffective`,floor(((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)))) AS `minutesLess`,cast((`zc`.`hour` + interval ((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute) as time) AS `etc` from (((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `s` on((`s`.`id` = `tst`.`state`))) join `vn`.`saleVolume` `sv` on((`sv`.`ticketFk` = `t`.`id`))) left join `vn`.`lastHourProduction` `lhp` on((`lhp`.`warehouseFk` = `t`.`warehouseFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`warehouseAlias` `wa` on((`wa`.`id` = `w`.`aliasFk`))) join `vn`.`zone` `z` on((`z`.`id` = `t`.`zoneFk`))) left join `vn`.`zoneClosure` `zc` on(((`zc`.`zoneFk` = `t`.`zoneFk`) and (`zc`.`dated` = curdate())))) left join `cache`.`departure_limit` `dl` on(((`dl`.`warehouse_id` = `t`.`warehouseFk`) and (`dl`.`fecha` = curdate())))) where (`w`.`hasProduction` and (cast(`t`.`shipped` as date) = curdate())) group by `t`.`zoneFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82548,4 +84621,4 @@ USE `vncontrol`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-03-30 12:16:04 +-- Dump completed on 2021-05-25 10:34:01 From f6a0bcb12cf2582c60b57f96d71f7f7d13461269 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 25 May 2021 13:33:17 +0200 Subject: [PATCH 2/2] Updated unit tests --- db/dump/dumpedFixtures.sql | 26 +++++++++++++------ db/dump/structure.sql | 2 +- db/export-data.sh | 1 + .../05-ticket/06_basic_data_steps.spec.js | 2 +- .../01_create_and_basic_data.spec.js | 2 +- .../sales-monitor/specs/salesFilter.spec.js | 2 +- .../back/methods/ticket/specs/filter.spec.js | 2 +- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 683e5b51f..b8f17d6ed 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -34,7 +34,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:49 +-- Dump completed on 2021-05-25 11:53:07 USE `account`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -120,7 +120,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:50 +-- Dump completed on 2021-05-25 11:53:07 USE `salix`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -176,7 +176,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:50 +-- Dump completed on 2021-05-25 11:53:08 USE `vn`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -403,6 +403,16 @@ LOCK TABLES `continent` WRITE; INSERT INTO `continent` VALUES (1,'Asia','AS'),(2,'América','AM'),(3,'África','AF'),(4,'Europa','EU'),(5,'Oceanía','OC'); /*!40000 ALTER TABLE `continent` ENABLE KEYS */; UNLOCK TABLES; + +-- +-- Dumping data for table `volumeConfig` +-- + +LOCK TABLES `volumeConfig` WRITE; +/*!40000 ALTER TABLE `volumeConfig` DISABLE KEYS */; +INSERT INTO `volumeConfig` VALUES (2.67,1.60,0.8,150,0.30,120,57); +/*!40000 ALTER TABLE `volumeConfig` ENABLE KEYS */; +UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -412,7 +422,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:51 +-- Dump completed on 2021-05-25 11:53:09 USE `cache`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -448,7 +458,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:52 +-- Dump completed on 2021-05-25 11:53:10 USE `hedera`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -514,7 +524,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:52 +-- Dump completed on 2021-05-25 11:53:10 USE `postgresql`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -600,7 +610,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:52 +-- Dump completed on 2021-05-25 11:53:10 USE `sage`; -- MariaDB dump 10.19 Distrib 10.5.9-MariaDB, for debian-linux-gnu (x86_64) -- @@ -656,4 +666,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-05-25 10:34:53 +-- Dump completed on 2021-05-25 11:53:11 diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 8d8c144e5..8df46890d 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -30508,7 +30508,7 @@ BEGIN NEW.currencyFk != OLD.currencyFk THEN - CALL vn2008.recibidaIvaDivisaUpdate(NEW.id); + -- CALL vn2008.recibidaIvaDivisaUpdate(NEW.id); END IF; diff --git a/db/export-data.sh b/db/export-data.sh index 5538d945e..5292e8f6a 100755 --- a/db/export-data.sh +++ b/db/export-data.sh @@ -59,6 +59,7 @@ TABLES=( component componentType continent + volumeConfig ) dump_tables ${TABLES[@]} diff --git a/e2e/paths/05-ticket/06_basic_data_steps.spec.js b/e2e/paths/05-ticket/06_basic_data_steps.spec.js index f7834e562..a5f9a60cf 100644 --- a/e2e/paths/05-ticket/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket/06_basic_data_steps.spec.js @@ -75,7 +75,7 @@ describe('Ticket Edit basic data path', () => { const result = await page .waitToGetProperty(selectors.ticketBasicData.stepTwoTotalPriceDif, 'innerText'); - expect(result).toContain('-€248.00'); + expect(result).toContain('-€232.75'); }); it(`should select a new reason for the changes made then click on finalize`, async() => { diff --git a/e2e/paths/14-account/01_create_and_basic_data.spec.js b/e2e/paths/14-account/01_create_and_basic_data.spec.js index 183ae5fa3..15c9118d1 100644 --- a/e2e/paths/14-account/01_create_and_basic_data.spec.js +++ b/e2e/paths/14-account/01_create_and_basic_data.spec.js @@ -80,7 +80,7 @@ describe('Account create and basic data path', () => { await page.reloadSection('account.card.roles'); const rolesCount = await page.countElement(selectors.accountRoles.anyResult); - expect(rolesCount).toEqual(34); + expect(rolesCount).toEqual(35); }); }); diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index 64cc35bfa..0666544e7 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -41,7 +41,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await app.models.SalesMonitor.salesFilter(ctx, filter); - expect(result.length).toEqual(7); + expect(result.length).toEqual(6); }); it('should return the tickets matching the problems on null', async() => { diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 7798b156e..0f4a1660e 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -41,7 +41,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await app.models.Ticket.filter(ctx, filter); - expect(result.length).toEqual(7); + expect(result.length).toEqual(6); }); it('should return the tickets matching the problems on null', async() => {