DROP PROCEDURE TMP_IN_INTRAITEMSelProc
GO
CREATE PROCEDURE TMP_IN_INTRAITEMSelProc
(   @VENDIDSS UD_IDVENDOR,
    @CORRNBR  INT,
    @CURYID     UD_CURYID
)

AS
BEGIN
      DECLARE @MONEDABASE CHAR(3)
      SET @MONEDABASE =(SELECT CURYORIG FROM SETUP) 

/****** VARIABLES QUE VIENEN DEL SETUP PARA EL REDONDEO ********************/ 
	DECLARE @ND_COSTOSETUP Tinyint
	DECLARE @ND_STOCKSETUP Tinyint
	DECLARE @ND_RESULTADOSETUP Tinyint 

	SET @ND_COSTOSETUP=(Select Floatcost from setup)
 	SET @ND_STOCKSETUP=(Select Floatqty from setup)
	SET @ND_RESULTADOSETUP=(select Floatoutput from setup)	
/*******************************************************************************************************/

      	SELECT	 [SEQUENCE] AS Item,
           		       	TMP_IN_INTRAITEM.INVTIDSKU AS Codigo,
	       		IN_VENDORINVT.BUYCOD AS Cod_Compra, 
                    		IN_INVENTORY.DESCR AS Descripcion,
                    		QTY as Cantidad,
                    		CASE @CURYID
				WHEN @MONEDABASE THEN STDCOSTPEN
				ELSE STDCOSTUSD
				END as Costo,
                    		CASE @CURYID
				WHEN @MONEDABASE THEN ROUND(QTY*STDCOSTPEN,@ND_RESULTADOSETUP)
				ELSE ROUND(QTY*STDCOSTUSD,@ND_RESULTADOSETUP)
				END as Total,
			TMP_IN_INTRAITEM.TAXIGV AS IGV,TMP_IN_INTRAITEM.TAXISC AS ISC,
                    		CASE @CURYID
				WHEN @MONEDABASE THEN STDCOSTPENOLD
				ELSE STDCOSTUSDOLD
				END as CostoAnt

	FROM 		TMP_IN_INTRAITEM,IN_INVENTORY,IN_VENDORINVT
	WHERE 	TMP_IN_INTRAITEM.INVTIDSKU = IN_INVENTORY.INVTIDSKU AND
	   	 	CORRNBR=@CORRNBR AND TMP_IN_INTRAITEM.INVTIDSKU=IN_VENDORINVT.INVTIDSKU
	  		 AND VENDIDSS=@VENDIDSS AND TMP_IN_INTRAITEM.SITEID=IN_VENDORINVT.SITEID

      	ORDER BY	SEQUENCE ASC

END


