2023-11-07 15:13:21 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setVisibleDiscard`(
|
|
|
|
vItemFk INT,
|
|
|
|
vWarehouseFk INT,
|
|
|
|
vQuantity INT,
|
|
|
|
vAddressFk INT)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-07-05 10:37:59 +00:00
|
|
|
* Procedimiento para dar dar de baja/alta un item, si vAdressFk es NULL
|
|
|
|
* se entiende que se da de alta y se toma el addressFk de la configuración
|
2023-11-07 15:13:21 +00:00
|
|
|
*
|
|
|
|
* @param vItemFk Identificador del ítem
|
|
|
|
* @param vWarehouseFk id del warehouse
|
|
|
|
* @param vQuantity a dar de alta/baja
|
|
|
|
* @param vAddressFk id address
|
|
|
|
*/
|
2024-04-03 07:02:34 +00:00
|
|
|
|
2023-11-07 15:13:21 +00:00
|
|
|
DECLARE vTicketFk INT;
|
|
|
|
DECLARE vClientFk INT;
|
2023-11-08 10:50:04 +00:00
|
|
|
DECLARE vDefaultCompanyFk INT;
|
2023-11-07 15:13:21 +00:00
|
|
|
DECLARE vCalc INT;
|
|
|
|
DECLARE vAddressShortage INT;
|
|
|
|
|
|
|
|
SELECT barcodeToItem(vItemFk) INTO vItemFk;
|
|
|
|
|
2023-11-08 10:50:04 +00:00
|
|
|
SELECT DEFAULT(companyFk) INTO vDefaultCompanyFk
|
2023-11-07 15:13:21 +00:00
|
|
|
FROM vn.ticket LIMIT 1;
|
2024-04-03 05:09:07 +00:00
|
|
|
|
|
|
|
IF vAddressFk IS NULL THEN
|
2023-11-08 10:50:04 +00:00
|
|
|
SELECT pc.shortageAddressFk INTO vAddressShortage
|
|
|
|
FROM productionConfig pc ;
|
2024-04-03 05:09:07 +00:00
|
|
|
ELSE
|
2023-11-07 15:13:21 +00:00
|
|
|
SET vAddressShortage = vAddressFk;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT a.clientFk INTO vClientFk
|
|
|
|
FROM address a
|
2024-04-15 13:59:05 +00:00
|
|
|
WHERE a.id = vAddressShortage;
|
2023-11-07 15:13:21 +00:00
|
|
|
|
|
|
|
SELECT t.id INTO vTicketFk
|
|
|
|
FROM ticket t
|
|
|
|
JOIN address a ON a.id = t.addressFk
|
|
|
|
JOIN ticketState ts ON ts.ticketFk = t.id
|
|
|
|
WHERE t.warehouseFk = vWarehouseFk
|
|
|
|
AND a.id = vAddressShortage
|
|
|
|
AND DATE(t.shipped) = util.VN_CURDATE()
|
|
|
|
AND ts.code = 'DELIVERED'
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
|
|
|
|
|
|
|
|
IF vTicketFk IS NULL THEN
|
|
|
|
CALL ticket_add(
|
|
|
|
vClientFk,
|
|
|
|
util.VN_CURDATE(),
|
|
|
|
vWarehouseFk,
|
2023-11-08 10:50:04 +00:00
|
|
|
vDefaultCompanyFk,
|
2023-11-07 15:13:21 +00:00
|
|
|
vAddressFk,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
util.VN_CURDATE(),
|
|
|
|
account.myUser_getId(),
|
|
|
|
FALSE,
|
|
|
|
vTicketFk);
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
INSERT INTO sale(ticketFk, itemFk, concept, quantity)
|
|
|
|
SELECT vTicketFk,
|
|
|
|
vItemFk,
|
2024-04-09 11:39:33 +00:00
|
|
|
name,
|
2023-11-07 15:13:21 +00:00
|
|
|
vQuantity
|
|
|
|
FROM item
|
|
|
|
WHERE id = vItemFk;
|
|
|
|
|
|
|
|
UPDATE cache.visible
|
|
|
|
SET visible = visible - vQuantity
|
|
|
|
WHERE calc_id = vCalc
|
|
|
|
AND item_id = vItemFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|