DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByAwb`(IN awbFk varchar(18))
BEGIN
/**
 * inserta en tmp.buyRecalc las compras de un awb
 *
 * @param awbFk
 */  
	DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc;

	CREATE TEMPORARY TABLE tmp.buyRecalc
		SELECT b.id
			FROM buy b 
				JOIN entry e ON e.id = b.entryFk
				JOIN duaEntry de ON de.entryFk = e.id
				JOIN dua d ON d.id = de.duaFk
				JOIN awb a ON a.id = d.awbFk
			WHERE a.code = awbFk;

	CALL buy_recalcPrices();

	DROP TEMPORARY TABLE tmp.buyRecalc;
END$$
DELIMITER ;
