diff --git a/db/dump/structure.sql b/db/dump/structure.sql
index 05eceb370..99f500bb3 100644
--- a/db/dump/structure.sql
+++ b/db/dump/structure.sql
@@ -881,52 +881,52 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `passwordGenerate`() RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci
READS SQL DATA
-BEGIN
-/**
- * Generates a random password that meets the minimum requirements.
- *
- * @return Generated password
- */
- DECLARE vMinLength TINYINT;
- DECLARE vMinAlpha TINYINT;
- DECLARE vMinUpper TINYINT;
- DECLARE vMinDigits TINYINT;
- DECLARE vMinPunct TINYINT;
- DECLARE vAlpha TINYINT DEFAULT 0;
- DECLARE vUpper TINYINT DEFAULT 0;
- DECLARE vDigits TINYINT DEFAULT 0;
- DECLARE vPunct TINYINT DEFAULT 0;
- DECLARE vRandIndex INT;
- DECLARE vPwd TEXT DEFAULT '';
-
- DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz';
- DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- DECLARE vDigitChars TEXT DEFAULT '1234567890';
- DECLARE vPunctChars TEXT DEFAULT '!$%&()=.';
-
- SELECT length, nAlpha, nUpper, nDigits, nPunct
- INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword;
-
- WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha
- OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO
- SET vRandIndex = FLOOR((RAND() * 4) + 1);
-
- CASE
- WHEN vRandIndex = 1 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1));
- SET vAlpha = vAlpha + 1;
- WHEN vRandIndex = 2 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1));
- SET vUpper = vUpper + 1;
- WHEN vRandIndex = 3 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1));
- SET vDigits = vDigits + 1;
- WHEN vRandIndex = 4 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1));
- SET vPunct = vPunct + 1;
- END CASE;
- END WHILE;
- RETURN vPwd;
+BEGIN
+/**
+ * Generates a random password that meets the minimum requirements.
+ *
+ * @return Generated password
+ */
+ DECLARE vMinLength TINYINT;
+ DECLARE vMinAlpha TINYINT;
+ DECLARE vMinUpper TINYINT;
+ DECLARE vMinDigits TINYINT;
+ DECLARE vMinPunct TINYINT;
+ DECLARE vAlpha TINYINT DEFAULT 0;
+ DECLARE vUpper TINYINT DEFAULT 0;
+ DECLARE vDigits TINYINT DEFAULT 0;
+ DECLARE vPunct TINYINT DEFAULT 0;
+ DECLARE vRandIndex INT;
+ DECLARE vPwd TEXT DEFAULT '';
+
+ DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz';
+ DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ DECLARE vDigitChars TEXT DEFAULT '1234567890';
+ DECLARE vPunctChars TEXT DEFAULT '!$%&()=.';
+
+ SELECT length, nAlpha, nUpper, nDigits, nPunct
+ INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword;
+
+ WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha
+ OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO
+ SET vRandIndex = FLOOR((RAND() * 4) + 1);
+
+ CASE
+ WHEN vRandIndex = 1 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1));
+ SET vAlpha = vAlpha + 1;
+ WHEN vRandIndex = 2 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1));
+ SET vUpper = vUpper + 1;
+ WHEN vRandIndex = 3 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1));
+ SET vDigits = vDigits + 1;
+ WHEN vRandIndex = 4 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1));
+ SET vPunct = vPunct + 1;
+ END CASE;
+ END WHILE;
+ RETURN vPwd;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -1019,11 +1019,11 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `userGetNameFromId__`(vSelf INT) RETURNS varchar(30) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-/**
- * @deprecated Use user_getNameFromId();
- */
- RETURN user_getNameFromId(vSelf);
+BEGIN
+/**
+ * @deprecated Use user_getNameFromId();
+ */
+ RETURN user_getNameFromId(vSelf);
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -1088,22 +1088,22 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `user_getMysqlRole`(vUserName VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-/**
- * From a username, it returns the associated MySQL wich should be used when
- * using external authentication systems.
- *
- * @param vUserName The user name
- * @return The associated MySQL role
- */
- DECLARE vRole VARCHAR(255);
-
- SELECT CONCAT(IF(r.hasLogin, 'z-', ''), r.name) INTO vRole
- FROM role r
- JOIN user u ON u.role = r.id
- WHERE u.name = vUserName;
-
- RETURN vRole;
+BEGIN
+/**
+ * From a username, it returns the associated MySQL wich should be used when
+ * using external authentication systems.
+ *
+ * @param vUserName The user name
+ * @return The associated MySQL role
+ */
+ DECLARE vRole VARCHAR(255);
+
+ SELECT CONCAT(IF(r.hasLogin, 'z-', ''), r.name) INTO vRole
+ FROM role r
+ JOIN user u ON u.role = r.id
+ WHERE u.name = vUserName;
+
+ RETURN vRole;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -1122,20 +1122,20 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `user_getNameFromId`(vSelf INT) RETURNS varchar(30) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-/**
- * Gets user name from it's id.
- *
- * @param vSelf The user id
- * @return The user name
- */
- DECLARE vName VARCHAR(30);
-
- SELECT `name` INTO vName
- FROM user
- WHERE id = vSelf;
-
- RETURN vName;
+BEGIN
+/**
+ * Gets user name from it's id.
+ *
+ * @param vSelf The user id
+ * @return The user name
+ */
+ DECLARE vName VARCHAR(30);
+
+ SELECT `name` INTO vName
+ FROM user
+ WHERE id = vSelf;
+
+ RETURN vName;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -4770,16 +4770,16 @@ BEGIN
* La tabla mana_spellers es una caché
*
*/
-
- UPDATE mana_spellers me
- JOIN
- (SELECT Id_Trabajador, FLOOR(SUM(importe)/12) as pesoCarteraMensual
- FROM bs.vendedores
- WHERE año * 100 + mes >= (YEAR(CURDATE()) -1) * 100 + MONTH(CURDATE())
- GROUP BY Id_Trabajador
- ) lastYearSales USING(Id_Trabajador)
- SET me.prices_modifier_rate = GREATEST(me.minRate,LEAST(me.maxRate,ROUND(- me.used/lastYearSales.pesoCarteraMensual,3))) ;
-
+
+ UPDATE mana_spellers me
+ JOIN
+ (SELECT Id_Trabajador, FLOOR(SUM(importe)/12) as pesoCarteraMensual
+ FROM bs.vendedores
+ WHERE año * 100 + mes >= (YEAR(CURDATE()) -1) * 100 + MONTH(CURDATE())
+ GROUP BY Id_Trabajador
+ ) lastYearSales USING(Id_Trabajador)
+ SET me.prices_modifier_rate = GREATEST(me.minRate,LEAST(me.maxRate,ROUND(- me.used/lastYearSales.pesoCarteraMensual,3))) ;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -5196,46 +5196,46 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`z-developer`@`%` PROCEDURE `saleGraphic`(vItemFk INT,
- vTypeFk INT,
- vCategoryFk INT,
- vFromDate DATE,
- vToDate DATE,
+CREATE DEFINER=`z-developer`@`%` PROCEDURE `saleGraphic`(vItemFk INT,
+ vTypeFk INT,
+ vCategoryFk INT,
+ vFromDate DATE,
+ vToDate DATE,
vProducerFk INT)
-BEGIN
-
- DECLARE vFromDateLastYear DATE;
- DECLARE vToDateLastYear DATE;
- DECLARE vFromDateTwoYearsAgo DATE;
- DECLARE vToDateTwoYearsAgo DATE;
-
- SET vItemFk = IFNULL(vItemFk,0);
- SET vTypeFk = IFNULL(vTypeFk, 0);
- SET vCategoryFk = IFNULL(vCategoryFk,0);
- SET vFromDate = IFNULL(vFromDate,CURDATE());
- SET vToDate = IFNULL(vToDate,CURDATE());
- SET vProducerFk = IFNULL(vProducerFk,0);
-
- SET vFromDateLastYear = TIMESTAMPADD(YEAR,-1,vFromDate);
- SET vToDateLastYear = TIMESTAMPADD(YEAR,-1,vToDate);
- SET vFromDateTwoYearsAgo = TIMESTAMPADD(YEAR,-2,vFromDate);
- SET vToDateTwoYearsAgo = TIMESTAMPADD(YEAR,-2,vToDate);
-
- SELECT s.quantity, CAST(v.importe AS DECIMAL(10,0)) importe, v.fecha
- FROM bs.ventas v
- JOIN vn.sale s ON s.id = v.Id_Movimiento
- JOIN vn.item i ON i.id = s.itemFk
- JOIN vn.itemType it ON it.id = i.typeFk
- JOIN vn.itemCategory ic ON ic.id = it.categoryFk
- WHERE vItemFk IN (i.id, 0)
- AND vTypeFk IN (i.typeFk, 0)
- AND vCategoryFk IN (it.categoryFk, 0)
- AND vProducerFk IN (i.producerFk, 0)
- AND (v.fecha BETWEEN vFromDate AND vToDate
- OR v.fecha BETWEEN vFromDateLastYear AND vToDateLastYear
- OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo
- );
-
+BEGIN
+
+ DECLARE vFromDateLastYear DATE;
+ DECLARE vToDateLastYear DATE;
+ DECLARE vFromDateTwoYearsAgo DATE;
+ DECLARE vToDateTwoYearsAgo DATE;
+
+ SET vItemFk = IFNULL(vItemFk,0);
+ SET vTypeFk = IFNULL(vTypeFk, 0);
+ SET vCategoryFk = IFNULL(vCategoryFk,0);
+ SET vFromDate = IFNULL(vFromDate,CURDATE());
+ SET vToDate = IFNULL(vToDate,CURDATE());
+ SET vProducerFk = IFNULL(vProducerFk,0);
+
+ SET vFromDateLastYear = TIMESTAMPADD(YEAR,-1,vFromDate);
+ SET vToDateLastYear = TIMESTAMPADD(YEAR,-1,vToDate);
+ SET vFromDateTwoYearsAgo = TIMESTAMPADD(YEAR,-2,vFromDate);
+ SET vToDateTwoYearsAgo = TIMESTAMPADD(YEAR,-2,vToDate);
+
+ SELECT s.quantity, CAST(v.importe AS DECIMAL(10,0)) importe, v.fecha
+ FROM bs.ventas v
+ JOIN vn.sale s ON s.id = v.Id_Movimiento
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.itemType it ON it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ WHERE vItemFk IN (i.id, 0)
+ AND vTypeFk IN (i.typeFk, 0)
+ AND vCategoryFk IN (it.categoryFk, 0)
+ AND vProducerFk IN (i.producerFk, 0)
+ AND (v.fecha BETWEEN vFromDate AND vToDate
+ OR v.fecha BETWEEN vFromDateLastYear AND vToDateLastYear
+ OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo
+ );
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7084,9 +7084,9 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `cacheCalc_clean`()
-BEGIN
- DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, NOW());
- DELETE FROM cache_calc WHERE expires < vCleanTime;
+BEGIN
+ DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, NOW());
+ DELETE FROM cache_calc WHERE expires < vCleanTime;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7104,27 +7104,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `cache_calc_end`(IN `v_calc` INT)
-BEGIN
- DECLARE v_cache_name VARCHAR(255);
- DECLARE v_params VARCHAR(255);
-
- -- Libera el bloqueo y actualiza la fecha de ultimo refresco.
-
- UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id
- SET
- cc.last_refresh = NOW(),
- cc.expires = ADDTIME(NOW(), c.lifetime),
- cc.connection_id = NULL
- WHERE cc.id = v_calc;
-
- SELECT c.name, ca.params INTO v_cache_name, v_params
- FROM cache c
- JOIN cache_calc ca ON c.id = ca.cache_id
- WHERE ca.id = v_calc;
-
- IF v_cache_name IS NOT NULL THEN
- DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
- END IF;
+BEGIN
+ DECLARE v_cache_name VARCHAR(255);
+ DECLARE v_params VARCHAR(255);
+
+ -- Libera el bloqueo y actualiza la fecha de ultimo refresco.
+
+ UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id
+ SET
+ cc.last_refresh = NOW(),
+ cc.expires = ADDTIME(NOW(), c.lifetime),
+ cc.connection_id = NULL
+ WHERE cc.id = v_calc;
+
+ SELECT c.name, ca.params INTO v_cache_name, v_params
+ FROM cache c
+ JOIN cache_calc ca ON c.id = ca.cache_id
+ WHERE ca.id = v_calc;
+
+ IF v_cache_name IS NOT NULL THEN
+ DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7142,88 +7142,88 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `cache_calc_start`(OUT `v_calc` INT, INOUT `v_refresh` INT, IN `v_cache_name` VARCHAR(50), IN `v_params` VARCHAR(100))
-proc: BEGIN
- DECLARE v_valid BOOL;
- DECLARE v_lock_id VARCHAR(100);
- DECLARE v_cache_id INT;
- DECLARE v_expires DATETIME;
- DECLARE v_clean_time DATETIME;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- IF v_lock_id IS NOT NULL THEN
- DO RELEASE_LOCK(v_lock_id);
- END IF;
-
- RESIGNAL;
- END;
-
- SET v_params = IFNULL(v_params, '');
-
- -- Si el servidor se ha reiniciado invalida todos los calculos.
-
- SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid;
-
- IF !v_valid
- THEN
- DELETE FROM cache_calc;
- INSERT INTO cache_valid (valid) VALUES (TRUE);
- END IF;
-
- -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia.
-
- SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params);
-
- IF !GET_LOCK(v_lock_id, 30)
- THEN
- SET v_calc = NULL;
- SET v_refresh = FALSE;
- LEAVE proc;
- END IF;
-
- -- Comprueba si el calculo solicitado existe y esta actualizado.
-
- SELECT c.id, ca.id, ca.expires
- INTO v_cache_id, v_calc, v_expires
- FROM cache c
- LEFT JOIN cache_calc ca
- ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci'
- WHERE c.name = v_cache_name COLLATE 'utf8_general_ci';
-
- -- Si existe una calculo valido libera el bloqueo y devuelve su identificador.
-
- IF !v_refresh AND NOW() < v_expires
- THEN
- DO RELEASE_LOCK(v_lock_id);
- SET v_refresh = FALSE;
- LEAVE proc;
- END IF;
-
- -- Si el calculo no existe le crea una entrada en la tabla de calculos.
-
- IF v_calc IS NULL
- THEN
- INSERT INTO cache_calc SET
- cache_id = v_cache_id,
- cacheName = v_cache_name,
- params = v_params,
- last_refresh = NULL,
- expires = NULL,
- connection_id = CONNECTION_ID();
-
- SET v_calc = LAST_INSERT_ID();
- ELSE
- UPDATE cache_calc
- SET
- last_refresh = NULL,
- expires = NULL,
- connection_id = CONNECTION_ID()
- WHERE id = v_calc;
- END IF;
-
- -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador.
-
- SET v_refresh = TRUE;
+proc: BEGIN
+ DECLARE v_valid BOOL;
+ DECLARE v_lock_id VARCHAR(100);
+ DECLARE v_cache_id INT;
+ DECLARE v_expires DATETIME;
+ DECLARE v_clean_time DATETIME;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ IF v_lock_id IS NOT NULL THEN
+ DO RELEASE_LOCK(v_lock_id);
+ END IF;
+
+ RESIGNAL;
+ END;
+
+ SET v_params = IFNULL(v_params, '');
+
+ -- Si el servidor se ha reiniciado invalida todos los calculos.
+
+ SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid;
+
+ IF !v_valid
+ THEN
+ DELETE FROM cache_calc;
+ INSERT INTO cache_valid (valid) VALUES (TRUE);
+ END IF;
+
+ -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia.
+
+ SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params);
+
+ IF !GET_LOCK(v_lock_id, 30)
+ THEN
+ SET v_calc = NULL;
+ SET v_refresh = FALSE;
+ LEAVE proc;
+ END IF;
+
+ -- Comprueba si el calculo solicitado existe y esta actualizado.
+
+ SELECT c.id, ca.id, ca.expires
+ INTO v_cache_id, v_calc, v_expires
+ FROM cache c
+ LEFT JOIN cache_calc ca
+ ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci'
+ WHERE c.name = v_cache_name COLLATE 'utf8_general_ci';
+
+ -- Si existe una calculo valido libera el bloqueo y devuelve su identificador.
+
+ IF !v_refresh AND NOW() < v_expires
+ THEN
+ DO RELEASE_LOCK(v_lock_id);
+ SET v_refresh = FALSE;
+ LEAVE proc;
+ END IF;
+
+ -- Si el calculo no existe le crea una entrada en la tabla de calculos.
+
+ IF v_calc IS NULL
+ THEN
+ INSERT INTO cache_calc SET
+ cache_id = v_cache_id,
+ cacheName = v_cache_name,
+ params = v_params,
+ last_refresh = NULL,
+ expires = NULL,
+ connection_id = CONNECTION_ID();
+
+ SET v_calc = LAST_INSERT_ID();
+ ELSE
+ UPDATE cache_calc
+ SET
+ last_refresh = NULL,
+ expires = NULL,
+ connection_id = CONNECTION_ID()
+ WHERE id = v_calc;
+ END IF;
+
+ -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador.
+
+ SET v_refresh = TRUE;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7241,24 +7241,24 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `cache_calc_unlock`(IN `v_calc` INT)
-proc: BEGIN
- DECLARE v_cache_name VARCHAR(50);
- DECLARE v_params VARCHAR(100);
-
- IF v_calc IS NULL THEN
- LEAVE proc;
- END IF;
-
- SELECT c.name, ca.params INTO v_cache_name, v_params
- FROM cache c
- JOIN cache_calc ca ON c.id = ca.cache_id
- WHERE ca.id = v_calc;
-
- DELETE FROM cache_calc WHERE id = v_calc;
-
- IF v_cache_name IS NOT NULL THEN
- DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
- END IF;
+proc: BEGIN
+ DECLARE v_cache_name VARCHAR(50);
+ DECLARE v_params VARCHAR(100);
+
+ IF v_calc IS NULL THEN
+ LEAVE proc;
+ END IF;
+
+ SELECT c.name, ca.params INTO v_cache_name, v_params
+ FROM cache c
+ JOIN cache_calc ca ON c.id = ca.cache_id
+ WHERE ca.id = v_calc;
+
+ DELETE FROM cache_calc WHERE id = v_calc;
+
+ IF v_cache_name IS NOT NULL THEN
+ DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7277,9 +7277,9 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `cache_clean`()
NO SQL
-BEGIN
- CALL available_clean;
- CALL visible_clean;
+BEGIN
+ CALL available_clean;
+ CALL visible_clean;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7297,13 +7297,13 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `clean`()
-BEGIN
-
- DECLARE vDateShort DATETIME;
-
- SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE());
-
- DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
+BEGIN
+
+ DECLARE vDateShort DATETIME;
+
+ SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE());
+
+ DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -9202,154 +9202,154 @@ CREATE DEFINER=`root`@`%` PROCEDURE `exchange_new`(
IN `vAuction` SMALLINT,
IN `vPackage` INT,
IN `vPutOrderFk` INT)
-BEGIN
+BEGIN
/**
* Adds a new exchange, generates it's barcode and
* inserts/updates the transaction. When the referenced
* transaction exists as provisional, updates it with
- * the new values.
- */
- DECLARE vEkt INT;
- DECLARE vRewriteKop INT DEFAULT NULL;
- DECLARE vBarcode CHAR(15) DEFAULT NULL;
- DECLARE vIsDuplicated BOOL;
+ * the new values.
+ */
+ DECLARE vEkt INT;
+ DECLARE vRewriteKop INT DEFAULT NULL;
+ DECLARE vBarcode CHAR(15) DEFAULT NULL;
+ DECLARE vIsDuplicated BOOL;
DECLARE vUpdateExistent BOOL DEFAULT FALSE;
- DECLARE duplicateKey CONDITION FOR 1062;
+ DECLARE duplicateKey CONDITION FOR 1062;
+
+ DECLARE CONTINUE HANDLER FOR duplicateKey
+ SET vIsDuplicated = TRUE;
+
+ -- Generates the barcode
+
+ IF vAgj != 0 AND vAgj IS NOT NULL
+ THEN
+ SET vBarcode = CONCAT(
+ LPAD(vAuction, 2, 0),
+ LPAD(IFNULL(vClock, 99), 2, 0),
+ LPAD(DAYOFYEAR(vDate), 3, 0),
+ IF(vClock IS NULL OR vClock = 99,
+ LPAD(vAgj, 7, 0),
+ CONCAT(LPAD(vAgj, 5, 0), '01')
+ ),
+ '0'
+ );
+ END IF;
+
+ -- Rewrites the kop parameter
+
+ IF vKop IS NULL THEN
+ SELECT defaultKop INTO vKop FROM exchangeConfig;
+ END IF;
+
+ SELECT e.kop INTO vRewriteKop
+ FROM mailSender e
+ JOIN mail m ON m.senderFk = e.id
+ WHERE m.id = vMailFk;
+
+ SET vKop = IFNULL(vRewriteKop, vKop);
+
+ -- Inserts the new transaction
- DECLARE CONTINUE HANDLER FOR duplicateKey
- SET vIsDuplicated = TRUE;
-
- -- Generates the barcode
-
- IF vAgj != 0 AND vAgj IS NOT NULL
- THEN
- SET vBarcode = CONCAT(
- LPAD(vAuction, 2, 0),
- LPAD(IFNULL(vClock, 99), 2, 0),
- LPAD(DAYOFYEAR(vDate), 3, 0),
- IF(vClock IS NULL OR vClock = 99,
- LPAD(vAgj, 7, 0),
- CONCAT(LPAD(vAgj, 5, 0), '01')
- ),
- '0'
- );
- END IF;
-
- -- Rewrites the kop parameter
-
- IF vKop IS NULL THEN
- SELECT defaultKop INTO vKop FROM exchangeConfig;
- END IF;
-
- SELECT e.kop INTO vRewriteKop
- FROM mailSender e
- JOIN mail m ON m.senderFk = e.id
- WHERE m.id = vMailFk;
-
- SET vKop = IFNULL(vRewriteKop, vKop);
-
- -- Inserts the new transaction
-
- SET vIsDuplicated = FALSE;
- INSERT INTO ekt SET
- barcode = IFNULL(vBarcode, barcode)
- ,deliveryNumber = vDeliveryNumber
- ,entryYear = YEAR(vDate)
- ,fec = vDate
- ,hor = vHour
- ,ref = vRef
- ,item = vItem
- ,agj = vAgj
- ,cat = vCat
- ,pac = vPac
- ,sub = vSub
- ,kop = vKop
- ,ptd = vPtd
- ,pro = vPro
- ,ori = vOrigin
- ,ptj = vPtj
- ,qty = vQuantiy
- ,pri = vPrice
- ,klo = vClock
- ,s1 = vS1
- ,s2 = vS2
- ,s3 = vS3
- ,s4 = vS4
- ,s5 = vS5
- ,s6 = vS6
- ,k1 = vK1
- ,k2 = vK2
- ,k3 = vP1
- ,k4 = vP2
- ,auction = vAuction
- ,package = vPackage
- ,putOrderFk = vPutOrderFk;
-
- -- If it exists duplicado updates it
-
- IF NOT vIsDuplicated
- THEN
- SET vEkt = LAST_INSERT_ID();
- CALL ekt_load (vEkt);
-
- ELSEIF vDeliveryNumber != 0
- AND vDeliveryNumber IS NOT NULL
- THEN
- SELECT id INTO vEkt
- FROM ekt
- WHERE deliveryNumber = vDeliveryNumber;
-
- SELECT COUNT(*) = 0 INTO vUpdateExistent
- FROM ekt t
- JOIN `exchange` b ON b.ektFk = t.id
- JOIN exchangeConfig c
- WHERE t.deliveryNumber = vDeliveryNumber
- AND t.entryYear = YEAR(vDate)
- AND b.typeFk != c.presaleFk;
- END IF;
-
- IF vUpdateExistent
- THEN
- UPDATE ekt SET
- barcode = IFNULL(vBarcode, barcode)
- ,fec = vDate
- ,hor = vHour
- ,ref = vRef
- ,item = vItem
- ,agj = vAgj
- ,cat = vCat
- ,pac = vPac
- ,sub = vSub
- ,kop = vKop
- ,ptd = vPtd
- ,pro = vPro
- ,ori = vOrigin
- ,ptj = vPtj
- ,qty = vQuantiy
- ,pri = vPrice
- ,klo = vClock
- ,s1 = vS1
- ,s2 = vS2
- ,s3 = vS3
- ,s4 = vS4
- ,s5 = vS5
- ,s6 = vS6
- ,k1 = vK1
- ,k2 = vK2
- ,k3 = vP1
- ,k4 = vP2
- ,auction = vAuction
- ,package = vPackage
- ,putOrderFk = IFNULL(vPutOrderFk, putOrderFk)
- WHERE id = vEkt;
- END IF;
-
- -- Registers the exchange
-
- INSERT INTO `exchange` SET
- mailFk = vMailFk
- ,typeFk = vType
- ,ektFk = vEkt;
+ SET vIsDuplicated = FALSE;
+ INSERT INTO ekt SET
+ barcode = IFNULL(vBarcode, barcode)
+ ,deliveryNumber = vDeliveryNumber
+ ,entryYear = YEAR(vDate)
+ ,fec = vDate
+ ,hor = vHour
+ ,ref = vRef
+ ,item = vItem
+ ,agj = vAgj
+ ,cat = vCat
+ ,pac = vPac
+ ,sub = vSub
+ ,kop = vKop
+ ,ptd = vPtd
+ ,pro = vPro
+ ,ori = vOrigin
+ ,ptj = vPtj
+ ,qty = vQuantiy
+ ,pri = vPrice
+ ,klo = vClock
+ ,s1 = vS1
+ ,s2 = vS2
+ ,s3 = vS3
+ ,s4 = vS4
+ ,s5 = vS5
+ ,s6 = vS6
+ ,k1 = vK1
+ ,k2 = vK2
+ ,k3 = vP1
+ ,k4 = vP2
+ ,auction = vAuction
+ ,package = vPackage
+ ,putOrderFk = vPutOrderFk;
+
+ -- If it exists duplicado updates it
+
+ IF NOT vIsDuplicated
+ THEN
+ SET vEkt = LAST_INSERT_ID();
+ CALL ekt_load (vEkt);
+
+ ELSEIF vDeliveryNumber != 0
+ AND vDeliveryNumber IS NOT NULL
+ THEN
+ SELECT id INTO vEkt
+ FROM ekt
+ WHERE deliveryNumber = vDeliveryNumber;
+
+ SELECT COUNT(*) = 0 INTO vUpdateExistent
+ FROM ekt t
+ JOIN `exchange` b ON b.ektFk = t.id
+ JOIN exchangeConfig c
+ WHERE t.deliveryNumber = vDeliveryNumber
+ AND t.entryYear = YEAR(vDate)
+ AND b.typeFk != c.presaleFk;
+ END IF;
+
+ IF vUpdateExistent
+ THEN
+ UPDATE ekt SET
+ barcode = IFNULL(vBarcode, barcode)
+ ,fec = vDate
+ ,hor = vHour
+ ,ref = vRef
+ ,item = vItem
+ ,agj = vAgj
+ ,cat = vCat
+ ,pac = vPac
+ ,sub = vSub
+ ,kop = vKop
+ ,ptd = vPtd
+ ,pro = vPro
+ ,ori = vOrigin
+ ,ptj = vPtj
+ ,qty = vQuantiy
+ ,pri = vPrice
+ ,klo = vClock
+ ,s1 = vS1
+ ,s2 = vS2
+ ,s3 = vS3
+ ,s4 = vS4
+ ,s5 = vS5
+ ,s6 = vS6
+ ,k1 = vK1
+ ,k2 = vK2
+ ,k3 = vP1
+ ,k4 = vP2
+ ,auction = vAuction
+ ,package = vPackage
+ ,putOrderFk = IFNULL(vPutOrderFk, putOrderFk)
+ WHERE id = vEkt;
+ END IF;
+
+ -- Registers the exchange
+
+ INSERT INTO `exchange` SET
+ mailFk = vMailFk
+ ,typeFk = vType
+ ,ektFk = vEkt;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -11840,30 +11840,30 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_listAllocation`(IN `vWh` TINYINT, IN `vDate` DATE, IN `vType` INT, IN `vPrefix` VARCHAR(255), IN `vUseIds` BOOLEAN)
-BEGIN
-/**
- * Lists visible items and it's box sizes of the specified
- * type at specified date.
- *
- * @param vWh The warehouse id
- * @param vDate The visible date
- * @param vType The type id
- * @param vPrefix The article prefix to filter or %NULL for all
- * @param vUseIds Whether to order the result by item id
- * @select List of visible items with it's box sizes
- */
- CALL item_getVisible(vWh, vDate, vType, vPrefix);
-
- IF vUseIds
- THEN
- SELECT * FROM tmp.itemVisible
- ORDER BY Id_Article;
- ELSE
- SELECT * FROM tmp.itemVisible
- ORDER BY Article, packing;
- END IF;
-
- DROP TEMPORARY TABLE tmp.itemVisible;
+BEGIN
+/**
+ * Lists visible items and it's box sizes of the specified
+ * type at specified date.
+ *
+ * @param vWh The warehouse id
+ * @param vDate The visible date
+ * @param vType The type id
+ * @param vPrefix The article prefix to filter or %NULL for all
+ * @param vUseIds Whether to order the result by item id
+ * @select List of visible items with it's box sizes
+ */
+ CALL item_getVisible(vWh, vDate, vType, vPrefix);
+
+ IF vUseIds
+ THEN
+ SELECT * FROM tmp.itemVisible
+ ORDER BY Id_Article;
+ ELSE
+ SELECT * FROM tmp.itemVisible
+ ORDER BY Article, packing;
+ END IF;
+
+ DROP TEMPORARY TABLE tmp.itemVisible;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -13144,9 +13144,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 ;;
@@ -13162,7 +13162,7 @@ BEGIN
DECLARE vOk BOOL;
DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vWarehouse INT;
- DECLARE vShipment DATETIME;
+ DECLARE vShipment DATE;
DECLARE vTicket INT;
DECLARE vNotes VARCHAR(255);
DECLARE vItem INT;
@@ -16842,7 +16842,7 @@ CREATE TABLE `clientesProveedores` (
`IBAN` varchar(34) COLLATE utf8_unicode_ci NOT NULL,
`CodigoCondiciones` smallint(6) NOT NULL,
`StatusTraspasadoIME` tinyint(4) NOT NULL,
- `TipoImportacionIME` tinyint(4) NOT NULL,
+ `TipoImportacionIME` tinyint(4) NOT NULL DEFAULT '2',
`TipoPlanCuentaIME` smallint(6) NOT NULL DEFAULT '2',
`Contrapartida` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`CodigoCuentaImpagado` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
@@ -17481,8 +17481,7 @@ BEGIN
*/
TRUNCATE XDiario_movConta_IVA;
- DELETE FROM movConta WHERE enlazadoSage = FALSE ;
-
+ DELETE FROM movConta WHERE enlazadoSage = FALSE AND Asiento <> 1 ;
CALL clientesProveedoresAdd;
CALL planCuentasPgcAdd;
CALL XDiario_movConta_IVA_InvoiceOutAdd_Manager;
@@ -17588,7 +17587,7 @@ BEGIN
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)
- IFNULL(xmi.CodigoDivisa, sub3.code) CodigoDivisa, -- VARCHAR(3)
+ 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)
@@ -17675,6 +17674,7 @@ BEGIN
LEFT JOIN ( SELECT DISTINCT(account),cu.code
FROM vn.bank b
JOIN vn.currency cu ON cu.id = b.currencyFk
+ WHERE cu.code <> "EUR" -- no se informa cuando la divisa en EUR
)sub3 ON sub3.account = x.SUBCTA
WHERE x.enlazadoSage = 0
AND c.companyCode;
@@ -20786,8 +20786,8 @@ DELIMITER ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `log_add_beta__`(IN `vTableName` VARCHAR(255), IN `vNewId` VARCHAR(255), IN `vOldId` VARCHAR(255))
-proc: BEGIN
- -- XXX: Disabled while testing
+proc: BEGIN
+ -- XXX: Disabled while testing
DECLARE vLanded DATE;
DECLARE vWarehouseFk INT;
DECLARE vBuyerFk INT;
@@ -20795,20 +20795,20 @@ proc: BEGIN
DECLARE vItemFk INT;
DECLARE vItemName VARCHAR(50);
- -- LEAVE proc;
+ -- LEAVE proc;
- IF vOldId IS NOT NULL AND !(vOldId <=> vNewId) THEN
- INSERT IGNORE INTO `log` SET
- tableName = vTableName,
- tableId = vOldId,
- operation = 'delete';
- END IF;
-
- IF vNewId IS NOT NULL THEN
- INSERT IGNORE INTO `log` SET
- tableName = vTableName,
- tableId = vNewId,
- operation = 'insert';
+ IF vOldId IS NOT NULL AND !(vOldId <=> vNewId) THEN
+ INSERT IGNORE INTO `log` SET
+ tableName = vTableName,
+ tableId = vOldId,
+ operation = 'delete';
+ END IF;
+
+ IF vNewId IS NOT NULL THEN
+ INSERT IGNORE INTO `log` SET
+ tableName = vTableName,
+ tableId = vNewId,
+ operation = 'insert';
END IF;
IF vTableName = 'buy' THEN
@@ -20838,7 +20838,7 @@ proc: BEGIN
END IF;
END IF;
-
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -21106,29 +21106,29 @@ CREATE DEFINER=`root`@`%` PROCEDURE `log_refreshSale`(
BEGIN
DROP TEMPORARY TABLE IF EXISTS tValues;
CREATE TEMPORARY TABLE tValues
- ENGINE = MEMORY
- SELECT
- m.id saleFk,
- m.ticketFk,
- m.itemFk,
- t.warehouseFk,
- t.shipped,
+ ENGINE = MEMORY
+ SELECT
+ m.id saleFk,
+ m.ticketFk,
+ m.itemFk,
+ t.warehouseFk,
+ t.shipped,
ABS(m.quantity) quantity,
m.created,
TIMESTAMPADD(DAY, tp.life, t.shipped) expired,
m.quantity < 0 isIn,
- m.isPicked OR s.alertLevel > 1 isPicked
- FROM vn.sale m
- JOIN vn.ticket t ON t.id = m.ticketFk
+ m.isPicked OR s.alertLevel > 1 isPicked
+ FROM vn.sale m
+ JOIN vn.ticket t ON t.id = m.ticketFk
JOIN vn.ticketState s ON s.ticketFk = t.id
JOIN vn.item i ON i.id = m.itemFk
- JOIN vn.itemType tp ON tp.id = i.typeFk
+ JOIN vn.itemType tp ON tp.id = i.typeFk
WHERE (
- vTableId IS NULL
- OR (vTableName = 'ticket' AND t.id = vTableId)
- OR (vTableName = 'sale' AND m.id = vTableId)
- )
- AND t.shipped >= vn.getInventoryDate()
+ vTableId IS NULL
+ OR (vTableName = 'ticket' AND t.id = vTableId)
+ OR (vTableName = 'sale' AND m.id = vTableId)
+ )
+ AND t.shipped >= vn.getInventoryDate()
AND m.quantity != 0;
REPLACE INTO inbound (
@@ -21161,7 +21161,7 @@ BEGIN
FROM tValues
WHERE !isIn;
- DROP TEMPORARY TABLE tValues;
+ DROP TEMPORARY TABLE tValues;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -28242,10 +28242,10 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeUpdate` BEFORE UPDATE ON `vn`.`invoiceOut` FOR EACH ROW
-BEGIN
-CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
-CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount);
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeUpdate` BEFORE UPDATE ON `vn`.`invoiceOut` FOR EACH ROW
+BEGIN
+CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
+CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount);
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30637,6 +30637,100 @@ CREATE TABLE `payMethod` (
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `payment`
+--
+
+DROP TABLE IF EXISTS `payment`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `payment` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `received` date NOT NULL,
+ `supplierFk` int(11) NOT NULL,
+ `amount` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ `divisa` decimal(10,2) DEFAULT NULL,
+ `bankFk` int(11) NOT NULL DEFAULT '0',
+ `payMethodFk` tinyint(3) unsigned NOT NULL,
+ `bankingFees` double(6,2) unsigned NOT NULL DEFAULT '0.00',
+ `concept` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442',
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `isConciliated` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0',
+ `exchangeInsuranceFk` int(11) DEFAULT NULL,
+ `dueDated` date DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `empresa_id` (`companyFk`),
+ KEY `id_banco` (`bankFk`),
+ KEY `id_moneda` (`currencyFk`),
+ KEY `pay_met` (`payMethodFk`),
+ KEY `fk_pago_pago_sdc1_idx` (`exchangeInsuranceFk`),
+ KEY `pagoDueDatedIdx` (`dueDated`),
+ KEY `pago_ibfk_3` (`supplierFk`),
+ CONSTRAINT `pago_ibfk_3` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `pago_moneda_1` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `pago_pay_met` FOREIGN KEY (`payMethodFk`) REFERENCES `payMethod` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `payment_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `bank` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!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 `payment_beforeInsert` BEFORE INSERT ON `payment` FOR EACH ROW
+-- Edit trigger body code below this line. Do not edit lines above this one
+BEGIN
+ DECLARE cuenta_banco,cuenta_proveedor DOUBLE;
+ DECLARE vNewBookEntry INT;
+ DECLARE bolCASH BOOLEAN;
+
+ -- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH
+ SELECT (cash = 1) INTO bolCASH FROM bank WHERE bank.id = NEW.bankFk ;
+
+ IF bolCASH THEN
+
+ SELECT account INTO cuenta_banco
+ FROM bank
+ WHERE id = NEW.bankFk;
+
+ SELECT account INTO cuenta_proveedor
+ FROM supplier
+ WHERE id = NEW.supplierFk;
+
+ CALL vn.ledger_next(vNewBookEntry);
+
+ INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id)
+ SELECT vNewBookEntry,NEW.received,SUBCTA,CONTRA,NEW.concept,EURODEBE,EUROHABER,NEW.companyFk
+ FROM
+ ( SELECT cuenta_banco SUBCTA,cuenta_proveedor CONTRA,0 EURODEBE, NEW.amount + NEW.bankingFees EUROHABER
+ UNION ALL
+ SELECT cuenta_proveedor SUBCTA, cuenta_banco CONTRA,NEW.amount EURODEBE, 0 EUROHABER
+ ) gf;
+
+ IF NEW.bankingFees <> 0 THEN
+ INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id)
+ SELECT vNewBookEntry,NEW.received,IF(c.id = 1,6260000002,IF(CEE = 1,6260000003,6260000004)),cuenta_banco,NEW.concept,NEW.bankingFees,0,NEW.companyFk
+ FROM supplier s
+ JOIN country c ON s.countryFk = c.id
+ WHERE s.id = NEW.supplierFk;
+ END IF;
+ END IF;
+
+ SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
+ END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+
--
-- Temporary table structure for view `payment__`
--
@@ -31635,14 +31729,14 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` AFTER UPDATE ON `receipt` FOR EACH ROW
-BEGIN
- IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN
- INSERT INTO vn.mail(`sender`, subject, `body`)
- SELECT 'finanzas@verdnatura.es',
- CONCAT(' Cambios de recibos del cliente: ', NEW.clientFk),
- CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed);
- END IF;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` AFTER UPDATE ON `receipt` FOR EACH ROW
+BEGIN
+ IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN
+ INSERT INTO vn.mail(`sender`, subject, `body`)
+ SELECT 'finanzas@verdnatura.es',
+ CONCAT(' Cambios de recibos del cliente: ', NEW.clientFk),
+ CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed);
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -33333,7 +33427,26 @@ CREATE TABLE `tag` (
CONSTRAINT `fgnTag` FOREIGN KEY (`ediTypeFk`) REFERENCES `edi`.`type` (`type_id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Categorias para etiquetar los productos';
/*!40101 SET character_set_client = @saved_cs_client */;
-
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!50003 SET character_set_results = utf8 */ ;
+/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`tag_BEFORE_INSERT` BEFORE INSERT ON `tag` FOR EACH ROW
+BEGIN
+ IF NEW.ediTypeFk IS NULL AND (SELECT COUNT(*) FROM tag WHERE `name` = NEW.`name`) THEN
+ CALL util.throw('name duplicated');
+ END IF;
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Table structure for table `tagAbbreviation`
@@ -33622,7 +33735,7 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `ticket_beforeUpdate`
BEFORE UPDATE ON `ticket`
@@ -33668,6 +33781,9 @@ BEGIN
' a ',
TIME(NEW.shipped));
END IF;
+ INSERT IGNORE INTO zoneAgencyMode (agencyModeFk,zoneFk)
+ SELECT r.agencyModeFk, NEW.zoneFk FROM route r
+ WHERE r.id = NEW.routeFk;
END IF;
END */;;
DELIMITER ;
@@ -36110,6 +36226,25 @@ CREATE TABLE `zone` (
) ENGINE=InnoDBDEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `zoneAgencyMode`
+--
+
+DROP TABLE IF EXISTS `zoneAgencyMode`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `zoneAgencyMode` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `agencyModeFk` int(11) NOT NULL,
+ `zoneFk` int(11) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `zoneAgencyMode_UN` (`agencyModeFk`,`zoneFk`),
+ KEY `zoneAgencyMode_FK_1` (`zoneFk`),
+ CONSTRAINT `zoneAgencyMode_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `zoneAgencyMode_FK_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='junta agencias con zonas para que al enrutar se puedan proponer tickets.';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `zoneClosure`
--
@@ -36434,90 +36569,90 @@ DELIMITER ;;
/*!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
-
- DECLARE vCurrentCount INT;
- DECLARE vCheckSum INT;
- DECLARE vIsAlreadyNotified BOOLEAN;
- DECLARE vTableQueue TEXT;
- DECLARE vLineQueue TEXT;
- DECLARE vDone BOOL DEFAULT FALSE;
- DECLARE vCur CURSOR FOR
- SELECT CONCAT('
- ', IFNULL(pq.id, ''), ' |
- ', IFNULL(p.path, ''),' |
- ', IFNULL(i.Informe, ''),' |
- ', IFNULL(e.Estado, ''),' |
- ', IFNULL(w.firstname, ''), " ", IFNULL(w.lastName, ''),' |
- ', IFNULL(pq.`error`, ''),' |
-
')
- FROM vn.printingQueue pq
- LEFT JOIN vn.worker w ON w.id = pq.worker
- LEFT JOIN vn.printer p ON p.id = pq.printer
- LEFT JOIN vn2008.Informes i ON i.Id_Informe = pq.report
- JOIN vn2008.Estados e ON e.Id_Estado = pq.state
- LIMIT 30;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- SET vDone = TRUE;
-
- SELECT COUNT(*), IFNULL(SUM(id),0) INTO vCurrentCount, vCheckSum
- FROM vn.printingQueue WHERE state = 1;
-
- SELECT isAlreadyNotified INTO vIsAlreadyNotified
- FROM printingQueueCheck;
-
- IF (SELECT lastCount FROM printingQueueCheck) = vCurrentCount AND
- (SELECT lastCheckSum FROM printingQueueCheck) = vCheckSum AND
- vIsAlreadyNotified = FALSE AND vCurrentCount > 0
- THEN
-
- SELECT '
-
- Id Cola |
- Ruta Impresora |
- Informe |
- Estado |
- Trabajador |
- Error |
-
' INTO vTableQueue;
-
- OPEN vCur;
-
- l: LOOP
-
- SET vDone = FALSE;
-
- FETCH vCur INTO vLineQueue;
-
- IF vDone THEN
- LEAVE l;
- END IF;
-
- SELECT CONCAT(vTableQueue, vLineQueue) INTO vTableQueue;
-
- END LOOP;
-
- CLOSE vCur;
-
- INSERT INTO vn2008.mail (`to`, subject, text)
- VALUES ('cau@verdnatura.es, sysadmin@verdnatura.es',
- 'servidor de impresion parado',
- CONCAT('Hay ', vCurrentCount, ' lineas bloqueadas', vTableQueue, '
'));
-
- UPDATE printingQueueCheck SET isAlreadyNotified = TRUE;
- END IF;
-
- IF (SELECT lastCount FROM printingQueueCheck) > vCurrentCount AND
- vIsAlreadyNotified = TRUE
- THEN
- UPDATE printingQueueCheck SET isAlreadyNotified = FALSE;
- END IF;
-
- UPDATE printingQueueCheck
- SET lastCount = vCurrentCount,
- lastCheckSum = vCheckSum;
-
+/*!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
+
+ DECLARE vCurrentCount INT;
+ DECLARE vCheckSum INT;
+ DECLARE vIsAlreadyNotified BOOLEAN;
+ DECLARE vTableQueue TEXT;
+ DECLARE vLineQueue TEXT;
+ DECLARE vDone BOOL DEFAULT FALSE;
+ DECLARE vCur CURSOR FOR
+ SELECT CONCAT('
+ ', IFNULL(pq.id, ''), ' |
+ ', IFNULL(p.path, ''),' |
+ ', IFNULL(i.Informe, ''),' |
+ ', IFNULL(e.Estado, ''),' |
+ ', IFNULL(w.firstname, ''), " ", IFNULL(w.lastName, ''),' |
+ ', IFNULL(pq.`error`, ''),' |
+
')
+ FROM vn.printingQueue pq
+ LEFT JOIN vn.worker w ON w.id = pq.worker
+ LEFT JOIN vn.printer p ON p.id = pq.printer
+ LEFT JOIN vn2008.Informes i ON i.Id_Informe = pq.report
+ JOIN vn2008.Estados e ON e.Id_Estado = pq.state
+ LIMIT 30;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND
+ SET vDone = TRUE;
+
+ SELECT COUNT(*), IFNULL(SUM(id),0) INTO vCurrentCount, vCheckSum
+ FROM vn.printingQueue WHERE state = 1;
+
+ SELECT isAlreadyNotified INTO vIsAlreadyNotified
+ FROM printingQueueCheck;
+
+ IF (SELECT lastCount FROM printingQueueCheck) = vCurrentCount AND
+ (SELECT lastCheckSum FROM printingQueueCheck) = vCheckSum AND
+ vIsAlreadyNotified = FALSE AND vCurrentCount > 0
+ THEN
+
+ SELECT '
+
+ Id Cola |
+ Ruta Impresora |
+ Informe |
+ Estado |
+ Trabajador |
+ Error |
+
' INTO vTableQueue;
+
+ OPEN vCur;
+
+ l: LOOP
+
+ SET vDone = FALSE;
+
+ FETCH vCur INTO vLineQueue;
+
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+
+ SELECT CONCAT(vTableQueue, vLineQueue) INTO vTableQueue;
+
+ END LOOP;
+
+ CLOSE vCur;
+
+ INSERT INTO vn2008.mail (`to`, subject, text)
+ VALUES ('cau@verdnatura.es, sysadmin@verdnatura.es',
+ 'servidor de impresion parado',
+ CONCAT('Hay ', vCurrentCount, ' lineas bloqueadas', vTableQueue, '
'));
+
+ UPDATE printingQueueCheck SET isAlreadyNotified = TRUE;
+ END IF;
+
+ IF (SELECT lastCount FROM printingQueueCheck) > vCurrentCount AND
+ vIsAlreadyNotified = TRUE
+ THEN
+ UPDATE printingQueueCheck SET isAlreadyNotified = FALSE;
+ END IF;
+
+ UPDATE printingQueueCheck
+ SET lastCount = vCurrentCount,
+ lastCheckSum = vCheckSum;
+
END */ ;;
/*!50003 SET time_zone = @saved_time_zone */ ;;
/*!50003 SET sql_mode = @saved_sql_mode */ ;;
@@ -36590,27 +36725,27 @@ DELIMITER ;;
/*!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 `workerTimeControl_sendMail` ON SCHEDULE EVERY 1 WEEK STARTS '2020-11-25 08:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
- DECLARE vDone BOOL;
- DECLARE vWeek,vYear INT;
- DECLARE rs CURSOR FOR
- SELECT week,year
- FROM vn.time
- WHERE dated IN (DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL -4 DAY))
- GROUP BY year,week;
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- SET vDone = TRUE;
-
- OPEN rs;
- myLoop: LOOP
- SET vDone = FALSE;
- FETCH rs INTO vWeek, vYear;
- IF vDone THEN
- LEAVE myLoop;
- END IF;
- CALL vn.workerTimeControl_sendMail(vWeek, vYear, NULL);
- END LOOP;
- CLOSE rs;
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `workerTimeControl_sendMail` ON SCHEDULE EVERY 1 WEEK STARTS '2020-11-25 08:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ DECLARE vDone BOOL;
+ DECLARE vWeek,vYear INT;
+ DECLARE rs CURSOR FOR
+ SELECT week,year
+ FROM vn.time
+ WHERE dated IN (DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL -4 DAY))
+ GROUP BY year,week;
+ DECLARE CONTINUE HANDLER FOR NOT FOUND
+ SET vDone = TRUE;
+
+ OPEN rs;
+ myLoop: LOOP
+ SET vDone = FALSE;
+ FETCH rs INTO vWeek, vYear;
+ IF vDone THEN
+ LEAVE myLoop;
+ END IF;
+ CALL vn.workerTimeControl_sendMail(vWeek, vYear, NULL);
+ END LOOP;
+ CLOSE rs;
END */ ;;
/*!50003 SET time_zone = @saved_time_zone */ ;;
/*!50003 SET sql_mode = @saved_sql_mode */ ;;
@@ -37780,69 +37915,69 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`z-developer`@`%` FUNCTION `ekt_getEntry`(vEktFk INT) RETURNS int(11)
READS SQL DATA
-BEGIN
- DECLARE vTravelFk INT;
- DECLARE vEntryFk INT DEFAULT 0;
- DECLARE vEntryAssignFk INT;
-
- SET vTravelFk = vn.ekt_getTravel(vEktFk);
-
- IF vTravelFk THEN
-
- SELECT ea.id INTO vEntryAssignFk
- FROM edi.ekt e
- JOIN vn.travel tr ON tr.id = vTravelFk
- JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk
- AND ea.warehouseInFk = tr.warehouseInFk
- AND ea.agencyModeFk = tr.agencyFk
- AND IFNULL(ea.sub, e.sub) <=> e.sub
- AND IFNULL(ea.kop, e.kop) <=> e.kop
- AND IFNULL(ea.pro, e.pro) <=> e.pro
- WHERE e.id = vEktFk
- ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
- ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
- ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC,
- ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC,
- ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
- ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
- ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC
- LIMIT 1;
-
- SELECT MAX(e.id) INTO vEntryFk
- FROM vn.entry e
- JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk
- WHERE e.travelFk = vTravelFk
- AND e.sub <=> ea.sub
- AND e.kop <=> ea.kop
- AND e.pro <=> ea.pro;
-
-
- IF IFNULL(vEntryFk,0) = 0 THEN
-
- INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro)
- SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro
- FROM vn.ektEntryAssign ea
- JOIN vn.company c ON c.code = 'VNL'
- JOIN vn.currency cu ON cu.code = 'EUR'
- WHERE ea.id = vEntryAssignFk;
-
- SELECT MAX(id) INTO vEntryFk
- FROM vn.entry
- WHERE travelFk = vTravelFk;
-
- END IF;
-
- UPDATE vn.ektEntryAssign
- SET entryFk = vEntryFk
- WHERE id = vEntryAssignFk;
-
- ELSE
-
- SET vEntryFk = 9200;
-
- END IF;
-
- RETURN vEntryFk;
+BEGIN
+ DECLARE vTravelFk INT;
+ DECLARE vEntryFk INT DEFAULT 0;
+ DECLARE vEntryAssignFk INT;
+
+ SET vTravelFk = vn.ekt_getTravel(vEktFk);
+
+ IF vTravelFk THEN
+
+ SELECT ea.id INTO vEntryAssignFk
+ FROM edi.ekt e
+ JOIN vn.travel tr ON tr.id = vTravelFk
+ JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk
+ AND ea.warehouseInFk = tr.warehouseInFk
+ AND ea.agencyModeFk = tr.agencyFk
+ AND IFNULL(ea.sub, e.sub) <=> e.sub
+ AND IFNULL(ea.kop, e.kop) <=> e.kop
+ AND IFNULL(ea.pro, e.pro) <=> e.pro
+ WHERE e.id = vEktFk
+ ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
+ ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
+ ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC,
+ ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC,
+ ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
+ ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
+ ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC
+ LIMIT 1;
+
+ SELECT MAX(e.id) INTO vEntryFk
+ FROM vn.entry e
+ JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk
+ WHERE e.travelFk = vTravelFk
+ AND e.sub <=> ea.sub
+ AND e.kop <=> ea.kop
+ AND e.pro <=> ea.pro;
+
+
+ IF IFNULL(vEntryFk,0) = 0 THEN
+
+ INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro)
+ SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro
+ FROM vn.ektEntryAssign ea
+ JOIN vn.company c ON c.code = 'VNL'
+ JOIN vn.currency cu ON cu.code = 'EUR'
+ WHERE ea.id = vEntryAssignFk;
+
+ SELECT MAX(id) INTO vEntryFk
+ FROM vn.entry
+ WHERE travelFk = vTravelFk;
+
+ END IF;
+
+ UPDATE vn.ektEntryAssign
+ SET entryFk = vEntryFk
+ WHERE id = vEntryAssignFk;
+
+ ELSE
+
+ SET vEntryFk = 9200;
+
+ END IF;
+
+ RETURN vEntryFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -37861,69 +37996,69 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`z-developer`@`%` FUNCTION `ekt_getEntry_beta`(vEktFk INT) RETURNS int(11)
READS SQL DATA
-BEGIN
- DECLARE vTravelFk INT;
- DECLARE vEntryFk INT DEFAULT 0;
- DECLARE vEntryAssignFk INT;
-
- SET vTravelFk = vn.ekt_getTravel(vEktFk);
-
- IF vTravelFk THEN
-
- SELECT ea.id INTO vEntryAssignFk
- FROM edi.ekt e
- JOIN vn.travel tr ON tr.id = vTravelFk
- JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk
- AND ea.warehouseInFk = tr.warehouseInFk
- AND ea.agencyModeFk = tr.agencyFk
- AND IFNULL(ea.sub, e.sub) <=> e.sub
- AND IFNULL(ea.kop, e.kop) <=> e.kop
- AND IFNULL(ea.pro, e.pro) <=> e.pro
- WHERE e.id = vEktFk
- ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
- ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
- ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC,
- ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC,
- ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
- ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
- ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC
- LIMIT 1;
-
- SELECT MAX(e.id) INTO vEntryFk
- FROM vn.entry e
- JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk
- WHERE e.travelFk = vTravelFk
- AND e.sub <=> ea.sub
- AND e.kop <=> ea.kop
- AND e.pro <=> ea.pro;
-
-
- IF IFNULL(vEntryFk,0) = 0 THEN
-
- INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro)
- SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro
- FROM vn.ektEntryAssign ea
- JOIN vn.company c ON c.code = 'VNL'
- JOIN vn.currency cu ON cu.code = 'EUR'
- WHERE ea.id = vEntryAssignFk;
-
- SELECT MAX(id) INTO vEntryFk
- FROM vn.entry
- WHERE travelFk = vTravelFk;
-
- END IF;
-
- UPDATE vn.ektEntryAssign
- SET entryFk = vEntryFk
- WHERE id = vEntryAssignFk;
-
- ELSE
-
- SET vEntryFk = 9200;
-
- END IF;
-
- RETURN vEntryFk;
+BEGIN
+ DECLARE vTravelFk INT;
+ DECLARE vEntryFk INT DEFAULT 0;
+ DECLARE vEntryAssignFk INT;
+
+ SET vTravelFk = vn.ekt_getTravel(vEktFk);
+
+ IF vTravelFk THEN
+
+ SELECT ea.id INTO vEntryAssignFk
+ FROM edi.ekt e
+ JOIN vn.travel tr ON tr.id = vTravelFk
+ JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk
+ AND ea.warehouseInFk = tr.warehouseInFk
+ AND ea.agencyModeFk = tr.agencyFk
+ AND IFNULL(ea.sub, e.sub) <=> e.sub
+ AND IFNULL(ea.kop, e.kop) <=> e.kop
+ AND IFNULL(ea.pro, e.pro) <=> e.pro
+ WHERE e.id = vEktFk
+ ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
+ ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
+ ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC,
+ ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC,
+ ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
+ ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
+ ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC
+ LIMIT 1;
+
+ SELECT MAX(e.id) INTO vEntryFk
+ FROM vn.entry e
+ JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk
+ WHERE e.travelFk = vTravelFk
+ AND e.sub <=> ea.sub
+ AND e.kop <=> ea.kop
+ AND e.pro <=> ea.pro;
+
+
+ IF IFNULL(vEntryFk,0) = 0 THEN
+
+ INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro)
+ SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro
+ FROM vn.ektEntryAssign ea
+ JOIN vn.company c ON c.code = 'VNL'
+ JOIN vn.currency cu ON cu.code = 'EUR'
+ WHERE ea.id = vEntryAssignFk;
+
+ SELECT MAX(id) INTO vEntryFk
+ FROM vn.entry
+ WHERE travelFk = vTravelFk;
+
+ END IF;
+
+ UPDATE vn.ektEntryAssign
+ SET entryFk = vEntryFk
+ WHERE id = vEntryAssignFk;
+
+ ELSE
+
+ SET vEntryFk = 9200;
+
+ END IF;
+
+ RETURN vEntryFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -39700,17 +39835,17 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `item_getFhImage`(itemFk INT) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
- DECLARE vImageUrl VARCHAR(255);
- SELECT sr.PictureReference INTO vImageUrl
- FROM vn.buy b
- JOIN edi.ekt e ON b.ektFk = e.id
- JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref`
- JOIN vn.item i ON i.id = b.itemFk
- WHERE b.itemFk = itemFk
- ORDER BY (sr.EmbalageCode = e.package) DESC
- LIMIT 1;
- RETURN vImageUrl;
+BEGIN
+ DECLARE vImageUrl VARCHAR(255);
+ SELECT sr.PictureReference INTO vImageUrl
+ FROM vn.buy b
+ JOIN edi.ekt e ON b.ektFk = e.id
+ JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref`
+ JOIN vn.item i ON i.id = b.itemFk
+ WHERE b.itemFk = itemFk
+ ORDER BY (sr.EmbalageCode = e.package) DESC
+ LIMIT 1;
+ RETURN vImageUrl;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40362,7 +40497,7 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` FUNCTION `ticketSplitCounter`(vTicketFk INT) RETURNS varchar(15) CHARSET utf8 COLLATE utf8_unicode_ci
+CREATE DEFINER=`root`@`%` FUNCTION `ticketSplitCounter`(vTicketFk INT) RETURNS varchar(15) CHARSET utf8
READS SQL DATA
BEGIN
DECLARE vSplitCounter VARCHAR(15);
@@ -40375,7 +40510,9 @@ BEGIN
LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id
WHERE ticketFk = vTicketFk
) sub;
- RETURN vSplitCounter;
+
+ RETURN IFNULL(vSplitCounter,'--');
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40761,13 +40898,13 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`z-sysadmin`@`%` FUNCTION `time_getSalesYear`(vMonth INT, vYear INT) RETURNS int(11)
DETERMINISTIC
-BEGIN
-DECLARE vSalesYear INT;
-SELECT salesYear INTO vSalesYear
-FROM `time`
-WHERE `month` = vMonth AND `year` = vYear
-LIMIT 1;
-RETURN vSalesYear;
+BEGIN
+DECLARE vSalesYear INT;
+SELECT salesYear INTO vSalesYear
+FROM `time`
+WHERE `month` = vMonth AND `year` = vYear
+LIMIT 1;
+RETURN vSalesYear;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -42906,10 +43043,10 @@ proc: BEGIN
FROM edi.warehouseFloramondo
WHERE warehouseFk = vWarehouseFk;
- CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk);
-
+ CALL cache.visible_refresh(vVisibleCache, TRUE, vWarehouseFk);
+
IF (NOT vIsLogifloraAllowed AND vVNHWarehouseFk != vWarehouseFk)
- OR (vShipped > TIMESTAMPADD(DAY, vMaxLogifloraDays + vRangeLogifloraDays, CURDATE()) )
+ OR (vShipped > TIMESTAMPADD(DAY, vMaxLogifloraDays + vRangeLogifloraDays, CURDATE()) )
THEN
DELETE tl FROM tmp.ticketLot tl
JOIN item i ON i.id = tl.itemFk
@@ -48255,216 +48392,216 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `entryConverter`(IN `vEntry` INT)
-BEGIN
-
- DECLARE vWarehouseIn INT;
- DECLARE vWarehouseOut INT;
- DECLARE vTravel INT;
-
- DECLARE done BOOL DEFAULT FALSE;
-
- DECLARE vId_Entrada INT;
- DECLARE vId_Article INT;
- DECLARE vEtiquetas INT;
- DECLARE vId_Cubo VARCHAR(10);
- DECLARE vPacking INT;
- DECLARE vGrouping INT;
- DECLARE vCantidad INT;
- DECLARE vCostefijo DECIMAL(10,3);
- DECLARE vPortefijo DECIMAL(10,3);
- DECLARE vEmbalajefijo DECIMAL(10);
- DECLARE vComisionfija DECIMAL(10,3);
- DECLARE vCaja INT;
- DECLARE vNicho VARCHAR(5);
- DECLARE vTarifa1 DECIMAL(10,2);
- DECLARE vTarifa2 DECIMAL(10,2);
- DECLARE vTarifa3 DECIMAL(10,2);
- DECLARE vPVP DECIMAL(10,2);
- DECLARE vCompra INT;
-
- DECLARE rs CURSOR FOR
- SELECT
- b.Id_Entrada,
- b.Id_Article,
- b.Etiquetas,
- b.Id_Cubo,
- b.Packing,
- b.`grouping`,
- b.Cantidad,
- b.Costefijo,
- b.Portefijo,
- b.Embalajefijo,
- b.Comisionfija,
- b.caja,
- b.Nicho,
- b.Tarifa1,
- b.Tarifa2,
- b.Tarifa3,
- b.PVP
- FROM vn2008.Compres b
- JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article
- WHERE Id_Entrada = vEntry;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- SELECT warehouseInFk, warehouseOutFk, tr.id
- INTO vWarehouseIn, vWarehouseOut, vTravel
- FROM travel tr
- JOIN entry e ON e.travelFk = tr.id
- WHERE e.id = vEntry;
-
- UPDATE travel
- SET warehouseInFk = vWarehouseOut,
- warehouseOutFk = vWarehouseIn
- WHERE id = vTravel;
-
- UPDATE vn2008.Compres c
- LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article
- SET Etiquetas = 0, Cantidad = 0
- WHERE c.Id_Entrada = vEntry
- AND ic.espItemFk IS NULL;
-
- OPEN rs;
-
- DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry;
-
- FETCH rs INTO
- vId_Entrada,
- vId_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP;
-
- WHILE NOT done DO
-
- -- Primero la linea original con las cantidades invertidas
- INSERT INTO vn2008.Compres
- (
- Id_Entrada,
- Id_Article,
- Etiquetas,
- Id_Cubo,
- Packing,
- `grouping`,
- Cantidad,
- Costefijo,
- Portefijo,
- Embalajefijo,
- Comisionfija,
- caja,
- Nicho,
- Tarifa1,
- Tarifa2,
- Tarifa3,
- PVP
- )
- VALUES
- (
- vId_Entrada,
- vId_Article,
- - vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- - vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP);
-
- -- Ahora la linea nueva, con el item genérico
- INSERT INTO vn2008.Compres
- (
- Id_Entrada,
- Id_Article,
- Etiquetas,
- Id_Cubo,
- Packing,
- `grouping`,
- Cantidad,
- Costefijo,
- Portefijo,
- Embalajefijo,
- Comisionfija,
- caja,
- Nicho,
- Tarifa1,
- Tarifa2,
- Tarifa3,
- PVP
- )
- SELECT
- vId_Entrada,
- genItemFk as Id_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP
- FROM itemConversor
- WHERE espItemFk = vId_Article;
-
- SELECT LAST_INSERT_ID()
- INTO vCompra;
-
- REPLACE vn2008.Compres_mark(Id_Compra,`comment`)
- SELECT vCompra, vId_Article;
-
-
- FETCH rs INTO
- vId_Entrada,
- vId_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP;
-
- END WHILE;
-
-
- CLOSE rs;
-
-
-
+BEGIN
+
+ DECLARE vWarehouseIn INT;
+ DECLARE vWarehouseOut INT;
+ DECLARE vTravel INT;
+
+ DECLARE done BOOL DEFAULT FALSE;
+
+ DECLARE vId_Entrada INT;
+ DECLARE vId_Article INT;
+ DECLARE vEtiquetas INT;
+ DECLARE vId_Cubo VARCHAR(10);
+ DECLARE vPacking INT;
+ DECLARE vGrouping INT;
+ DECLARE vCantidad INT;
+ DECLARE vCostefijo DECIMAL(10,3);
+ DECLARE vPortefijo DECIMAL(10,3);
+ DECLARE vEmbalajefijo DECIMAL(10);
+ DECLARE vComisionfija DECIMAL(10,3);
+ DECLARE vCaja INT;
+ DECLARE vNicho VARCHAR(5);
+ DECLARE vTarifa1 DECIMAL(10,2);
+ DECLARE vTarifa2 DECIMAL(10,2);
+ DECLARE vTarifa3 DECIMAL(10,2);
+ DECLARE vPVP DECIMAL(10,2);
+ DECLARE vCompra INT;
+
+ DECLARE rs CURSOR FOR
+ SELECT
+ b.Id_Entrada,
+ b.Id_Article,
+ b.Etiquetas,
+ b.Id_Cubo,
+ b.Packing,
+ b.`grouping`,
+ b.Cantidad,
+ b.Costefijo,
+ b.Portefijo,
+ b.Embalajefijo,
+ b.Comisionfija,
+ b.caja,
+ b.Nicho,
+ b.Tarifa1,
+ b.Tarifa2,
+ b.Tarifa3,
+ b.PVP
+ FROM vn2008.Compres b
+ JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article
+ WHERE Id_Entrada = vEntry;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ SELECT warehouseInFk, warehouseOutFk, tr.id
+ INTO vWarehouseIn, vWarehouseOut, vTravel
+ FROM travel tr
+ JOIN entry e ON e.travelFk = tr.id
+ WHERE e.id = vEntry;
+
+ UPDATE travel
+ SET warehouseInFk = vWarehouseOut,
+ warehouseOutFk = vWarehouseIn
+ WHERE id = vTravel;
+
+ UPDATE vn2008.Compres c
+ LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article
+ SET Etiquetas = 0, Cantidad = 0
+ WHERE c.Id_Entrada = vEntry
+ AND ic.espItemFk IS NULL;
+
+ OPEN rs;
+
+ DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry;
+
+ FETCH rs INTO
+ vId_Entrada,
+ vId_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP;
+
+ WHILE NOT done DO
+
+ -- Primero la linea original con las cantidades invertidas
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada,
+ Id_Article,
+ Etiquetas,
+ Id_Cubo,
+ Packing,
+ `grouping`,
+ Cantidad,
+ Costefijo,
+ Portefijo,
+ Embalajefijo,
+ Comisionfija,
+ caja,
+ Nicho,
+ Tarifa1,
+ Tarifa2,
+ Tarifa3,
+ PVP
+ )
+ VALUES
+ (
+ vId_Entrada,
+ vId_Article,
+ - vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ - vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP);
+
+ -- Ahora la linea nueva, con el item genérico
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada,
+ Id_Article,
+ Etiquetas,
+ Id_Cubo,
+ Packing,
+ `grouping`,
+ Cantidad,
+ Costefijo,
+ Portefijo,
+ Embalajefijo,
+ Comisionfija,
+ caja,
+ Nicho,
+ Tarifa1,
+ Tarifa2,
+ Tarifa3,
+ PVP
+ )
+ SELECT
+ vId_Entrada,
+ genItemFk as Id_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP
+ FROM itemConversor
+ WHERE espItemFk = vId_Article;
+
+ SELECT LAST_INSERT_ID()
+ INTO vCompra;
+
+ REPLACE vn2008.Compres_mark(Id_Compra,`comment`)
+ SELECT vCompra, vId_Article;
+
+
+ FETCH rs INTO
+ vId_Entrada,
+ vId_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP;
+
+ END WHILE;
+
+
+ CLOSE rs;
+
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48526,62 +48663,62 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `entryPrepare`(IN `idE` BIGINT)
-BEGIN
- SELECT
- b.quantity / b.packing AS Paquetes,
- b.packing AS `Grouping`,
- barcode,
- 'ASEGURADO' AS asegurado,
- ic.name,
- ic.order,
- s.name AS Consignatario,
- e.supplierFk AS Id_Cliente,
- e.isOrdered,
- e.isConfirmed,
- 10 AS Calidad,
- LPAD(IFNULL(cpd.id, ip.code),
- 5,
- '0') AS path,
- b.entryFk AS Id_Ticket,
- t.landed AS Fecha,
- b.itemFk,
- b.quantity,
- i.name AS Concepte,
- i.size,
- i.inkFk,
- i.category,
- o.code AS Origen,
- 0 AS Bultos,
- wIn.`name` AS Tipo,
- 0 AS OK,
- 0 AS Reservado,
- i.stems,
- b.id AS Id_Movimiento,
- ip.code,
- 'PEDIDO ASEGURADO' AS MSG,
- 0 AS Seguro,
- i.image,
- pr.name AS producer
- FROM vn.buy b
- JOIN vn.entry e ON b.entryFk = e.id
- JOIN vn.travel t ON t.id = e.travelFk
- JOIN vn.warehouse wIn ON wIn.id = t.warehouseInFk
- JOIN vn.warehouse wOut ON wOut.id = t.warehouseOutFk
- JOIN vn.item i ON i.id = b.itemFk
- JOIN vn.itemType it ON it.id =i.typeFk
- JOIN vn.itemCategory ic ON ic.id = it.categoryFk
- JOIN vn.packaging pkg ON pkg.id = b.packageFk
- LEFT JOIN vn.itemPlacement ip ON i.id = ip.itemFk AND ip.warehouseFk = wIn.id AND ip.warehouseFk = t.warehouseOutFk
- LEFT JOIN (SELECT itemFk, code AS barcode FROM vn.itemBarcode GROUP BY itemFk) ib ON ib.itemFk = b.itemFk
- LEFT JOIN vn.origin o ON o.id = i.originFk
- LEFT JOIN vn.supplier s ON s.id = e.supplierFk
- LEFT JOIN vn.producer pr on pr.id = i.producerFk
- LEFT JOIN vn.coolerPathDetail cpd ON LEFT(ip.code, 3) = cpd.hallway
- WHERE
- NOT wIn.isFeedStock AND NOT e.isInventory AND NOT e.isRaid
- AND e.id = 158772
- AND i.typeFk IS NOT NULL
- AND ic.merchandise IS NOT FALSE;
+BEGIN
+ SELECT
+ b.quantity / b.packing AS Paquetes,
+ b.packing AS `Grouping`,
+ barcode,
+ 'ASEGURADO' AS asegurado,
+ ic.name,
+ ic.order,
+ s.name AS Consignatario,
+ e.supplierFk AS Id_Cliente,
+ e.isOrdered,
+ e.isConfirmed,
+ 10 AS Calidad,
+ LPAD(IFNULL(cpd.id, ip.code),
+ 5,
+ '0') AS path,
+ b.entryFk AS Id_Ticket,
+ t.landed AS Fecha,
+ b.itemFk,
+ b.quantity,
+ i.name AS Concepte,
+ i.size,
+ i.inkFk,
+ i.category,
+ o.code AS Origen,
+ 0 AS Bultos,
+ wIn.`name` AS Tipo,
+ 0 AS OK,
+ 0 AS Reservado,
+ i.stems,
+ b.id AS Id_Movimiento,
+ ip.code,
+ 'PEDIDO ASEGURADO' AS MSG,
+ 0 AS Seguro,
+ i.image,
+ pr.name AS producer
+ FROM vn.buy b
+ JOIN vn.entry e ON b.entryFk = e.id
+ JOIN vn.travel t ON t.id = e.travelFk
+ JOIN vn.warehouse wIn ON wIn.id = t.warehouseInFk
+ JOIN vn.warehouse wOut ON wOut.id = t.warehouseOutFk
+ JOIN vn.item i ON i.id = b.itemFk
+ JOIN vn.itemType it ON it.id =i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ JOIN vn.packaging pkg ON pkg.id = b.packageFk
+ LEFT JOIN vn.itemPlacement ip ON i.id = ip.itemFk AND ip.warehouseFk = wIn.id AND ip.warehouseFk = t.warehouseOutFk
+ LEFT JOIN (SELECT itemFk, code AS barcode FROM vn.itemBarcode GROUP BY itemFk) ib ON ib.itemFk = b.itemFk
+ LEFT JOIN vn.origin o ON o.id = i.originFk
+ LEFT JOIN vn.supplier s ON s.id = e.supplierFk
+ LEFT JOIN vn.producer pr on pr.id = i.producerFk
+ LEFT JOIN vn.coolerPathDetail cpd ON LEFT(ip.code, 3) = cpd.hallway
+ WHERE
+ NOT wIn.isFeedStock AND NOT e.isInventory AND NOT e.isRaid
+ AND e.id = 158772
+ AND i.typeFk IS NOT NULL
+ AND ic.merchandise IS NOT FALSE;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59338,77 +59475,77 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `saleItemShelvingMake`(IN `vTicketFk` INT, IN `vSectorFk` INT)
-BEGIN
-
- SET @rest:= CAST(0 AS DECIMAL(10,0));
- SET @saleFk := CAST(0 AS DECIMAL(10,0));
- SET @reserved := CAST(0 AS DECIMAL(10,0));
-
- UPDATE vn.itemShelving ish
- JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
- JOIN sale s ON s.id = sis.saleFk
- SET ish.visible = sis.quantity + ish.visible,
- ish.available = sis.quantity + ish.visible
- WHERE s.ticketFk = vTicketFk;
-
- DELETE sis.*
- FROM saleItemShelving sis
- JOIN sale s ON s.id = sis.saleFk
- WHERE s.ticketFk = vTicketFk;
-
- INSERT INTO saleItemShelving( saleFk,
- itemShelvingFk,
- quantity,
- ubication)
- SELECT saleFk,
- itemShelvingFk,
- CAST(Reserved as DECIMAL(10,0)) as Reserved,
- ubication
- FROM
- (SELECT saleFk,
- itemShelvingFk,
- ubication,
- @rest := IF(@saleFk = saleFk, @rest, quantity) as Falta,
- @reserved := IF(available < @rest, available, IF(@rest < packing,0,@rest)) as Reserved,
- @rest := @rest - @reserved,
- @saleFk := saleFk
- FROM
- ( SELECT s.id as saleFk,
- ish.created,
- ish.id as itemShelvingFk,
- ish.available,
- s.quantity,
- ish.packing,
- CONCAT(p.`column`, '-',p.`row`,': ', sh.code ) as ubication
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.sector sc ON sc.warehouseFk = t.warehouseFk
- JOIN vn.parking p ON p.sectorFk = sc.id
- JOIN vn.shelving sh ON sh.parkingFk = p.id
- JOIN vn.itemShelving ish ON ish.shelvingFk = sh.code AND ish.itemFk = s.itemFk
- WHERE t.id = vTicketFk
- AND sc.id = vSectorFk
- AND s.quantity MOD ish.packing = 0
- AND s.quantity >= ish.packing
- ORDER BY s.id,
- sh.priority DESC,
- ish.packing DESC,
- ish.created
- ) sub
- ) sub2
- WHERE Reserved > 0;
-
- UPDATE vn.itemShelving ish
- JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
- JOIN vn.sale s ON s.id = sis.saleFk
- SET ish.available = ish.visible - sis.quantity,
- ish.visible = ish.visible - sis.quantity
- WHERE s.ticketFk = vTicketFk
- AND s.isPicked = FALSE;
-
- CALL vn.saleItemShelvingIsPicked(vTicketFk, TRUE);
-
-
+BEGIN
+
+ SET @rest:= CAST(0 AS DECIMAL(10,0));
+ SET @saleFk := CAST(0 AS DECIMAL(10,0));
+ SET @reserved := CAST(0 AS DECIMAL(10,0));
+
+ UPDATE vn.itemShelving ish
+ JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
+ JOIN sale s ON s.id = sis.saleFk
+ SET ish.visible = sis.quantity + ish.visible,
+ ish.available = sis.quantity + ish.visible
+ WHERE s.ticketFk = vTicketFk;
+
+ DELETE sis.*
+ FROM saleItemShelving sis
+ JOIN sale s ON s.id = sis.saleFk
+ WHERE s.ticketFk = vTicketFk;
+
+ INSERT INTO saleItemShelving( saleFk,
+ itemShelvingFk,
+ quantity,
+ ubication)
+ SELECT saleFk,
+ itemShelvingFk,
+ CAST(Reserved as DECIMAL(10,0)) as Reserved,
+ ubication
+ FROM
+ (SELECT saleFk,
+ itemShelvingFk,
+ ubication,
+ @rest := IF(@saleFk = saleFk, @rest, quantity) as Falta,
+ @reserved := IF(available < @rest, available, IF(@rest < packing,0,@rest)) as Reserved,
+ @rest := @rest - @reserved,
+ @saleFk := saleFk
+ FROM
+ ( SELECT s.id as saleFk,
+ ish.created,
+ ish.id as itemShelvingFk,
+ ish.available,
+ s.quantity,
+ ish.packing,
+ CONCAT(p.`column`, '-',p.`row`,': ', sh.code ) as ubication
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ JOIN vn.sector sc ON sc.warehouseFk = t.warehouseFk
+ JOIN vn.parking p ON p.sectorFk = sc.id
+ JOIN vn.shelving sh ON sh.parkingFk = p.id
+ JOIN vn.itemShelving ish ON ish.shelvingFk = sh.code AND ish.itemFk = s.itemFk
+ WHERE t.id = vTicketFk
+ AND sc.id = vSectorFk
+ AND s.quantity MOD ish.packing = 0
+ AND s.quantity >= ish.packing
+ ORDER BY s.id,
+ sh.priority DESC,
+ ish.packing DESC,
+ ish.created
+ ) sub
+ ) sub2
+ WHERE Reserved > 0;
+
+ UPDATE vn.itemShelving ish
+ JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
+ JOIN vn.sale s ON s.id = sis.saleFk
+ SET ish.available = ish.visible - sis.quantity,
+ ish.visible = ish.visible - sis.quantity
+ WHERE s.ticketFk = vTicketFk
+ AND s.isPicked = FALSE;
+
+ CALL vn.saleItemShelvingIsPicked(vTicketFk, TRUE);
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -60149,33 +60286,33 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `scanTreeCreate__`()
-BEGIN
- CALL nestTree(
- 'vn2008',
- 'scan',
- 'vn2008',
- 'scanTree'
- );
-
- UPDATE vn2008.scanTree st
- JOIN (
- SELECT sl.scan_id,
- MAX(sl.odbc_date) lastScanned,
- COUNT(DISTINCT t.routeFk) routeCount,
- MIN(t.routeFk) mod 1000 as minRoute,
- MAX(t.routeFk) mod 1000 as maxRoute,
- COUNT(sl.scan_line_id) as scanned
- FROM vn2008.scan_line sl
- JOIN expedition e ON e.id = sl.`code`
- JOIN ticket t ON t.id = e.ticketFk
- WHERE t.routeFk
- GROUP BY sl.scan_id
- ) rs ON rs.scan_id = st.id
- SET st.lastScanned = rs.lastScanned,
- st.routeCount = rs.routeCount,
- st.minRoute = rs.minRoute,
- st.maxRoute = IF(rs.minRoute != rs.maxRoute, rs.maxRoute,NULL),
- st.scanned = rs.scanned;
+BEGIN
+ CALL nestTree(
+ 'vn2008',
+ 'scan',
+ 'vn2008',
+ 'scanTree'
+ );
+
+ UPDATE vn2008.scanTree st
+ JOIN (
+ SELECT sl.scan_id,
+ MAX(sl.odbc_date) lastScanned,
+ COUNT(DISTINCT t.routeFk) routeCount,
+ MIN(t.routeFk) mod 1000 as minRoute,
+ MAX(t.routeFk) mod 1000 as maxRoute,
+ COUNT(sl.scan_line_id) as scanned
+ FROM vn2008.scan_line sl
+ JOIN expedition e ON e.id = sl.`code`
+ JOIN ticket t ON t.id = e.ticketFk
+ WHERE t.routeFk
+ GROUP BY sl.scan_id
+ ) rs ON rs.scan_id = st.id
+ SET st.lastScanned = rs.lastScanned,
+ st.routeCount = rs.routeCount,
+ st.minRoute = rs.minRoute,
+ st.maxRoute = IF(rs.minRoute != rs.maxRoute, rs.maxRoute,NULL),
+ st.scanned = rs.scanned;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -64051,25 +64188,25 @@ DELIMITER ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`z-developer`@`%` PROCEDURE `ticketManaToPromo`(vTicketFk INT)
-BEGIN
-
- DECLARE vManaComponent INT;
-
- DECLARE vPromoComponent INT;
-
- SELECT id INTO vManaComponent
- FROM vn.component c
- WHERE c.code = 'mana';
-
- SELECT id INTO vPromoComponent
- FROM vn.component c
- WHERE c.code = 'floramondoPromo';
-
- UPDATE vn.saleComponent sc
- JOIN vn.sale s ON s.id = sc.saleFk
- SET componentFk = vPromoComponent
- WHERE componentFk = vManaComponent
- AND s.ticketFk = vTicketFk;
+BEGIN
+
+ DECLARE vManaComponent INT;
+
+ DECLARE vPromoComponent INT;
+
+ SELECT id INTO vManaComponent
+ FROM vn.component c
+ WHERE c.code = 'mana';
+
+ SELECT id INTO vPromoComponent
+ FROM vn.component c
+ WHERE c.code = 'floramondoPromo';
+
+ UPDATE vn.saleComponent sc
+ JOIN vn.sale s ON s.id = sc.saleFk
+ SET componentFk = vPromoComponent
+ WHERE componentFk = vManaComponent
+ AND s.ticketFk = vTicketFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -65147,6 +65284,150 @@ BEGIN
CLOSE rsTicket;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_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_cloneWeekly__3` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!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 `ticket_cloneWeekly__3`(IN vWeek INT)
+BEGIN
+DECLARE vIsDone BOOL;
+ DECLARE vLanding DATE;
+ DECLARE vShipment DATE;
+ DECLARE vWarehouse INT;
+ DECLARE vTicket INT;
+ DECLARE vWeekDay INT;
+ DECLARE vClient INT;
+ DECLARE vEmpresa INT;
+ DECLARE vConsignatario INT;
+ DECLARE vAgencia INT;
+ DECLARE vNewTicket INT;
+ DECLARE vYear INT;
+
+ DECLARE rsTicket CURSOR FOR
+ SELECT tt.Id_Ticket, weekDay, Id_Cliente, warehouse_id, empresa_id, Id_Consigna, Id_Agencia
+ FROM Tickets_turno tt
+ JOIN Tickets t ON tt.Id_Ticket = t.Id_Ticket;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
+
+ SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0);
+
+ OPEN rsTicket;
+ myLoop: LOOP
+ BEGIN
+ DECLARE vSalesPersonEmail VARCHAR(150);
+ DECLARE vMailSent BOOL;
+ DECLARE vSubject VARCHAR(150);
+ DECLARE vMessage TEXT;
+ /*DECLARE vError TEXT;
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+ GET DIAGNOSTICS CONDITION 1
+ vError = MESSAGE_TEXT;
+
+ END;*/
+
+ SET vIsDone = FALSE;
+ FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vConsignatario, vAgencia;
+
+ IF vIsDone THEN
+
+ LEAVE myLoop;
+ END IF;
+ SELECT date INTO vShipment
+ FROM `time`
+ WHERE `year` = vYear AND `week` = vWeek
+ AND WEEKDAY(date) = vWeekDay;
+
+ -- busca si el ticket ya ha sido clonado
+ IF (SELECT COUNT(*) FROM vn.ticket tOrig
+ JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk
+ JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id
+ JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk
+ JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk
+ WHERE tOrig.id = vTicket AND tClon.isDeleted = FALSE AND DATE(tClon.shipped) = vShipment) > 0
+ THEN
+ ITERATE myLoop;
+ END IF;
+ CALL vn.zone_getLanded(vShipment, vConsignatario, vAgencia, vWarehouse,FALSE);
+
+ SELECT landed INTO vLanding from tmp.zoneGetLanded LIMIT 1;
+ IF (SELECT COUNT(*) FROM Agencias WHERE Id_Agencia = vAgencia AND Agencia LIKE '%turno%') THEN
+ SET vAgencia = NULL;
+ END IF;
+
+ CALL vn.ticketCreateWithoutZone(vClient, vShipment, vWarehouse, vEmpresa, vConsignatario, vAgencia, NULL, vLanding,account.userGetId(), vNewTicket);
+
+ IF (vLanding IS NULL) THEN
+
+ SELECT e.email INTO vSalesPersonEmail
+ FROM vn.client c
+ JOIN vn.worker sp ON sp.id = c.salesPersonFk
+ JOIN account.emailUser e ON e.userFk = sp.userFk
+ WHERE c.id = vClient;
+
+ SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicket,
+ ' para el dia: ', vShipment);
+ SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicket,
+ ' para el dia: ', vShipment,
+ ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket,
+ ' pero ha que revisar las fechas y la agencia');
+
+ SELECT COUNT(*) INTO vMailSent
+ FROM vn.mail
+ WHERE sender = vSalesPersonEmail
+ AND subject = vSubject;
+
+ IF NOT vMailSent THEN
+ INSERT INTO vn2008.mail (`to`,`subject`,`text`)
+ VALUES (vSalesPersonEmail, vSubject, vMessage);
+ END IF;
+ CALL vn.ticketStateUpdate (vNewTicket, 'FIXING');
+ END IF;
+
+ INSERT INTO vn.sale (ticketFk, itemFk, concept, quantity, price, discount, priceFixed, isPriceFixed)
+ SELECT vNewTicket, saleOrig.itemFk , saleOrig.concept , saleOrig.quantity, saleOrig.price , saleOrig.discount, saleOrig.priceFixed, saleOrig.isPriceFixed
+ FROM vn.sale saleOrig
+ WHERE saleOrig.ticketFk = vTicket;
+
+ INSERT IGNORE INTO vn.saleCloned(saleOriginalFk, saleClonedFk)
+ SELECT saleOriginal.id, saleClon.id
+ FROM vn.sale saleOriginal
+ JOIN vn.sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity
+ WHERE saleOriginal.ticketFk = vTicket AND saleClon.ticketFk = vNewTicket;
+
+ INSERT INTO Ordenes (orden,datorden,datticket,codvendedor,codcomprador,cantidad,preciomax,preu,id_article,id_cliente,comentario,
+ ok, total,datcompra,ko,id_movimiento)
+ SELECT o.orden,o.datorden,vShipment,o.codvendedor,o.codcomprador,o.cantidad,o.preciomax,o.preu,o.id_article,o.id_cliente,o.comentario,
+ o.ok, o.total,o.datcompra,o.ko,m2.Id_Movimiento
+ FROM Movimientos m JOIN Ordenes o ON o.Id_Movimiento = m.Id_Movimiento
+ JOIN Movimientos m2 ON m.Concepte = m2.Concepte AND m.Cantidad = m2.Cantidad AND m.Id_Article = m2.Id_Article
+ WHERE m.Id_Ticket = vTicket AND m2.Id_Ticket = vNewTicket;
+
+ INSERT INTO ticket_observation(Id_Ticket,observation_type_id,text) VALUES(vNewTicket,4,CONCAT('turno desde ticket: ',vTicket))
+ ON DUPLICATE KEY UPDATE text = CONCAT(ticket_observation.text,VALUES(text),' ');
+
+ INSERT INTO ticket_observation(Id_Ticket,observation_type_id,text) VALUES(vNewTicket,1,'ATENCION: Contiene lineas de TURNO')
+ ON DUPLICATE KEY UPDATE text = CONCAT(ticket_observation.text,VALUES(text),' ');
+
+ CALL vn.ticketCalculateClon(vNewTicket, vTicket);
+ END;
+ END LOOP;
+
+ CLOSE rsTicket;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -76215,4 +76496,4 @@ USE `vncontrol`;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2021-01-05 9:34:47
+-- Dump completed on 2021-01-08 10:00:22
diff --git a/db/export-structure.sh b/db/export-structure.sh
index 1fef22a31..36d41ea18 100755
--- a/db/export-structure.sh
+++ b/db/export-structure.sh
@@ -59,7 +59,6 @@ IGNORETABLES=(
--ignore-table=vn.mail__
--ignore-table=vn.manaSpellers
--ignore-table=vn.outgoingInvoiceKk
- --ignore-table=vn.payment
--ignore-table=vn.paymentExchangeInsurance
--ignore-table=vn.payrollCenter
--ignore-table=vn.plantpassport__
diff --git a/loopback/locale/en.json b/loopback/locale/en.json
index fc07126e9..0db7554c1 100644
--- a/loopback/locale/en.json
+++ b/loopback/locale/en.json
@@ -88,5 +88,7 @@
"Amount cannot be zero": "Amount cannot be zero",
"Company has to be official": "Company has to be official",
"A travel with this data already exists": "A travel with this data already exists",
- "The observation type can't be repeated": "The observation type can't be repeated"
+ "The observation type can't be repeated": "The observation type can't be repeated",
+ "New ticket request has been created with price": "New ticket request has been created '{{description}}' for day {{shipped}}, with a quantity of {{quantity}} and a price of {{price}} €",
+ "New ticket request has been created": "New ticket request has been created '{{description}}' for day {{shipped}}, with a quantity of {{quantity}}"
}
\ No newline at end of file
diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index e0264a252..af7f7778d 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -167,5 +167,7 @@
"You can't upload images on the test environment": "No puedes subir imágenes en el entorno de pruebas",
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
"Sorts whole route": "Reordena ruta entera",
- "Invalid account": "Cuenta inválida"
+ "Invalid account": "Cuenta inválida",
+ "New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}} y un precio de {{price}} €",
+ "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}}"
}
\ No newline at end of file
diff --git a/loopback/util/log.js b/loopback/util/log.js
index d81fc39a0..b491b97d0 100644
--- a/loopback/util/log.js
+++ b/loopback/util/log.js
@@ -24,9 +24,9 @@ exports.translateValues = async(instance, changes) => {
function formatDate(date) {
return new Intl.DateTimeFormat('es', {
- year: '2-digit',
- month: '2-digit',
- day: '2-digit',
+ year: 'numeric',
+ month: 'numeric',
+ day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
diff --git a/modules/ticket/back/models/ticket-request.js b/modules/ticket/back/models/ticket-request.js
index f711ed23e..814f47bae 100644
--- a/modules/ticket/back/models/ticket-request.js
+++ b/modules/ticket/back/models/ticket-request.js
@@ -8,10 +8,38 @@ module.exports = function(Self) {
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
const loopBackContext = LoopBackContext.getCurrentContext();
- let filter = {where: {userFk: loopBackContext.active.accessToken.userId}};
- let worker = await Self.app.models.Worker.findOne(filter);
+ const filter = {where: {userFk: loopBackContext.active.accessToken.userId}};
+ const models = Self.app.models;
+ const worker = await models.Worker.findOne(filter);
- ctx.instance.requesterFk = worker.id;
+ const instance = ctx.instance;
+ instance.requesterFk = worker.id;
+
+ const httpCtx = {req: loopBackContext.active};
+ const httpRequest = httpCtx.req.http .req;
+ const $t = httpRequest.__;
+
+ const attenderId = instance.attenderFk;
+ if (attenderId) {
+ const ticket = await models.Ticket.findById(instance.ticketFk);
+ let messageText = 'New ticket request has been created';
+ if (instance.price)
+ messageText = 'New ticket request has been created with price';
+
+ const shipped = new Intl.DateTimeFormat('es', {
+ year: 'numeric',
+ month: 'numeric',
+ day: 'numeric'
+ }).format(ticket.shipped);
+
+ const message = $t(messageText, {
+ description: instance.description,
+ shipped: shipped,
+ quantity: instance.quantity,
+ price: instance.price
+ });
+ await models.Chat.sendCheckingPresence(httpCtx, attenderId, message);
+ }
}
});
};