60 lines
1.7 KiB
SQL
60 lines
1.7 KiB
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(
|
|
vShelvingCode VARCHAR(10),
|
|
vList TEXT,
|
|
vIsChecking BOOL,
|
|
vWarehouseFk INT
|
|
)
|
|
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 itemShelving.isChecked
|
|
*
|
|
* @param vShelvingCode Código de 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 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;
|
|
DECLARE vShelvingFk INT;
|
|
|
|
SELECT id INTO vShelvingFk
|
|
FROM shelving
|
|
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
|
|
|
|
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 IF(COUNT(*), TRUE, FALSE) INTO vIsChecked
|
|
FROM itemShelving
|
|
WHERE shelvingFk = vShelvingFk
|
|
AND itemFk = vItemFk;
|
|
END IF;
|
|
|
|
IF NOT vIsChecking OR NOT vIsChecked THEN
|
|
CALL itemShelving_add(vShelvingCode, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
|
|
END IF;
|
|
|
|
UPDATE itemShelving
|
|
SET isChecked = vIsChecked
|
|
WHERE shelvingFk = vShelvingFk
|
|
AND itemFk = vItemFk
|
|
AND isChecked IS NULL;
|
|
|
|
SET vCounter = vCounter + 1;
|
|
END WHILE;
|
|
END$$
|
|
DELIMITER ;
|