
 ALTER 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 IN_INTRAITEM.INTPERCPEN  
   ELSE IN_INTRAITEM.INTPERCUSD  
   END as Percepcion, 
             CASE @CURYID  
   WHEN @MONEDABASE THEN ROUND(QTY*IN_INTRAITEM.STDCOSTPEN,@ND_RESULTADOSETUP )  
   ELSE ROUND(QTY*IN_INTRAITEM.STDCOSTUSD,@ND_RESULTADOSETUP)  
   END as TOTAL,'' AS PART  
      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   
      UNION ALL   
      SELECT 0,'','',IN_INVENTORY.CLASSID,'',IN_CATEGORY.DESCR,'',SUM(QTY),0,0,0,0, 0, 
             SUM(CASE @CURYID  
   WHEN @MONEDABASE THEN ROUND(QTY*IN_INTRAITEM.STDCOSTPEN,@ND_RESULTADOSETUP )  
   ELSE ROUND(QTY*IN_INTRAITEM.STDCOSTUSD,@ND_RESULTADOSETUP)  
   END) as TOTAL,'Por Categorķa' as PART  
      FROM   IN_INTRAITEM,IN_INVENTORY,IN_VENDORINVT,IN_INVENTORYUNITMED,IN_CATEGORY  
      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 AND   
             IN_INVENTORY.CLASSID=IN_CATEGORY.CLASSID  
      GROUP BY IN_INVENTORY.CLASSID,IN_CATEGORY.DESCR          
END  
  
  
  
  
