/* PROCEDIMIEMTO QUE GENERA LA CONSULTA PARA EL REPORTE DE INGRESO O SALIDA*/


DROP PROCEDURE ConsultaParaReporteIngresoProc
GO
CREATE PROCEDURE ConsultaParaReporteIngresoProc
( @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
	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,IN_INTRAITEM.INVTIDSKU,IN_VENDORINVT.BUYCOD,IN_INVENTORY.CLASSID,
             IN_INVENTORY.CLASSUBID,IN_INVENTORY.DESCR,IN_INVENTORYUNITMED.DESCR AS UNIT_MED,
             QTY,IN_INTRAITEM.STDCOSTPEN,INTRDATEPROCE,
             CASE @CURYID
			WHEN @MONEDABASE THEN IN_INTRAITEM.STDCOSTPENOLD
			ELSE IN_INTRAITEM.STDCOSTUSDOLD
			END as CostoAnt,
             CASE @CURYID
			WHEN @MONEDABASE THEN IN_INTRAITEM.STDCOSTPEN
			ELSE IN_INTRAITEM.STDCOSTUSD
			END as Costo,
             CASE @CURYID
			WHEN @MONEDABASE THEN ROUND(QTY*IN_INTRAITEM.STDCOSTPEN,@ND_RESULTADOSETUP )
			ELSE ROUND(QTY*IN_INTRAITEM.STDCOSTUSD,@ND_RESULTADOSETUP)
			END as TOTAL

      FROM   IN_INTRAITEM,IN_INVENTORY,IN_VENDORINVT,IN_INVENTORYUNITMED
      WHERE  IN_INTRAITEM.SITEID=@SITEID AND
             BATNBR=@BATNBR AND IN_INTRAITEM.INVTIDSKU=IN_INVENTORY.INVTIDSKU AND
             IN_INTRAITEM.INVTIDSKU=IN_VENDORINVT.INVTIDSKU AND VENDIDSS=@VENDIDSS AND
	     IN_INVENTORY.STKUNITID=IN_INVENTORYUNITMED.STKUNITID AND IN_INTRAITEM.SITEID=IN_VENDORINVT.SITEID 
END
