DROP PROCEDURE IN_INTRAITEMSelProc
GO
CREATE PROCEDURE IN_INTRAITEMSelProc
(   @SITEID     UD_IDSITE,
    @BATNBR     CHAR(10), 
    @VENDIDSS   UD_IDVENDOR,
    @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

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

      SELECT [SEQUENCE] AS Item,
             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_COSTOSETUP)
			ELSE ROUND(QTY*STDCOSTUSD,@ND_COSTOSETUP)
			END as Total,
	IN_INTRAITEM.TAXIGV AS IGV,IN_INTRAITEM.TAXISC AS ISC,
                    		CASE @CURYID
				WHEN @MONEDABASE THEN STDCOSTPENOLD
				ELSE STDCOSTUSDOLD
				END as CostoAnt
      FROM IN_INTRAITEM, IN_INVENTORY, IN_VENDORINVT 
      WHERE IN_INTRAITEM.INVTIDSKU = IN_INVENTORY.INVTIDSKU AND 
      	    IN_INTRAITEM.SITEID=@SITEID AND IN_INTRAITEM.INVTIDSKU=IN_VENDORINVT.INVTIDSKU AND 
            VENDIDSS=@VENDIDSS AND BATNBR=@BATNBR AND IN_INTRAITEM.SITEID=IN_VENDORINVT.SITEID

END