DROP PROCEDURE IN_CalculaTotalesProc
GO
CREATE PROCEDURE IN_CalculaTotalesProc
( @CURYID 	UD_CURYID,
  @CORRNBR	INT)
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)
/*******************************************************************************************************/

   IF @CURYID=@MONEDABASE
      SELECT ROUND(SUM(STDCOSTPEN*QTY),@ND_RESULTADOSETUP) AS VALVENTA,
	     (ROUND(SUM(STDCOSTPEN*QTY*TAXIGV/100),@ND_RESULTADOSETUP)) AS IGV
      FROM TMP_IN_INTRAITEM
      WHERE CORRNBR=@CORRNBR
   ELSE
      SELECT ROUND(SUM(STDCOSTUSD*QTY),@ND_RESULTADOSETUP) AS VALVENTA, 
	     (ROUND(SUM(STDCOSTUSD*QTY*TAXIGV/100),@ND_RESULTADOSETUP)) AS IGV
      FROM TMP_IN_INTRAITEM
      WHERE CORRNBR=@CORRNBR
END 


