2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-06-14 10:41:46 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(
|
|
|
|
vShelvingFk VARCHAR(8),
|
|
|
|
vBarcode VARCHAR(22),
|
|
|
|
vQuantity INT,
|
|
|
|
vPackagingFk VARCHAR(10),
|
|
|
|
vGrouping INT,
|
|
|
|
vPacking INT,
|
|
|
|
vWarehouseFk INT
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Añade registro o lo actualiza si ya existe.
|
|
|
|
*
|
|
|
|
* @param vShelvingFk matrícula del carro
|
|
|
|
* @param vBarcode el id del registro
|
|
|
|
* @param vQuantity indica la cantidad del producto
|
|
|
|
* @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra
|
|
|
|
* @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra
|
|
|
|
* @param vPacking el packing del producto, NULL para coger el de la ultima compra
|
|
|
|
* @param vWarehouseFk indica el sector
|
2024-04-25 12:28:47 +00:00
|
|
|
*
|
2024-01-15 11:31:03 +00:00
|
|
|
**/
|
|
|
|
DECLARE vItemFk INT;
|
2024-02-06 12:31:58 +00:00
|
|
|
DECLARE vBuyFk INT;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-05-20 07:27:20 +00:00
|
|
|
SELECT id INTO vBuyFk
|
|
|
|
FROM buy WHERE id = vBarcode;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT barcodeToItem(vBarcode) INTO vItemFk;
|
|
|
|
|
2024-05-20 07:27:20 +00:00
|
|
|
IF vBuyFk IS NULL THEN
|
2024-06-14 10:41:46 +00:00
|
|
|
CALL util.throw('The buy is required');
|
2024-05-20 07:27:20 +00:00
|
|
|
END IF;
|
|
|
|
|
2024-05-08 08:03:11 +00:00
|
|
|
IF vPacking IS NULL
|
2024-05-13 12:24:31 +00:00
|
|
|
THEN
|
2024-05-08 08:03:11 +00:00
|
|
|
SET vPacking = itemPacking(vBarcode, vWarehouseFk);
|
|
|
|
SET vQuantity = vQuantity * vPacking;
|
2024-01-15 11:31:03 +00:00
|
|
|
END IF;
|
|
|
|
|
2024-04-25 12:28:47 +00:00
|
|
|
IF (SELECT COUNT(*) FROM itemShelving
|
|
|
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
|
|
|
AND itemFk = vItemFk
|
2024-05-20 07:27:20 +00:00
|
|
|
AND packing = vPacking
|
|
|
|
AND buyFk = vBuyFk) THEN
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
UPDATE itemShelving
|
2024-05-20 07:27:20 +00:00
|
|
|
SET visible = visible + vQuantity
|
2024-04-25 12:28:47 +00:00
|
|
|
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
ELSE
|
2024-02-06 12:31:58 +00:00
|
|
|
|
|
|
|
INSERT INTO itemShelving(
|
|
|
|
itemFk,
|
|
|
|
shelvingFk,
|
|
|
|
visible,
|
|
|
|
grouping,
|
|
|
|
packing,
|
|
|
|
packagingFk,
|
|
|
|
buyFk)
|
|
|
|
SELECT vItemFk,
|
|
|
|
vShelvingFk,
|
|
|
|
vQuantity,
|
|
|
|
IFNULL(vGrouping, b.grouping),
|
|
|
|
IFNULL(vPacking, b.packing),
|
|
|
|
IFNULL(vPackagingFk, b.packagingFk),
|
|
|
|
id
|
|
|
|
FROM buy b
|
|
|
|
WHERE id = vBuyFk;
|
2024-01-15 11:31:03 +00:00
|
|
|
END IF;
|
|
|
|
END$$
|
2024-01-31 06:11:03 +00:00
|
|
|
DELIMITER ;
|