DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingListSwitch`(saleFk INT)
BEGIN

	DECLARE valueFk INT;
    DECLARE encajando INT DEFAULT 9;
    
    SELECT valor INTO valueFk 
		FROM vn2008.Movimientos_mark 
		WHERE Id_Movimiento = saleFk 
			AND stateFk = encajando;
            
	SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3;
	
	REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk) 
		VALUES(saleFk,valueFk,account.myUser_getId(),encajando);


END$$
DELIMITER ;
