DROP PROCEDURE IN_ObtieneCostosTotalesEnFormulasProc
GO
CREATE PROCEDURE IN_ObtieneCostosTotalesEnFormulasProc
( @KITID	UD_KITID,
  @CORRNBR	INT,
  @TABLA	BIT		 --1 SI ES IN_KITCOMPONENT, 0  SI ES TMP_IN_KITCOMPONENT 
)
AS
BEGIN 

/****** 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)	
/*******************************************************************************************************/

	IF (@TABLA=1)
		BEGIN
			SELECT 	ROUND(SUM(STDCOSTPEN*QTY),@ND_COSTOSETUP) AS COSTOPEN ,SUM(STDCOSTUSD*QTY) AS COSTOUSD
			FROM 		IN_KITCOMPONENT
			WHERE 	IN_KITCOMPONENT.KITID=@KITID
		END
	ELSE
		BEGIN
			SELECT 	ROUND(SUM(STDCOSTPEN*QTY),@ND_COSTOSETUP) AS COSTOPEN ,SUM(STDCOSTUSD*QTY) AS COSTOUSD
			FROM 		TMP_IN_KITCOMPONENT
			WHERE 	TMP_IN_KITCOMPONENT.KITID=@KITID AND CORRNBR=@CORRNBR
		END

END


