salix/db/routines/vn/procedures/itemShelving_addList.sql

60 lines
1.7 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-09-16 07:17:20 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(
2024-11-13 08:03:44 +00:00
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
*
2024-11-13 08:03:44 +00:00
* @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;
2024-11-13 08:03:44 +00:00
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
2024-11-13 08:03:44 +00:00
WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk;
END IF;
2024-09-17 10:30:11 +00:00
IF NOT vIsChecking OR NOT vIsChecked THEN
2024-11-13 08:03:44 +00:00
CALL itemShelving_add(vShelvingCode, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
END IF;
UPDATE itemShelving
SET isChecked = vIsChecked
2024-11-13 08:03:44 +00:00
WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk
AND isChecked IS NULL;
SET vCounter = vCounter + 1;
END WHILE;
END$$
DELIMITER ;