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

30 lines
786 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`travel_updatePacking`(vItemFk INT, vPacking INT)
BEGIN
/**
* Actualiza packing para los movimientos de almacén de la subasta al almacén central
*
* @param vItemFk id del item
* @param vPacking nuevo packing
*/
DECLARE vAuctionWarehouseFk INT;
DECLARE vMainWarehouseFk INT;
SELECT warehouseFk INTO vAuctionWarehouseFk
FROM auctionConfig;
SELECT mainWarehouseFk INTO vMainWarehouseFk
FROM config;
UPDATE entry e
JOIN travel t ON t.id = e.travelFk
JOIN buy b on b.entryFk = e.id
SET b.packing = vPacking
WHERE t.shipped >= util.dayEnd(CURDATE())
AND t.warehouseInFk = vMainWarehouseFk
AND t.warehouseOutFk = vAuctionWarehouseFk
AND b.itemFk = vItemFk;
END$$
DELIMITER ;