DROP PROCEDURE RecalculaCreditosClientesProc
GO
CREATE PROCEDURE RecalculaCreditosClientesProc
(
	@CORRNBR        int,
	@MTOTOTLIMIT	UD_MONTO,
	@DECIMALES	INT
)
AS
BEGIN
    BEGIN TRAN
 	  UPDATE Tmp_Op_Cust_Limit
	  SET 	CREDLIMITED=ROUND(PORCENTLIMITED*@MTOTOTLIMIT/100,@DECIMALES),
		MTOSURPLUS=ROUND(PORCENTSURPLUS*PORCENTLIMITED*@MTOTOTLIMIT/10000,@DECIMALES)
          WHERE CORRNBR=@CORRNBR

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'Error Recalculando Montos en TMP_OP_CUST_LIMIT'
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

END