2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(vShelvingFk VARCHAR(3), vList TEXT, vIsChecking BOOL, vWarehouseFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/* Recorre cada elemento en la colección vList.
|
|
|
|
* Si el parámetro isChecking = FALSE, llama a itemShelving_add.
|
|
|
|
*
|
|
|
|
* Cuando es TRUE sólo inserta los elementos de la colección que no están ya en
|
|
|
|
* ese shelving, actualizando los valores del campo vn.itemShelving.isChecked
|
|
|
|
*
|
|
|
|
* param vShelvingFk Identificador de vn.shelving
|
|
|
|
* param vList JSON array con esta estructura: '[value1, value2, ...]'
|
|
|
|
* param vIsChecking Define si hay que añadir o comprobar los items
|
|
|
|
* param vWarehouseFk Identificador de vn.warehouse
|
|
|
|
*/
|
|
|
|
DECLARE vListLength INT DEFAULT JSON_LENGTH(vList);
|
|
|
|
DECLARE vCounter INT DEFAULT 0;
|
|
|
|
DECLARE vBarcode VARCHAR(22);
|
|
|
|
DECLARE vPath VARCHAR(6);
|
|
|
|
DECLARE vItemFk INT;
|
|
|
|
DECLARE vIsChecked BOOL;
|
|
|
|
|
|
|
|
WHILE vCounter < vListLength DO
|
|
|
|
SET vPath = CONCAT('$[',vCounter,']');
|
|
|
|
SET vBarcode = JSON_EXTRACT(vList,vPath);
|
|
|
|
SET vIsChecked = NULL;
|
|
|
|
IF vIsChecking THEN
|
|
|
|
SELECT barcodeToItem(vBarcode) INTO vItemFk;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vIsChecked
|
|
|
|
FROM vn.itemShelving
|
|
|
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
|
|
|
AND itemFk = vItemFk;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF NOT (vIsChecking AND vIsChecked) THEN
|
|
|
|
CALL vn.itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
UPDATE vn.itemShelving
|
|
|
|
SET isChecked = vIsChecked
|
|
|
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
2024-04-19 11:03:57 +00:00
|
|
|
AND itemFk = vItemFk AND isChecked IS NULL;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
SET vCounter = vCounter + 1;
|
|
|
|
END WHILE;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|