USE [BPMDATA] GO /****** Object: Table [Parametros].[WFShockTipoCambio] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Parametros].[WFShockTipoCambio]') AND type in (N'U')) DROP TABLE [Parametros].[WFShockTipoCambio] GO /****** Object: Table [Parametros].[WFShockTasaInteres] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Parametros].[WFShockTasaInteres]') AND type in (N'U')) DROP TABLE [Parametros].[WFShockTasaInteres] GO /****** Object: Table [Parametros].[WFGradualidadCobertura] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Parametros].[WFGradualidadCobertura]') AND type in (N'U')) DROP TABLE [Parametros].[WFGradualidadCobertura] GO /****** Object: UserDefinedFunction [dbo].[F_pmt] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[F_pmt]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[F_pmt] GO /****** Object: UserDefinedFunction [dbo].[F_getCuotaDTI] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[F_getCuotaDTI]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[F_getCuotaDTI] GO /****** Object: StoredProcedure [dbo].[usp_wf_sensibilizacion_deudas] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_wf_sensibilizacion_deudas]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[usp_wf_sensibilizacion_deudas] GO /****** Object: StoredProcedure [dbo].[usp_wf_riesgocambiario_CSD] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_wf_riesgocambiario_CSD]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[usp_wf_riesgocambiario_CSD] GO /****** Object: StoredProcedure [dbo].[usp_wf_generador_moneda] Script Date: 16/02/2018 10:43:05 a.m. ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_wf_generador_moneda]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[usp_wf_generador_moneda] GO /****** Object: StoredProcedure [dbo].[usp_wf_generador_moneda] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_wf_generador_moneda]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' ------------------------------------------------------------------------------ -- Ultimus LA -- Nombre SP: usp_wf_generador_moneda -- Proceso Utiliza: PrestamoPrendario -- Creado Por: Byron Madrigal -- Fecha Creación: 22/11/2016 ------------------------------------------------------------------------------ -- Modif. Por: Andres Leon R -- Modif. Fecha : 24/10/2017 -- Modif. Detalle:Nuevos ajuste Proyecto Actualización ------------------------------------------------------------------------------ /* exec [usp_wf_generador_moneda] @i_opcion = 1, @i_incidente = 109, @i_solicitud = 145, @i_idcliente = 180, @i_identificacion = ''01-1288-0438'', @i_proceso = ''PrestamoPrendario'', @i_ingreso_brut_col = 1652000.00, @i_ingreso_brut_dol = 0, @i_tipo_cambio = 542, @i_fecha_solicitud = ''2016-07-05'' exec [usp_wf_generador_moneda] @i_opcion = 1, @i_incidente = 217, @i_solicitud = 253, @i_idcliente = 293, @i_identificacion = ''02-0726-0237'', @i_proceso = ''PrestamoPrendario'', @i_ingreso_brut_col = 1348310.0000, @i_ingreso_brut_dol = 1753.5500, @i_tipo_cambio = 562.75, @i_fecha_solicitud = ''2017-03-23'' */ CREATE PROCEDURE [dbo].[usp_wf_generador_moneda] @i_opcion INT, @i_incidente INT = 0, @i_solicitud INT = 0, @i_proceso VARCHAR(50) = '''', @i_idcliente INT = NULL, @i_identificacion VARCHAR(30) = '''', @i_ingreso_brut_col FLOAT = NULL, @i_ingreso_brut_dol FLOAT = NULL, @i_tipo_cambio FLOAT = NULL, @i_fecha_solicitud VARCHAR(10) = NULL AS DECLARE @o_res_code INT, @o_res_message NVARCHAR(MAX), @o_res_err_procedure NVARCHAR(MAX), @o_res_err_line INT, @o_tipo_generador INT, @o_desc_tipo_generador NVARCHAR(100), @MonedaIngresos CHAR(1) = '''', @MonedaDeudaActual CHAR(1) = '''', -- C = Colones, D = Dolares, T = Todas @SumaCuotasCIC FLOAT = 0, @SumaCuotasFSN FLOAT = 0, @SumaTotal FLOAT = 0, @DeudaActualColones INT = 0, @DeudaActualDolares INT = 0, @Cobertura CHAR(1) = '''', -- C = Cubre, N = No Cubre @PuntoCorte FLOAT, @CSDCliente FLOAT, @Riesgo NVARCHAR(50) IF @i_opcion = 1 BEGIN BEGIN TRY BEGIN TRAN T1 SET @i_fecha_solicitud = ISNULL(@i_fecha_solicitud, '''') SELECT @i_ingreso_brut_col = ISNULL(@i_ingreso_brut_col,0), @i_ingreso_brut_dol = ISNULL(@i_ingreso_brut_dol,0), @i_tipo_cambio = ISNULL(@i_tipo_cambio,1), @i_fecha_solicitud = CONVERT(DATE,CONVERT(VARCHAR(20),ISNULL(@i_fecha_solicitud, GETDATE()),105)), @o_tipo_generador = 0, @o_desc_tipo_generador = '''' BEGIN -- Moneda Ingreso SELECT @i_ingreso_brut_col = ISNULL(@i_ingreso_brut_col,0), @i_ingreso_brut_dol = ISNULL(@i_ingreso_brut_dol,0), @i_tipo_cambio = ISNULL(@i_tipo_cambio,1) IF @i_ingreso_brut_col > 0 AND @i_ingreso_brut_dol > 0 BEGIN SET @MonedaIngresos = ''T'' END ELSE IF @i_ingreso_brut_col > 0 AND @i_ingreso_brut_dol = 0 BEGIN SET @MonedaIngresos = ''C'' END ELSE IF @i_ingreso_brut_dol > 0 AND @i_ingreso_brut_col = 0 BEGIN SET @MonedaIngresos = ''D'' END ELSE BEGIN SET @MonedaIngresos = ''N'' END END BEGIN -- Moneda Deudas Actuales SELECT @DeudaActualColones = COUNT(*) FROM [BPMPRENDARIO].[Prendario].[SituacionActual] WHERE IdSolicitud = @i_solicitud --and sa_saldo != ''0.0000'' and Moneda = ''N - COLONES O UNIDADES DE DESARROLLO'' SELECT @DeudaActualDolares = COUNT(*) FROM [BPMPRENDARIO].[Prendario].[SituacionActual] WHERE IdSolicitud = @i_solicitud --and sa_saldo != ''0.0000'' and Moneda = ''E - DIVISA EXTRANJERA'' IF @DeudaActualColones > 0 AND @DeudaActualDolares > 0 BEGIN SET @MonedaDeudaActual = ''T'' END ELSE IF @DeudaActualColones > 0 AND @DeudaActualDolares = 0 BEGIN SET @MonedaDeudaActual = ''C'' END ELSE IF @DeudaActualDolares > 0 AND @DeudaActualColones = 0 BEGIN SET @MonedaDeudaActual = ''D'' END ELSE IF @DeudaActualDolares = 0 AND @DeudaActualColones = 0 BEGIN SET @MonedaDeudaActual = ''N'' END END BEGIN -- SumaCuotasCIC - SumaCuotasFSN SELECT @SumaCuotasCIC = CONVERT(FLOAT,ISNULL(CargaMensualCSD,''0'')), @SumaCuotasFSN = CONVERT(FLOAT,ISNULL(CuotasNoReguladasCSD,''0'')) FROM [BPMPRENDARIO].[Global].[InformacionIngresosCliente] WHERE IdCliente = @i_idcliente SET @SumaTotal = ((@SumaCuotasCIC/@i_tipo_cambio)+(@SumaCuotasFSN/@i_tipo_cambio)) END BEGIN --Cobertura IF(@SumaTotal<@i_ingreso_brut_dol) BEGIN SET @Cobertura = ''C'' END ELSE BEGIN SET @Cobertura = ''N'' END END --Obtiene el Punto de Corte CSD BEGIN SELECT @PuntoCorte = PorcentajePuntoCorteCSD FROM [BPMPRENDARIO].[Catalogos].[PuntoCorteCSD] WHERE IdPuntoCorteCSD = 1 END --Obtiene el CSD del Cliente BEGIN SELECT @CSDCliente = CoberturaSobreDeuda FROM [BPMPRENDARIO].[Global].[Cliente] WHERE IdCliente = @i_idcliente END --Riesgo BEGIN IF(@CSDCliente>(@PuntoCorte*100)) BEGIN SET @Riesgo = ''DE ALTO RIESGO'' END ELSE BEGIN SET @Riesgo = ''DE BAJO RIESGO'' END END --@MonedaIngresos = ''T'' --@MonedaDeudaActual = ''C'' --@Cobertura = ''C'' --select @MonedaIngresos --select @MonedaDeudaActual --select @Cobertura IF ((@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''D'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''C'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''C'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''T'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''C'' AND @MonedaDeudaActual = ''N'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''N'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''N'' AND @Cobertura = ''C'')) OR (@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''T'' AND @Cobertura = ''C'') BEGIN SET @o_tipo_generador = 1 END ELSE IF ((@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''D'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''C'' AND @MonedaDeudaActual = ''C'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''C'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''D'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''C'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''T'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''T'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''C'' AND @MonedaDeudaActual = ''T'' AND @Cobertura = ''C'') OR (@MonedaIngresos = ''C'' AND @MonedaDeudaActual = ''T'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''C'' AND @MonedaDeudaActual = ''C'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''C'' AND @MonedaDeudaActual = ''N'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''D'' AND @MonedaDeudaActual = ''N'' AND @Cobertura = ''N'') OR (@MonedaIngresos = ''T'' AND @MonedaDeudaActual = ''N'' AND @Cobertura = ''N'')) BEGIN SET @o_tipo_generador = 2 END ELSE BEGIN SET @o_tipo_generador = 3 END SET @o_desc_tipo_generador = CASE @o_tipo_generador WHEN 1 THEN ''GENERADOR DE MONEDA EXTRANJERA'' WHEN 2 THEN ''NO GENERADOR DE MONEDA EXTRANJERA''+'' ''+ @Riesgo WHEN 3 THEN ''NO GENERADOR DE MONEDA EXTRANJERA'' END SELECT @o_res_code = 0, @o_res_message = ''EXITOSO'' COMMIT TRAN T1 END TRY BEGIN CATCH ROLLBACK TRAN T1 SELECT @o_res_code = ERROR_NUMBER(), @o_res_message = ERROR_MESSAGE(), @o_res_err_procedure = ERROR_PROCEDURE(), @o_res_err_line = ERROR_LINE() END CATCH SELECT res_cod_generador = @o_tipo_generador, res_des_generador = @o_desc_tipo_generador, res_code = @o_res_code, res_message = @o_res_message, res_err_procedure = @o_res_err_procedure, res_err_line = @o_res_err_line END ' END GO /****** Object: StoredProcedure [dbo].[usp_wf_riesgocambiario_CSD] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_wf_riesgocambiario_CSD]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' ------------------------------------------------------------------------------ -- Ultimus LA -- Nombre SP: usp_wf_riesgocambiario_CSD -- Proceso Utiliza: PrestamoPrendario -- Creado Por: Andrés León -- Fecha Creación: 17/10/2017 ------------------------------------------------------------------------------ -- Modif. Por: -- Modif. Fecha : -- Modif. Detalle: ------------------------------------------------------------------------------ /* exec [usp_wf_riesgocambiario_CSD] @i_opcion = 1, @i_incidente = 109, @i_solicitud = 145, @i_idcliente = 180, @i_identificacion = ''01-1288-0438'', @i_proceso = ''PrestamoPrendario'', @i_ingreso_neto_col = 1652000.00, @i_ingreso_neto_dol = 0, @i_tipo_cambio = 542, @i_fecha_solicitud = ''2016-07-05'' exec [usp_wf_riesgocambiario_CSD] @i_opcion = 2, @i_incidente = 251, @i_solicitud = 301, @i_idcliente = 336, @i_identificacion = ''01-0782-0379'', @i_proceso = ''PrestamoPrendario'', @i_ingreso_neto_col = 1652000.00, @i_ingreso_neto_dol = 0, @i_tipo_cambio = 542, @i_fecha_solicitud = ''2016-07-05'' */ CREATE PROCEDURE [dbo].[usp_wf_riesgocambiario_CSD] @i_opcion INT, @i_incidente INT = 0, @i_solicitud INT = 0, @i_proceso VARCHAR(50) = '''', @i_idcliente INT = NULL, @i_identificacion VARCHAR(30) = '''', @i_ingreso_neto_col FLOAT = NULL, @i_ingreso_neto_dol FLOAT = NULL, @i_ingreso_bruto_col FLOAT = NULL, @i_ingreso_bruto_dol FLOAT = NULL, @i_tipo_cambio FLOAT = NULL, @i_fecha_solicitud VARCHAR(10) = NULL AS DECLARE @o_res_code INT, @o_res_message NVARCHAR(MAX), @o_res_err_procedure NVARCHAR(MAX), @o_res_err_line INT, @MonedaIngresos CHAR(1) = '''', -- C = Colones, D = Dolares, T = Todas @MonedaDeudaActual CHAR(1) = '''', -- C = Colones, D = Dolares, T = Todas @DeudaActualColones INT = 0, @DeudaActualDolares INT = 0, @SumaCuotasCIC_COLONES FLOAT = 0, @SumaCuotasCIC_DOLARES FLOAT = 0, @SumaCuotasCIC FLOAT = 0, @SumaCuotasFSN FLOAT = 0, @NuevaCuota FLOAT = 0, @NuevaDeuda CHAR(1) = ''D'', -- C = Colones, D = Dolares, T = Todas @RiesgoCambiario FLOAT = 0, @DesRiesgoCambiario VARCHAR(50)= '''', @CodRiesgoCambiario CHAR(1) = '''', @PuntoCorte FLOAT, @CSD FLOAT = 0 BEGIN TRY IF @i_opcion = 1 BEGIN BEGIN -- Moneda Ingreso SELECT @i_ingreso_neto_col = ISNULL(@i_ingreso_neto_col,0), @i_ingreso_neto_dol = ISNULL(@i_ingreso_neto_dol,0), @i_tipo_cambio = ISNULL(@i_tipo_cambio,1) IF @i_ingreso_neto_col > 0 AND @i_ingreso_neto_dol > 0 BEGIN SET @MonedaIngresos = ''T'' END ELSE IF @i_ingreso_neto_col > 0 AND @i_ingreso_neto_dol = 0 BEGIN SET @MonedaIngresos = ''C'' END ELSE IF @i_ingreso_neto_dol > 0 AND @i_ingreso_neto_col = 0 BEGIN SET @MonedaIngresos = ''D'' END ELSE BEGIN SET @MonedaIngresos = ''N'' END END BEGIN -- Moneda Deudas Actuales SELECT @DeudaActualColones = COUNT(*) FROM [BPMPRENDARIO].[Prendario].[SituacionActual] WHERE IdSolicitud = @i_solicitud --and sa_saldo != ''0.0000'' and Moneda = ''N - COLONES O UNIDADES DE DESARROLLO'' SELECT @DeudaActualDolares = COUNT(*) FROM [BPMPRENDARIO].[Prendario].[SituacionActual] WHERE IdSolicitud = @i_solicitud --and sa_saldo != ''0.0000'' and Moneda = ''E - DIVISA EXTRANJERA'' IF @DeudaActualColones > 0 AND @DeudaActualDolares > 0 BEGIN SET @MonedaDeudaActual = ''T'' END ELSE IF @DeudaActualColones > 0 AND @DeudaActualDolares = 0 BEGIN SET @MonedaDeudaActual = ''C'' END ELSE IF @DeudaActualDolares > 0 AND @DeudaActualColones = 0 BEGIN SET @MonedaDeudaActual = ''D'' END END BEGIN -- SumaCuotasFSN SELECT --@SumaCuotasCIC = CONVERT(FLOAT,ISNULL(CargaMensualCSD,''0'')), @SumaCuotasFSN = (CONVERT(FLOAT,ISNULL(CuotasNoReguladasCSD,''0''))/@i_tipo_cambio) FROM [BPMPRENDARIO].[Global].[InformacionIngresosCliente] WHERE IdCliente = @i_idcliente END BEGIN-- SumaCuotasCIC SELECT @SumaCuotasCIC_COLONES =ISNULL(SUM(CONVERT(FLOAT,ISNULL(REPLACE(so_cuota_esc_normal ,'','',''''),''0''))),0) FROM [BPMPRENDARIO].[Prendario].[SensibilizacionOperacion] WHERE so_solicitud =@i_solicitud AND so_co_moneda = 0 and so_id_operacion != ''Operacion del Tramite Actual'' SELECT @SumaCuotasCIC_DOLARES =ISNULL(SUM(CONVERT(FLOAT,ISNULL(REPLACE(so_cuota_esc_normal ,'','',''''),''0''))),0) FROM [BPMPRENDARIO].[Prendario].[SensibilizacionOperacion] WHERE so_solicitud =@i_solicitud AND so_co_moneda = 1 and so_id_operacion != ''Operacion del Tramite Actual'' SET @SumaCuotasCIC = @SumaCuotasCIC_COLONES + (@SumaCuotasCIC_DOLARES*@i_tipo_cambio) END BEGIN -- Nueva Cuota SELECT @NuevaCuota = so_cuota_esc_normal FROM [BPMPRENDARIO].[Prendario].[SensibilizacionOperacion] WHERE so_id_operacion = ''Operacion del Tramite Actual'' AND so_solicitud = @i_solicitud END BEGIN -- No Aplica IF (@MonedaIngresos = @MonedaDeudaActual and @MonedaDeudaActual = @NuevaDeuda) BEGIN SET @DesRiesgoCambiario = ''No Aplica'' SET @CodRiesgoCambiario = ''0'' END END IF (@CodRiesgoCambiario != ''0'') BEGIN IF (@MonedaIngresos = ''C'' and @MonedaDeudaActual = ''C'' and @NuevaDeuda = ''C'') BEGIN SELECT ''0'' as IdRiesgoCambiarioDeudor, ''No Aplica'' as DescripcionRiesgoCambiarioDeudor END -- Para Ingreso en Colones / Deudas en Colones / Nueva deuda Dólares: IF (@MonedaIngresos = ''C'' and @MonedaDeudaActual = ''C'' and @NuevaDeuda = ''D'') BEGIN SELECT @RiesgoCambiario = (@SumaCuotasCIC + @SumaCuotasFSN + (@NuevaCuota * @i_tipo_cambio)) / @i_ingreso_neto_col END -- Para Ingreso en Colones / Deudas en Dólares / Nueva deuda Dólares: -- Para Ingreso en Colones / Deudas en Dólares / Nueva deuda Colones: -- Para Ingreso en Colones / Deudas Ambas Monedas / Nueva deuda Dólares: -- Para Ingreso en Colones / Deudas Ambas Monedas / Nueva deuda Colones: IF ((@MonedaIngresos = ''C'' and @MonedaDeudaActual = ''D'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''C'' and @MonedaDeudaActual = ''D'' and @NuevaDeuda = ''C'') OR (@MonedaIngresos = ''C'' and @MonedaDeudaActual = ''T'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''C'' and @MonedaDeudaActual = ''T'' and @NuevaDeuda = ''C'')) BEGIN SELECT @RiesgoCambiario = (@SumaCuotasCIC + (@SumaCuotasFSN * @i_tipo_cambio) + (@NuevaCuota * @i_tipo_cambio)) / @i_ingreso_neto_col END -- Para Ingreso en Dólares / Deudas en Colones / Nueva deuda Dólares: -- Para Ingreso en Dólares / Deudas en Colones / Nueva deuda Colones: -- Para Ingreso en Dólares / Deudas en Dólares / Nueva deuda Colones: IF ((@MonedaIngresos = ''D'' and @MonedaDeudaActual = ''C'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''D'' and @MonedaDeudaActual = ''C'' and @NuevaDeuda = ''C'') OR (@MonedaIngresos = ''D'' and @MonedaDeudaActual = ''D'' and @NuevaDeuda = ''C'')) BEGIN SELECT @RiesgoCambiario = (@SumaCuotasCIC + @SumaCuotasFSN + (@NuevaCuota * @i_tipo_cambio)) / (@i_ingreso_neto_dol* @i_tipo_cambio) END -- Para Ingreso en Dólares / Deudas Ambas Monedas / Nueva deuda Dólares: -- Para Ingreso en Dólares / Deudas Ambas Monedas / Nueva deuda Colones: -- Para Ingreso Ambas Monedas / Deudas en colones / Nueva deuda Colones: -- Para Ingreso Ambas Monedas / Deudas en Dólares / Nueva deuda Colones: -- Para Ingreso Ambas Monedas / Deudas en Dólares / Nueva deuda Dólares: -- Para Ingreso Ambas Monedas / Deudas en Colones / Nueva deuda Dólares: -- Para Ingreso Ambas Monedas / Deudas en Ambas Monedas / Nueva deuda Dólares: -- Para Ingreso Ambas Monedas / Deudas en Ambas Monedas / Nueva deuda Colones: IF ((@MonedaIngresos = ''D'' and @MonedaDeudaActual = ''T'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''D'' and @MonedaDeudaActual = ''T'' and @NuevaDeuda = ''C'') OR (@MonedaIngresos = ''T'' and @MonedaDeudaActual = ''D'' and @NuevaDeuda = ''C'') OR (@MonedaIngresos = ''T'' and @MonedaDeudaActual = ''D'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''T'' and @MonedaDeudaActual = ''C'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''T'' and @MonedaDeudaActual = ''T'' and @NuevaDeuda = ''D'') OR (@MonedaIngresos = ''T'' and @MonedaDeudaActual = ''T'' and @NuevaDeuda = ''C'')) BEGIN SELECT @RiesgoCambiario = (@SumaCuotasCIC + (@SumaCuotasFSN * @i_tipo_cambio) + (@NuevaCuota * @i_tipo_cambio)) / ((@i_ingreso_neto_dol * @i_tipo_cambio) + @i_ingreso_neto_col) END -- Para Ingreso Ambas Monedas / Deudas en colones / Nueva deuda Colones: IF (@MonedaIngresos = ''T'' and @MonedaDeudaActual = ''C'' and @NuevaDeuda = ''C'') BEGIN SELECT @RiesgoCambiario = (@SumaCuotasCIC + @SumaCuotasFSN + (@NuevaCuota * @i_tipo_cambio)) / ((@i_ingreso_neto_dol * @i_tipo_cambio) + @i_ingreso_neto_col) END select @PuntoCorte = PorcentajePuntoCorteCSD from [BPMPRENDARIO].[Catalogos].[PuntoCorteCSD] where IdPuntoCorteCSD = 1 IF (@RiesgoCambiario <= @PuntoCorte) BEGIN SET @DesRiesgoCambiario = ''Deudor con Bajo Riesgo Cambiario'' SET @CodRiesgoCambiario = ''1'' END ELSE IF (@RiesgoCambiario > @PuntoCorte) BEGIN SET @DesRiesgoCambiario = ''Deudor con Alto Riesgo Cambiario'' SET @CodRiesgoCambiario = ''2'' END END SELECT @o_res_code = 0, @o_res_message = ''EXITOSO'' SELECT res_riesgo_cambiario = @DesRiesgoCambiario, res_cod_riesgo_cambiario = @CodRiesgoCambiario, res_code = @o_res_code, res_message = @o_res_message, res_err_procedure = @o_res_err_procedure, res_err_line = @o_res_err_line END IF @i_opcion = 2 BEGIN BEGIN -- SumaCuotasFSN SELECT --@SumaCuotasCIC = CONVERT(FLOAT,ISNULL(CargaMensualCSD,''0'')), @SumaCuotasFSN = (CONVERT(FLOAT,ISNULL(CuotasNoReguladasCSD,''0''))/@i_tipo_cambio) FROM [BPMPRENDARIO].[Global].[InformacionIngresosCliente] WHERE IdCliente = @i_idcliente END BEGIN -- SumaCuotasCIC SELECT @SumaCuotasCIC_COLONES =ISNULL(SUM(CONVERT(FLOAT,ISNULL(REPLACE(so_cuota_esc_severo ,'','',''''),''0''))),0) FROM [BPMPRENDARIO].[Prendario].[SensibilizacionOperacion] WHERE so_solicitud =@i_solicitud AND so_co_moneda = 0 and so_id_operacion != ''Operacion del Tramite Actual'' SELECT @SumaCuotasCIC_DOLARES =ISNULL(SUM(CONVERT(FLOAT,ISNULL(REPLACE(so_cuota_esc_severo ,'','',''''),''0''))),0) FROM [BPMPRENDARIO].[Prendario].[SensibilizacionOperacion] WHERE so_solicitud =@i_solicitud AND so_co_moneda = 1 and so_id_operacion != ''Operacion del Tramite Actual'' SET @SumaCuotasCIC = ((@SumaCuotasCIC_COLONES)/@i_tipo_cambio) + (@SumaCuotasCIC_DOLARES) END BEGIN -- Nueva Cuota SELECT @NuevaCuota = so_cuota_esc_severo FROM [BPMPRENDARIO].[Prendario].[SensibilizacionOperacion] WHERE so_id_operacion = ''Operacion del Tramite Actual'' AND so_solicitud = @i_solicitud END Set @CSD = ((@SumaCuotasCIC + @SumaCuotasFSN + @NuevaCuota) / ((@i_ingreso_bruto_col/ @i_tipo_cambio) + @i_ingreso_bruto_dol)) --SELECT @CSD =((@SumaCuotasCIC + @SumaCuotasFSN + @NuevaCuota) / ((@i_ingreso_bruto_dol * @i_tipo_cambio) + @i_ingreso_bruto_col)) * 100 --select @CSD SELECT @o_res_code = 0, @o_res_message = ''EXITOSO'' SELECT CSD = @CSD, res_code = @o_res_code, res_message = @o_res_message, res_err_procedure = @o_res_err_procedure, res_err_line = @o_res_err_line END END TRY BEGIN CATCH SELECT @o_res_code = ERROR_NUMBER(), @o_res_message = ERROR_MESSAGE(), @o_res_err_procedure = ERROR_PROCEDURE(), @o_res_err_line = ERROR_LINE() END CATCH ' END GO /****** Object: StoredProcedure [dbo].[usp_wf_sensibilizacion_deudas] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_wf_sensibilizacion_deudas]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' ------------------------------------------------------------------------------ -- Ultimus LA -- Nombre SP: usp_wf_sensibilizacion_deudas -- Proceso Utiliza: PRESTAMO PRENDARIO -- Creado Por: Byron Madrigal -- Fecha Creación: 21/11/2016 ------------------------------------------------------------------------------ -- Modif. Por: -- Modif. Fecha : -- Modif. Detalle: ------------------------------------------------------------------------------ /* exec [usp_wf_sensibilizacion_deudas] @i_opcion = 1, @i_incidente = 226, @i_idsolicitud = 268, @i_idcliente = 306, @i_identificacion = ''01-0790-0113'', @i_co_tipoparticipante = 1, @i_proceso = ''PrestamoPrendario'', @i_ingreso_neto_col = 4677350, @i_ingreso_neto_dol = 3268.49, @i_tipo_cambio = 562.75, @i_cuota = 1102.7118179391582, @i_tasa = 8.71, @i_tipo_tasa = ''V'', @i_co_moneda = 1, @i_plazo_meses = 96, @i_monto = 73022.81, @i_seguros = 81.09 */ CREATE PROCEDURE [dbo].[usp_wf_sensibilizacion_deudas] @i_opcion INT, @i_incidente INT = 0, @i_idsolicitud INT = 0, @i_proceso VARCHAR(50) = '''', @i_idcliente INT = 0, @i_identificacion VARCHAR(30) = '''', @i_co_tipoparticipante BIT = 1, @i_ingreso_neto_col FLOAT = NULL, @i_ingreso_neto_dol FLOAT = NULL, @i_tipo_cambio FLOAT = NULL, @i_cuota FLOAT = 0, @i_tasa FLOAT = 0, @i_tipo_tasa VARCHAR(10) = ''F'', --F=Fija, V=Variable @i_co_moneda INT = 0, --0=Colones, 1=Dolares @i_plazo_meses INT = 0, @i_monto FLOAT = 0, @i_seguros FLOAT = 0 AS DECLARE @o_res_code INT, @o_res_message NVARCHAR(MAX), @o_res_err_procedure NVARCHAR(MAX), @o_res_err_line INT, @i_incidente_corte INT IF @i_opcion = 1 BEGIN BEGIN TRY BEGIN TRAN T1 Set @i_incidente_corte = 227; --ALR 09052017(Se cambia la forma de sensibilizacion dependeiendo de la fecha del incidente) IF(@i_incidente >= @i_incidente_corte) BEGIN --INICIO DE SENSIBILIZACION DE INCIDENTES MAYORES AL 18-04-2017 SELECT @i_ingreso_neto_col = ISNULL(@i_ingreso_neto_col,0), @i_ingreso_neto_dol = ISNULL(@i_ingreso_neto_dol,0), @i_tipo_cambio = ISNULL(@i_tipo_cambio,1) ---Crea la estructura estandar para el temporal de situacion actual CREATE TABLE #Temp_Situacion_Actual ( [IdSituacionActual] [int] NOT NULL, [IdSolicitud] [int] NULL, [IdCliente] [int] NULL, [Incidente] [int] NULL, [Proceso] [nchar](48) NULL, [Identificacion] [varchar](30) NULL, [EsDeudor] [bit] NULL, [Estado] [char](1) NULL, [IdOperacion] [varchar](30) NULL, [Moneda] [varchar](50) NULL, [FecVencimiento] [varchar](15) NULL, [TipoOperacion] [varchar](50) NULL, [Condicion] [varchar](50) NULL, [EstadoOperacion] [varchar](50) NULL, [DiasAtraso] [int] NULL, [EntidadAcreedora] [varchar](50) NULL, [Saldo] [varchar](20) NULL, [CuotasEquivalente] [varchar](20) NULL, [MontoOriginal] [varchar](20) NULL, [FecInicio] [varchar](10) NULL, [MontoNoDesembolsado] [varchar](50) NULL, [Cancela] [int] NULL, [CuotaPrincipal] [decimal](18, 2) NULL, [CuotaIntereses] [decimal](18, 2) NULL, [TipoTasa] [varchar](50) NULL, [TasaNominal] [decimal](18, 2) NULL, [DTI_MiniEndeudamiento] [decimal](18, 2) NULL, [CuotaCertificada] [varchar](20) NULL, ) ---Crea la estructura estandar para el temporal de situacion actual CREATE TABLE #Temp_Sensibilizacion_Operacion ( so_incidente int NOT NULL, so_solicitud int NOT NULL, so_proceso varchar(30) NOT NULL, so_idcliente int NOT NULL, so_identificacion varchar(30) NOT NULL, so_esdeudor bit NOT NULL, so_estado char(1) NOT NULL, so_id_operacion varchar(50) NOT NULL, so_refinancia bit NULL, so_meses_plazo_restante float NULL, so_producto varchar(20) NULL, so_cuota_generada float NULL, so_cuota_sin_seguro float NULL, so_cuota_seguro float NULL, ---Cuota Estresada so_cuota_esc_normal float NULL, so_cuota_esc_leve float NULL, so_cuota_esc_moderado float NULL, so_cuota_esc_severo float NULL, ---Cuota MiniEndeudamiento so_dti_esc_normal float NULL, so_dti_esc_leve float NULL, so_dti_esc_moderado float NULL, so_dti_esc_severo float NULL, so_co_moneda int NULL, ---Tipo Cambio Devaluacion so_tip_camb_deval_esc_normal float NULL, so_tip_camb_deval_esc_leve float NULL, so_tip_camb_deval_esc_moderado float NULL, so_tip_camb_deval_esc_servero float NULL, ---Tipo Cambio Revaluacion so_tip_camb_reval_esc_normal float NULL, so_tip_camb_reval_esc_leve float NULL, so_tip_camb_reval_esc_moderado float NULL, so_tip_camb_reval_esc_servero float NULL, ---Ingresos Colones so_ingreso_col_esc_normal float NULL, so_ingreso_col_esc_leve float NULL, so_ingreso_col_esc_moderado float NULL, so_ingreso_col_esc_severo float NULL, ---Ingresos Colones so_ingreso_dol_esc_normal float NULL, so_ingreso_dol_esc_leve float NULL, so_ingreso_dol_esc_moderado float NULL, so_ingreso_dol_esc_severo float NULL, ) CREATE TABLE #Temp_Sensibilizacion_Resumen ( [sr_incidente] [int] NOT NULL, [sr_solicitud] [int] NOT NULL, [sr_proceso] [varchar](30) NOT NULL, [sr_idcliente] int NOT NULL, [sr_identificacion] [varchar](30) NOT NULL, [sr_cuota_esc_normal] [float] NULL, [sr_cuota_esc_leve] [float] NULL, [sr_cuota_esc_moderado] [float] NULL, [sr_cuota_esc_severo] [float] NULL, [sr_co_moneda] [int] NOT NULL, [sr_endeuda_esc_normal] [float] NULL, [sr_endeuda_esc_leve] [float] NULL, [sr_endeuda_esc_moderado] [float] NULL, [sr_endeuda_esc_severo] [float] NULL ) ---Obtiene la configuracion de los parametros de shock de Tipo de Cambio SELECT [st_codigo], [st_esc_normal], [st_esc_leve], [st_esc_moderado], [st_esc_severo], [st_cod_moneda], [st_estado] INTO #Temp_Parametrizacion_Shock_Tipo_Cambio FROM BPMDATA.Parametros.WFShockTipoCambio WHERE st_estado = 1 IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tipo_Cambio)) THROW 51000, ''No existe parametrización vigente para el shock de tipo de cambio '', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tipo_Cambio WHERE st_cod_moneda = 0)) THROW 51001, ''No existe parametrización vigente para el shock de tipo de cambio para la moneda colones'', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tipo_Cambio WHERE st_cod_moneda = 1)) THROW 51002, ''No existe parametrización vigente para el shock de tipo de cambio para la moneda dolares'', 1; ---Obtiene la configuracion de los parametros de shock de tasa de interes SELECT [st_codigo], [st_esc_normal], [st_esc_leve], [st_esc_moderado], [st_esc_severo], [st_cod_moneda], [st_estado] INTO #Temp_Parametrizacion_Shock_Tasa_Interes FROM BPMDATA.Parametros.WFShockTasaInteres WHERE st_estado = 1 IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tasa_Interes)) THROW 51003, ''No existe parametrización para el shock de tasa de interes '', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tasa_Interes WHERE st_cod_moneda = 0)) THROW 51004, ''No existe parametrización para el shock de tasa de interes para la moneda colones '', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tasa_Interes WHERE st_cod_moneda = 1)) THROW 51005, ''No existe parametrización para el shock de tasa de interes para la moneda dolares'', 1; ---Obtiene la Situacion Actual del Cliente IF(CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0) INSERT INTO #Temp_Situacion_Actual SELECT * FROM BPMPRENDARIO.Prendario.SituacionActual WHERE IdSolicitud = @i_idsolicitud AND Proceso = @i_proceso AND IdCliente = @i_idcliente INSERT INTO #Temp_Situacion_Actual( [IdSituacionActual], [IdSolicitud], [IdCliente], [Incidente], [Proceso], [Identificacion], [EsDeudor], [Estado], [IdOperacion], [Moneda], [FecVencimiento], [TipoOperacion], [Condicion], [EstadoOperacion], [DiasAtraso], [EntidadAcreedora], [Saldo], [CuotasEquivalente], [MontoOriginal], [FecInicio], [MontoNoDesembolsado], [Cancela], [CuotaPrincipal], [CuotaIntereses], [TipoTasa], [TasaNominal], [DTI_MiniEndeudamiento] ) SELECT [IdSituacionActual] = ISNULL((SELECT MAX([IdSituacionActual])+1 FROM BPMPRENDARIO.Prendario.SituacionActual ),1), [IdSolicitud] = @i_idsolicitud, [IdCliente] = @i_idcliente, [Incidente] = @i_incidente, [Proceso] = @i_proceso, [Identificacion] = @i_identificacion, [EsDeudor] = 1, [Estado] = ''C'', [IdOperacion] = ''Operacion del Tramite Actual'', [Moneda] = @i_co_moneda, [FecVencimiento] = CONVERT(VARCHAR,DATEADD(DAY, (@i_plazo_meses * 30), GETDATE()),103), [TipoOperacion] = CASE WHEN CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0 THEN ''1'' WHEN CHARINDEX(''TARJETA'', @i_proceso, 0) > 0 THEN ''3'' END, [Condicion] = ''DEUDOR'', [EstadoOperacion] = ''VIGENTE'', [DiasAtraso] = 0, [EntidadAcreedora] = ''Banco Davivienda (Costa Rica)'', [Saldo] = @i_monto, [CuotasEquivalente] = 0, [MontoOriginal] = @i_monto, [FecInicio] = CONVERT(VARCHAR,GETDATE(),103), [MontoNoDesembolsado] = @i_monto, [Cancela] = 0, [CuotaPrincipal] = 0, [CuotaIntereses] = 0, [TipoTasa] = @i_tipo_tasa, [TasaNominal] = @i_tasa, [DTI_MiniEndeudamiento] = 0 ---Obtiene el código del tipo de operacion UPDATE #Temp_Situacion_Actual SET TipoOperacion = RTRIM(SUBSTRING(TipoOperacion,0, CHARINDEX(''-'',TipoOperacion))) ---Carga la temporal de sensibilizacion operacion con la informacion base de la Situacion Actual INSERT INTO #Temp_Sensibilizacion_Operacion(so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, so_esdeudor, so_estado, so_id_operacion, so_refinancia, so_meses_plazo_restante, so_co_moneda) SELECT Incidente, IdSolicitud, Proceso, IdCliente, Identificacion, EsDeudor, Estado, IdOperacion, Refinancia = CASE Cancela WHEN 1 THEN 1 ELSE 0 END, MesesPlazoRestante = CASE WHEN TipoTasa IN (''F'') OR TipoOperacion IN (3,6) THEN 0 ELSE DATEDIFF(DAY, CONVERT(DATETIME, FecInicio, 103), CONVERT(DATETIME, FecVencimiento, 103)) END, Moneda = CASE Moneda WHEN ''E - DIVISA EXTRANJERA'' THEN 1 WHEN ''N - COLONES O UNIDADES DE DESARROLLO'' THEN 0 WHEN 1 THEN 1 ELSE 0 END FROM #Temp_Situacion_Actual ---Calcula los escenarios de devaluacion del tipo de cambio UPDATE #Temp_Sensibilizacion_Operacion SET so_tip_camb_deval_esc_normal = @i_tipo_cambio * ((st_esc_normal/100)+1), so_tip_camb_deval_esc_leve = @i_tipo_cambio * ((st_esc_leve/100)+1), so_tip_camb_deval_esc_moderado = @i_tipo_cambio * ((st_esc_moderado/100)+1), so_tip_camb_deval_esc_servero = @i_tipo_cambio * ((st_esc_severo/100)+1) FROM #Temp_Parametrizacion_Shock_Tipo_Cambio WHERE st_cod_moneda = 0 ---Calcula los escenarios de revaluacion del tipo de cambio UPDATE #Temp_Sensibilizacion_Operacion SET so_tip_camb_reval_esc_normal = @i_tipo_cambio * ((st_esc_normal/100)+1), so_tip_camb_reval_esc_leve = @i_tipo_cambio * ((st_esc_leve/100)+1), so_tip_camb_reval_esc_moderado = @i_tipo_cambio * ((st_esc_moderado/100)+1), so_tip_camb_reval_esc_servero = @i_tipo_cambio * ((st_esc_severo/100)+1) FROM #Temp_Parametrizacion_Shock_Tipo_Cambio WHERE st_cod_moneda = 1 ---Calcula los escenarios los ingresos con tipo de cambio revaluado o devaluado segun la moneda UPDATE #Temp_Sensibilizacion_Operacion SET so_ingreso_col_esc_normal = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_normal), so_ingreso_col_esc_leve = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_leve), so_ingreso_col_esc_moderado = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_moderado), so_ingreso_col_esc_severo = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_servero), so_ingreso_dol_esc_normal = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_normal), so_ingreso_dol_esc_leve = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_leve), so_ingreso_dol_esc_moderado = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_moderado), so_ingreso_dol_esc_severo = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_servero) FROM #Temp_Parametrizacion_Shock_Tipo_Cambio ---Determina cual es el producto asociado UPDATE #Temp_Sensibilizacion_Operacion SET so_producto = CASE WHEN (so_meses_plazo_restante/30) > 96 THEN ''HVI'' WHEN (so_meses_plazo_restante/30) > 60 AND (so_meses_plazo_restante/30) < 84 AND CONVERT(FLOAT,B.Saldo) > 15000000 THEN ''AUTO'' WHEN (so_meses_plazo_restante/30) > 1 AND (so_meses_plazo_restante/30) < 96 AND CONVERT(FLOAT,B.Saldo) < 15000000 THEN ''CP'' ELSE NULL END FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_incidente = B.Incidente AND A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_identificacion = B.Identificacion AND A.so_id_operacion = B.IdOperacion -------------------Determina la cuota generada------------------- --Si la Cuota Certidficada es cero o nulo UPDATE A SET A.so_cuota_generada = ROUND([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''), ISNULL(B.TasaNominal,0), 0, CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 0),2) FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE B.CuotaCertificada IS NULL OR B.CuotaCertificada = ''0'' --Si la Cuota Certidficada no es cero ni nulo UPDATE A SET A.so_cuota_generada = ROUND(CONVERT(FLOAT,B.CuotaCertificada),2) FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE B.CuotaCertificada IS NOT NULL AND B.CuotaCertificada != ''0'' -------------------Calcula la cuota sin seguro y la cuota del seguro------------------- --Si la Cuota Certidficada es cero o nulo UPDATE A SET A.so_cuota_sin_seguro = A.so_cuota_generada, A.so_cuota_seguro = CASE A.so_producto WHEN ''HVI''THEN ROUND((A.so_cuota_generada * 0.1),2) WHEN ''AUTO''THEN ROUND((A.so_cuota_generada * 0.35),2) ELSE 0 END FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE A.so_id_operacion != ''Operacion del Tramite Actual'' AND (B.CuotaCertificada IS NULL OR B.CuotaCertificada = ''0'') --Si la Cuota Certidficada NO es cero ni es nulo UPDATE A SET A.so_cuota_sin_seguro = A.so_cuota_generada, A.so_cuota_seguro = 0 FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE A.so_id_operacion != ''Operacion del Tramite Actual'' AND B.CuotaCertificada IS NOT NULL AND B.CuotaCertificada != ''0'' --Si es la operacion del Tramite actual UPDATE #Temp_Sensibilizacion_Operacion SET so_cuota_sin_seguro = so_cuota_generada, so_cuota_seguro = ISNULL(@i_seguros,0) WHERE so_id_operacion = ''Operacion del Tramite Actual'' -------------------Calcula las cuotas según el escenario de estres------------------- --Si la Cuota Certidficada es cero o nulo UPDATE A SET A.so_cuota_esc_normal = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_leve = CASE WHEN B.TipoTasa IN (''V'',''FV'', ''VF'')THEN ROUND(([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''), ISNULL(B.TasaNominal,0), ISNULL(C.st_esc_leve,0), CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 1) + A.so_cuota_seguro),2) WHEN B.TipoTasa IN (''F'') THEN (A.so_cuota_sin_seguro + A.so_cuota_seguro) ELSE (A.so_cuota_sin_seguro + A.so_cuota_seguro) END, A.so_cuota_esc_moderado = CASE WHEN B.TipoTasa IN (''V'',''FV'', ''VF'')THEN ROUND(([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''),ISNULL(B.TasaNominal,0), ISNULL(C.st_esc_moderado,0), CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 2) + A.so_cuota_seguro),2) WHEN B.TipoTasa IN (''F'') THEN (A.so_cuota_sin_seguro + A.so_cuota_seguro) ELSE (A.so_cuota_sin_seguro + A.so_cuota_seguro) END, A.so_cuota_esc_severo = CASE WHEN B.TipoTasa IN (''V'',''FV'', ''VF'')THEN ROUND(([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''),ISNULL(B.TasaNominal,0), ISNULL(C.st_esc_severo,0), CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 3) + A.so_cuota_seguro),2) WHEN B.TipoTasa IN (''F'') THEN (A.so_cuota_sin_seguro + A.so_cuota_seguro) ELSE (A.so_cuota_sin_seguro + A.so_cuota_seguro) END FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion INNER JOIN #Temp_Parametrizacion_Shock_Tasa_Interes C ON (A.so_co_moneda = C.st_cod_moneda) WHERE B.CuotaCertificada IS NULL OR B.CuotaCertificada = ''0'' --Si la Cuota Certidficada NO es cero ni es nulo UPDATE A SET A.so_cuota_esc_normal = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_leve = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_moderado = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_severo = (A.so_cuota_sin_seguro + A.so_cuota_seguro) FROM #Temp_Sensibilizacion_Operacion A INNER JOIN #Temp_Situacion_Actual B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion INNER JOIN #Temp_Parametrizacion_Shock_Tasa_Interes C ON (A.so_co_moneda = C.st_cod_moneda) WHERE B.CuotaCertificada IS NOT NULL AND B.CuotaCertificada != ''0'' -------------------Calcula los mini-endeudamientos según el escenario de estres------------------- UPDATE #Temp_Sensibilizacion_Operacion SET so_dti_esc_normal = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_normal/ so_ingreso_col_esc_normal) WHEN 1 THEN (so_cuota_esc_normal/ so_ingreso_dol_esc_normal) END, so_dti_esc_leve = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_leve/ so_ingreso_col_esc_leve) WHEN 1 THEN (so_cuota_esc_leve/ so_ingreso_dol_esc_leve) END, so_dti_esc_moderado = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_moderado/ so_ingreso_col_esc_moderado) WHEN 1 THEN (so_cuota_esc_moderado/ so_ingreso_dol_esc_moderado) END, so_dti_esc_severo = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_severo/ so_ingreso_col_esc_severo) WHEN 1 THEN (so_cuota_esc_severo/ so_ingreso_dol_esc_severo) END INSERT INTO #Temp_Sensibilizacion_Resumen SELECT so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, SUM(so_cuota_esc_normal), SUM(so_cuota_esc_leve), SUM(so_cuota_esc_moderado), SUM(so_cuota_esc_severo), so_co_moneda, 0, 0, 0, 0 FROM #Temp_Sensibilizacion_Operacion GROUP BY so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, so_co_moneda UPDATE #Temp_Sensibilizacion_Resumen SET sr_endeuda_esc_normal = A.sr_endeuda_esc_normal, sr_endeuda_esc_leve = A.sr_endeuda_esc_leve, sr_endeuda_esc_moderado = A.sr_endeuda_esc_moderado, sr_endeuda_esc_severo = A.sr_endeuda_esc_severo FROM (SELECT sr_endeuda_esc_normal = SUM(so_dti_esc_normal), sr_endeuda_esc_leve = SUM(so_dti_esc_leve), sr_endeuda_esc_moderado = SUM(so_dti_esc_moderado), sr_endeuda_esc_severo = SUM(so_dti_esc_severo) FROM #Temp_Sensibilizacion_Operacion)A IF(CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0) BEGIN DELETE BPMPRENDARIO.Prendario.SensibilizacionOperacion WHERE --so_incidente = @i_incidente so_solicitud = @i_idsolicitud AND so_proceso = @i_proceso AND so_idcliente = @i_idcliente --AND so_identificacion = @i_identificacion DELETE BPMPRENDARIO.Prendario.SensibilizacionResumen WHERE --sr_incidente = @i_incidente sr_solicitud = @i_idsolicitud AND sr_proceso = @i_proceso AND sr_idcliente = @i_idcliente --AND sr_identificacion = @i_identificacion INSERT INTO BPMPRENDARIO.Prendario.SensibilizacionOperacion SELECT * FROM #Temp_Sensibilizacion_Operacion INSERT INTO BPMPRENDARIO.Prendario.SensibilizacionResumen SELECT * FROM #Temp_Sensibilizacion_Resumen END SELECT @o_res_code = 0, @o_res_message = ''EXITOSO'' --FIN DE SENSIBILIZACION DE INCIDENTES MAYORES AL 18-04-2017 END ELSE BEGIN --INICIO DE SENSIBILIZACION DE INCIDENTES MENORES AL 18-04-2017 SELECT @i_ingreso_neto_col = ISNULL(@i_ingreso_neto_col,0), @i_ingreso_neto_dol = ISNULL(@i_ingreso_neto_dol,0), @i_tipo_cambio = ISNULL(@i_tipo_cambio,1) ---Crea la estructura estandar para el temporal de situacion actual CREATE TABLE #Temp_Situacion_Actual1 ( [IdSituacionActual] [int] NOT NULL, [IdSolicitud] [int] NULL, [IdCliente] [int] NULL, [Incidente] [int] NULL, [Proceso] [nchar](48) NULL, [Identificacion] [varchar](30) NULL, [EsDeudor] [bit] NULL, [Estado] [char](1) NULL, [IdOperacion] [varchar](30) NULL, [Moneda] [varchar](50) NULL, [FecVencimiento] [varchar](15) NULL, [TipoOperacion] [varchar](50) NULL, [Condicion] [varchar](50) NULL, [EstadoOperacion] [varchar](50) NULL, [DiasAtraso] [int] NULL, [EntidadAcreedora] [varchar](50) NULL, [Saldo] FLOAT NULL, [CuotasEquivalente] FLOAT NULL, [MontoOriginal] [varchar](20) NULL, [FecInicio] [varchar](10) NULL, [MontoNoDesembolsado] FLOAT NULL, [Cancela] [int] NULL, [CuotaPrincipal] [decimal](18, 2) NULL, [CuotaIntereses] [decimal](18, 2) NULL, [TipoTasa] [varchar](50) NULL, [TasaNominal] [decimal](18, 2) NULL, [DTI_MiniEndeudamiento] [decimal](18, 2) NULL, [CuotaCertificada] [varchar](20) NULL, ) ---Crea la estructura estandar para el temporal de situacion actual CREATE TABLE #Temp_Sensibilizacion_Operacion1 ( so_incidente int NOT NULL, so_solicitud int NOT NULL, so_proceso varchar(30) NOT NULL, so_idcliente int NOT NULL, so_identificacion varchar(30) NOT NULL, so_esdeudor bit NOT NULL, so_estado char(1) NOT NULL, so_id_operacion varchar(50) NOT NULL, so_refinancia bit NULL, so_meses_plazo_restante float NULL, so_producto varchar(20) NULL, so_cuota_generada float NULL, so_cuota_sin_seguro float NULL, so_cuota_seguro float NULL, ---Cuota Estresada so_cuota_esc_normal float NULL, so_cuota_esc_leve float NULL, so_cuota_esc_moderado float NULL, so_cuota_esc_severo float NULL, ---Cuota MiniEndeudamiento so_dti_esc_normal float NULL, so_dti_esc_leve float NULL, so_dti_esc_moderado float NULL, so_dti_esc_severo float NULL, so_co_moneda int NULL, ---Tipo Cambio Devaluacion so_tip_camb_deval_esc_normal float NULL, so_tip_camb_deval_esc_leve float NULL, so_tip_camb_deval_esc_moderado float NULL, so_tip_camb_deval_esc_servero float NULL, ---Tipo Cambio Revaluacion so_tip_camb_reval_esc_normal float NULL, so_tip_camb_reval_esc_leve float NULL, so_tip_camb_reval_esc_moderado float NULL, so_tip_camb_reval_esc_servero float NULL, ---Ingresos Colones so_ingreso_col_esc_normal float NULL, so_ingreso_col_esc_leve float NULL, so_ingreso_col_esc_moderado float NULL, so_ingreso_col_esc_severo float NULL, ---Ingresos Colones so_ingreso_dol_esc_normal float NULL, so_ingreso_dol_esc_leve float NULL, so_ingreso_dol_esc_moderado float NULL, so_ingreso_dol_esc_severo float NULL, ) CREATE TABLE #Temp_Sensibilizacion_Resumen1 ( [sr_incidente] [int] NOT NULL, [sr_solicitud] [int] NOT NULL, [sr_proceso] [varchar](30) NOT NULL, [sr_idcliente] int NOT NULL, [sr_identificacion] [varchar](30) NOT NULL, [sr_cuota_esc_normal] [float] NULL, [sr_cuota_esc_leve] [float] NULL, [sr_cuota_esc_moderado] [float] NULL, [sr_cuota_esc_severo] [float] NULL, [sr_co_moneda] [int] NOT NULL, [sr_endeuda_esc_normal] [float] NULL, [sr_endeuda_esc_leve] [float] NULL, [sr_endeuda_esc_moderado] [float] NULL, [sr_endeuda_esc_severo] [float] NULL ) ---Obtiene la configuracion de los parametros de shock de Tipo de Cambio SELECT [st_codigo], [st_esc_normal], [st_esc_leve], [st_esc_moderado], [st_esc_severo], [st_cod_moneda], [st_estado] INTO #Temp_Parametrizacion_Shock_Tipo_Cambio1 FROM BPMDATA.Parametros.WFShockTipoCambio WHERE st_estado = 1 IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tipo_Cambio1)) THROW 51000, ''No existe parametrización vigente para el shock de tipo de cambio '', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tipo_Cambio1 WHERE st_cod_moneda = 0)) THROW 51001, ''No existe parametrización vigente para el shock de tipo de cambio para la moneda colones'', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tipo_Cambio1 WHERE st_cod_moneda = 1)) THROW 51002, ''No existe parametrización vigente para el shock de tipo de cambio para la moneda dolares'', 1; ---Obtiene la configuracion de los parametros de shock de tasa de interes SELECT [st_codigo], [st_esc_normal], [st_esc_leve], [st_esc_moderado], [st_esc_severo], [st_cod_moneda], [st_estado] INTO #Temp_Parametrizacion_Shock_Tasa_Interes1 FROM BPMDATA.Parametros.WFShockTasaInteres WHERE st_estado = 1 IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tasa_Interes1)) THROW 51003, ''No existe parametrización para el shock de tasa de interes '', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tasa_Interes1 WHERE st_cod_moneda = 0)) THROW 51004, ''No existe parametrización para el shock de tasa de interes para la moneda colones '', 1; IF(NOT EXISTS(SELECT TOP 1 st_codigo FROM #Temp_Parametrizacion_Shock_Tasa_Interes1 WHERE st_cod_moneda = 1)) THROW 51005, ''No existe parametrización para el shock de tasa de interes para la moneda dolares'', 1; ---Obtiene la Situacion Actual del Cliente IF(CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0) INSERT INTO #Temp_Situacion_Actual1( [IdSituacionActual], [IdSolicitud], [IdCliente], [Incidente], [Proceso], [Identificacion], [EsDeudor], [Estado], [IdOperacion], [Moneda], [FecVencimiento], [TipoOperacion], [Condicion], [EstadoOperacion], [DiasAtraso], [EntidadAcreedora], [Saldo], [CuotasEquivalente], [MontoOriginal], [FecInicio], [MontoNoDesembolsado], [Cancela], [CuotaPrincipal], [CuotaIntereses], [TipoTasa], [TasaNominal], [DTI_MiniEndeudamiento], [CuotaCertificada] ) SELECT [IdSituacionActual], [IdSolicitud], [IdCliente], [Incidente], [Proceso], [Identificacion], [EsDeudor], [Estado], [IdOperacion], [Moneda], [FecVencimiento], [TipoOperacion], [Condicion], [EstadoOperacion], [DiasAtraso], [EntidadAcreedora], CASE [Moneda] WHEN ''E - DIVISA EXTRANJERA'' THEN (convert(float,[Saldo]) /@i_tipo_cambio) WHEN ''N - COLONES O UNIDADES DE DESARROLLO'' THEN convert(float,[Saldo]) ELSE convert(float,[Saldo]) END, CASE [Moneda] WHEN ''E - DIVISA EXTRANJERA'' THEN (convert(float,[CuotasEquivalente])/@i_tipo_cambio) WHEN ''N - COLONES O UNIDADES DE DESARROLLO'' THEN convert(float,[CuotasEquivalente]) ELSE convert(float,[CuotasEquivalente]) END, [MontoOriginal], [FecInicio], CASE [Moneda] WHEN ''E - DIVISA EXTRANJERA'' THEN (convert(float,[MontoNoDesembolsado])/@i_tipo_cambio) WHEN ''N - COLONES O UNIDADES DE DESARROLLO'' THEN convert(float,[MontoNoDesembolsado]) ELSE convert(float,[MontoNoDesembolsado]) END, [Cancela], [CuotaPrincipal], [CuotaIntereses], [TipoTasa], [TasaNominal], [DTI_MiniEndeudamiento], [CuotaCertificada] FROM BPMPRENDARIO.Prendario.SituacionActual WHERE IdSolicitud = @i_idsolicitud AND Proceso = @i_proceso AND IdCliente = @i_idcliente INSERT INTO #Temp_Situacion_Actual1( [IdSituacionActual], [IdSolicitud], [IdCliente], [Incidente], [Proceso], [Identificacion], [EsDeudor], [Estado], [IdOperacion], [Moneda], [FecVencimiento], [TipoOperacion], [Condicion], [EstadoOperacion], [DiasAtraso], [EntidadAcreedora], [Saldo], [CuotasEquivalente], [MontoOriginal], [FecInicio], [MontoNoDesembolsado], [Cancela], [CuotaPrincipal], [CuotaIntereses], [TipoTasa], [TasaNominal], [DTI_MiniEndeudamiento] ) SELECT [IdSituacionActual] = ISNULL((SELECT MAX([IdSituacionActual])+1 FROM BPMPRENDARIO.Prendario.SituacionActual ),1), [IdSolicitud] = @i_idsolicitud, [IdCliente] = @i_idcliente, [Incidente] = @i_incidente, [Proceso] = @i_proceso, [Identificacion] = @i_identificacion, [EsDeudor] = 1, [Estado] = ''C'', [IdOperacion] = ''Operacion del Tramite Actual'', [Moneda] = @i_co_moneda, [FecVencimiento] = CONVERT(VARCHAR,DATEADD(DAY, (@i_plazo_meses * 30), GETDATE()),103), [TipoOperacion] = CASE WHEN CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0 THEN ''1'' WHEN CHARINDEX(''TARJETA'', @i_proceso, 0) > 0 THEN ''3'' END, [Condicion] = ''DEUDOR'', [EstadoOperacion] = ''VIGENTE'', [DiasAtraso] = 0, [EntidadAcreedora] = ''Banco Davivienda (Costa Rica)'', [Saldo] = @i_monto, [CuotasEquivalente] = 0, [MontoOriginal] = @i_monto, [FecInicio] = CONVERT(VARCHAR,GETDATE(),103), [MontoNoDesembolsado] = @i_monto, [Cancela] = 0, [CuotaPrincipal] = 0, [CuotaIntereses] = 0, [TipoTasa] = @i_tipo_tasa, [TasaNominal] = @i_tasa, [DTI_MiniEndeudamiento] = 0 ---Obtiene el código del tipo de operacion UPDATE #Temp_Situacion_Actual1 SET TipoOperacion = RTRIM(SUBSTRING(TipoOperacion,0, CHARINDEX(''-'',TipoOperacion))) ---Carga la temporal de sensibilizacion operacion con la informacion base de la Situacion Actual INSERT INTO #Temp_Sensibilizacion_Operacion1(so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, so_esdeudor, so_estado, so_id_operacion, so_refinancia, so_meses_plazo_restante, so_co_moneda) SELECT Incidente, IdSolicitud, Proceso, IdCliente, Identificacion, EsDeudor, Estado, IdOperacion, Refinancia = CASE Cancela WHEN 1 THEN 1 ELSE 0 END, MesesPlazoRestante = CASE WHEN TipoTasa IN (''F'') AND TipoOperacion IN (3,6) THEN 0 ELSE DATEDIFF(DAY, CONVERT(DATETIME, FecInicio, 103), CONVERT(DATETIME, FecVencimiento, 103)) END, Moneda = CASE Moneda WHEN ''E - DIVISA EXTRANJERA'' THEN 1 WHEN ''N - COLONES O UNIDADES DE DESARROLLO'' THEN 0 WHEN 1 THEN 1 ELSE 0 END FROM #Temp_Situacion_Actual1 ---Calcula los escenarios de devaluacion del tipo de cambio UPDATE #Temp_Sensibilizacion_Operacion1 SET so_tip_camb_deval_esc_normal = @i_tipo_cambio * ((st_esc_normal/100)+1), so_tip_camb_deval_esc_leve = @i_tipo_cambio * ((st_esc_leve/100)+1), so_tip_camb_deval_esc_moderado = @i_tipo_cambio * ((st_esc_moderado/100)+1), so_tip_camb_deval_esc_servero = @i_tipo_cambio * ((st_esc_severo/100)+1) FROM #Temp_Parametrizacion_Shock_Tipo_Cambio1 WHERE st_cod_moneda = 0 ---Calcula los escenarios de revaluacion del tipo de cambio UPDATE #Temp_Sensibilizacion_Operacion1 SET so_tip_camb_reval_esc_normal = @i_tipo_cambio * ((st_esc_normal/100)+1), so_tip_camb_reval_esc_leve = @i_tipo_cambio * ((st_esc_leve/100)+1), so_tip_camb_reval_esc_moderado = @i_tipo_cambio * ((st_esc_moderado/100)+1), so_tip_camb_reval_esc_servero = @i_tipo_cambio * ((st_esc_severo/100)+1) FROM #Temp_Parametrizacion_Shock_Tipo_Cambio1 WHERE st_cod_moneda = 1 ---Calcula los escenarios los ingresos con tipo de cambio revaluado o devaluado segun la moneda UPDATE #Temp_Sensibilizacion_Operacion1 SET so_ingreso_col_esc_normal = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_normal), so_ingreso_col_esc_leve = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_leve), so_ingreso_col_esc_moderado = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_moderado), so_ingreso_col_esc_severo = @i_ingreso_neto_col + (@i_ingreso_neto_dol * so_tip_camb_deval_esc_servero), so_ingreso_dol_esc_normal = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_normal), so_ingreso_dol_esc_leve = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_leve), so_ingreso_dol_esc_moderado = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_moderado), so_ingreso_dol_esc_severo = @i_ingreso_neto_dol + (@i_ingreso_neto_col / so_tip_camb_reval_esc_servero) FROM #Temp_Parametrizacion_Shock_Tipo_Cambio1 ---Determina cual es el producto asociado UPDATE #Temp_Sensibilizacion_Operacion1 SET so_producto = CASE WHEN (so_meses_plazo_restante/30) > 96 THEN ''HVI'' WHEN (so_meses_plazo_restante/30) > 60 THEN ''AUTO'' WHEN (so_meses_plazo_restante/30) > 1 THEN ''CP'' ELSE NULL END -------------------Determina la cuota generada------------------- --Si la Cuota Certidficada es cero o nulo UPDATE A SET A.so_cuota_generada = ROUND([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''), ISNULL(B.TasaNominal,0), 0, CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 0),2) FROM #Temp_Sensibilizacion_Operacion1 A INNER JOIN #Temp_Situacion_Actual1 B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE B.CuotaCertificada IS NULL OR B.CuotaCertificada = ''0'' --Si la Cuota Certidficada no es cero ni nulo UPDATE A SET A.so_cuota_generada = ROUND(CONVERT(FLOAT,B.CuotaCertificada),2) FROM #Temp_Sensibilizacion_Operacion1 A INNER JOIN #Temp_Situacion_Actual1 B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE B.CuotaCertificada IS NOT NULL AND B.CuotaCertificada != ''0'' -------------------Calcula la cuota sin seguro y la cuota del seguro------------------- --Si la Cuota Certidficada es cero o nulo UPDATE A SET A.so_cuota_sin_seguro = A.so_cuota_generada, A.so_cuota_seguro = CASE A.so_producto WHEN ''HVI''THEN ROUND((A.so_cuota_generada * 0.1),2) WHEN ''AUTO''THEN ROUND((A.so_cuota_generada * 0.35),2) ELSE 0 END FROM #Temp_Sensibilizacion_Operacion1 A INNER JOIN #Temp_Situacion_Actual1 B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE A.so_id_operacion != ''Operacion del Tramite Actual'' AND (B.CuotaCertificada IS NULL OR B.CuotaCertificada = ''0'') --Si la Cuota Certidficada NO es cero ni es nulo UPDATE A SET A.so_cuota_sin_seguro = A.so_cuota_generada, A.so_cuota_seguro = 0 FROM #Temp_Sensibilizacion_Operacion1 A INNER JOIN #Temp_Situacion_Actual1 B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion WHERE A.so_id_operacion != ''Operacion del Tramite Actual'' AND B.CuotaCertificada IS NOT NULL AND B.CuotaCertificada != ''0'' --Si es la operacion del Tramite actual UPDATE #Temp_Sensibilizacion_Operacion1 SET so_cuota_sin_seguro = so_cuota_generada, so_cuota_seguro = ISNULL(@i_seguros,0) WHERE so_id_operacion = ''Operacion del Tramite Actual'' -------------------Calcula las cuotas según el escenario de estres------------------- --Si la Cuota Certidficada es cero o nulo UPDATE A SET A.so_cuota_esc_normal = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_leve = CASE WHEN B.TipoTasa IN (''V'',''FV'', ''VF'')THEN ROUND(([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''), ISNULL(B.TasaNominal,0), ISNULL(C.st_esc_leve,0), CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 1) + A.so_cuota_seguro),2) WHEN B.TipoTasa IN (''F'') THEN (A.so_cuota_sin_seguro + A.so_cuota_seguro) ELSE (A.so_cuota_sin_seguro + A.so_cuota_seguro) END, A.so_cuota_esc_moderado = CASE WHEN B.TipoTasa IN (''V'',''FV'', ''VF'')THEN ROUND(([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''),ISNULL(B.TasaNominal,0), ISNULL(C.st_esc_moderado,0), CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 2) + A.so_cuota_seguro),2) WHEN B.TipoTasa IN (''F'') THEN (A.so_cuota_sin_seguro + A.so_cuota_seguro) ELSE (A.so_cuota_sin_seguro + A.so_cuota_seguro) END, A.so_cuota_esc_severo = CASE WHEN B.TipoTasa IN (''V'',''FV'', ''VF'')THEN ROUND(([BPMDATA].[dbo].[F_getCuotaDTI](ISNULL(B.Condicion, ''''),ISNULL(B.TasaNominal,0), ISNULL(C.st_esc_severo,0), CONVERT(FLOAT,ISNULL(A.so_meses_plazo_restante,0)) /30, ISNULL(B.Saldo,0), B.TipoOperacion, 3) + A.so_cuota_seguro),2) WHEN B.TipoTasa IN (''F'') THEN (A.so_cuota_sin_seguro + A.so_cuota_seguro) ELSE (A.so_cuota_sin_seguro + A.so_cuota_seguro) END FROM #Temp_Sensibilizacion_Operacion1 A INNER JOIN #Temp_Situacion_Actual1 B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion INNER JOIN #Temp_Parametrizacion_Shock_Tasa_Interes1 C ON (A.so_co_moneda = C.st_cod_moneda) WHERE B.CuotaCertificada IS NULL OR B.CuotaCertificada = ''0'' --Si la Cuota Certidficada NO es cero ni es nulo UPDATE A SET A.so_cuota_esc_normal = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_leve = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_moderado = (A.so_cuota_sin_seguro + A.so_cuota_seguro), A.so_cuota_esc_severo = (A.so_cuota_sin_seguro + A.so_cuota_seguro) FROM #Temp_Sensibilizacion_Operacion1 A INNER JOIN #Temp_Situacion_Actual1 B ON A.so_solicitud = B.IdSolicitud AND A.so_proceso = B.Proceso AND A.so_idcliente = B.IdCliente AND A.so_id_operacion = B.IdOperacion INNER JOIN #Temp_Parametrizacion_Shock_Tasa_Interes1 C ON (A.so_co_moneda = C.st_cod_moneda) WHERE B.CuotaCertificada IS NOT NULL AND B.CuotaCertificada != ''0'' -------------------Calcula los mini-endeudamientos según el escenario de estres------------------- UPDATE #Temp_Sensibilizacion_Operacion1 SET so_dti_esc_normal = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_normal/ so_ingreso_col_esc_normal) WHEN 1 THEN (so_cuota_esc_normal/ so_ingreso_dol_esc_normal) END, so_dti_esc_leve = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_leve/ so_ingreso_col_esc_leve) WHEN 1 THEN (so_cuota_esc_leve/ so_ingreso_dol_esc_leve) END, so_dti_esc_moderado = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_moderado/ so_ingreso_col_esc_moderado) WHEN 1 THEN (so_cuota_esc_moderado/ so_ingreso_dol_esc_moderado) END, so_dti_esc_severo = CASE so_co_moneda WHEN 0 THEN (so_cuota_esc_severo/ so_ingreso_col_esc_severo) WHEN 1 THEN (so_cuota_esc_severo/ so_ingreso_dol_esc_severo) END INSERT INTO #Temp_Sensibilizacion_Resumen1 SELECT so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, SUM(so_cuota_esc_normal), SUM(so_cuota_esc_leve), SUM(so_cuota_esc_moderado), SUM(so_cuota_esc_severo), so_co_moneda, 0, 0, 0, 0 FROM #Temp_Sensibilizacion_Operacion1 GROUP BY so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, so_co_moneda UPDATE #Temp_Sensibilizacion_Resumen1 SET sr_endeuda_esc_normal = A.sr_endeuda_esc_normal, sr_endeuda_esc_leve = A.sr_endeuda_esc_leve, sr_endeuda_esc_moderado = A.sr_endeuda_esc_moderado, sr_endeuda_esc_severo = A.sr_endeuda_esc_severo FROM (SELECT sr_endeuda_esc_normal = SUM(so_dti_esc_normal), sr_endeuda_esc_leve = SUM(so_dti_esc_leve), sr_endeuda_esc_moderado = SUM(so_dti_esc_moderado), sr_endeuda_esc_severo = SUM(so_dti_esc_severo) FROM #Temp_Sensibilizacion_Operacion1)A IF(CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0) BEGIN DELETE BPMPRENDARIO.Prendario.SensibilizacionOperacion WHERE --so_incidente = @i_incidente so_solicitud = @i_idsolicitud AND so_proceso = @i_proceso AND so_idcliente = @i_idcliente --AND so_identificacion = @i_identificacion DELETE BPMPRENDARIO.Prendario.SensibilizacionResumen WHERE --sr_incidente = @i_incidente sr_solicitud = @i_idsolicitud AND sr_proceso = @i_proceso AND sr_idcliente = @i_idcliente --AND sr_identificacion = @i_identificacion INSERT INTO BPMPRENDARIO.Prendario.SensibilizacionOperacion SELECT * FROM #Temp_Sensibilizacion_Operacion1 INSERT INTO BPMPRENDARIO.Prendario.SensibilizacionResumen SELECT * FROM #Temp_Sensibilizacion_Resumen1 END SELECT @o_res_code = 0, @o_res_message = ''EXITOSO'' --FIN DE SENSIBILIZACION DE INCIDENTES MAYORES AL 18-04-2017 END COMMIT TRAN T1 END TRY BEGIN CATCH ROLLBACK TRAN T1 SELECT @o_res_code = ERROR_NUMBER(), @o_res_message = ERROR_MESSAGE(), @o_res_err_procedure = ERROR_PROCEDURE(), @o_res_err_line = ERROR_LINE() END CATCH SELECT res_code = @o_res_code, res_message = @o_res_message, res_err_procedure = @o_res_err_procedure, res_err_line = @o_res_err_line END IF @i_opcion = 2 BEGIN IF(CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0) BEGIN --[DataSet 1] - Calculo de Cuotas y DTI por Operacion y Moneda en cada Escenario SELECT so_incidente, so_solicitud, so_proceso, so_idcliente, so_identificacion, so_esdeudor, so_estado, so_id_operacion, so_co_moneda, so_simbolo_moneda_col = (SELECT TOP 1 Simbolo FROM BPMPRENDARIO.Catalogos.Moneda WHERE IdMoneda=0), so_simbolo_moneda_dol = (SELECT TOP 1 Simbolo FROM BPMPRENDARIO.Catalogos.Moneda WHERE IdMoneda=1), so_cuota_esc_normal_col = CASE so_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_normal AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_leve_col = CASE so_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_leve AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_moderado_col = CASE so_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_moderado AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_severo_col = CASE so_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_severo AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_normal_dol = CASE so_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_normal AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_leve_dol = CASE so_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_leve AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_moderado_dol = CASE so_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_moderado AS MONEY),1) ELSE ''0.00'' END, so_cuota_esc_severo_dol = CASE so_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(so_cuota_esc_severo AS MONEY),1) ELSE ''0.00'' END FROM BPMPRENDARIO.Prendario.SensibilizacionOperacion S WHERE ---so_incidente = @i_incidente so_solicitud = @i_idsolicitud AND so_proceso = @i_proceso AND so_idcliente = @i_idcliente --AND so_identificacion = @i_identificacion --[DataSet 2] - Resumen de Cuotas por moneda en cada Escenario SELECT sr_etiqueta = ''Totales'', A.sr_incidente, A.sr_solicitud, A.sr_proceso, A.sr_idcliente, A.sr_identificacion, sr_cuota_esc_normal_col = CASE A.sr_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(A.sr_cuota_esc_normal AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_leve_col = CASE A.sr_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(A.sr_cuota_esc_leve AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_moderado_col = CASE A.sr_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(A.sr_cuota_esc_moderado AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_severo_col = CASE A.sr_co_moneda WHEN 0 THEN CONVERT(VARCHAR,CAST(A.sr_cuota_esc_severo AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_normal_dol = CASE B.sr_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(B.sr_cuota_esc_normal AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_leve_dol = CASE B.sr_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(B.sr_cuota_esc_leve AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_moderado_dol = CASE B.sr_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(B.sr_cuota_esc_moderado AS MONEY),1) ELSE ''0.00'' END, sr_cuota_esc_severo_dol = CASE B.sr_co_moneda WHEN 1 THEN CONVERT(VARCHAR,CAST(B.sr_cuota_esc_severo AS MONEY),1) ELSE ''0.00'' END, sr_simbolo_moneda_col = (SELECT TOP 1 Simbolo FROM BPMPRENDARIO.Catalogos.Moneda WHERE IdMoneda=0), sr_simbolo_moneda_dol = (SELECT TOP 1 Simbolo FROM BPMPRENDARIO.Catalogos.Moneda WHERE IdMoneda=1) FROM ( SELECT * FROM BPMPRENDARIO.Prendario.SensibilizacionResumen WHERE ---sr_incidente = @i_incidente sr_solicitud = @i_idsolicitud AND sr_proceso = @i_proceso AND sr_idcliente = @i_idcliente --AND sr_identificacion = @i_identificacion AND sr_co_moneda = 1 )A LEFT JOIN ( SELECT * FROM BPMPRENDARIO.Prendario.SensibilizacionResumen WHERE ---sr_incidente = @i_incidente sr_solicitud = @i_idsolicitud AND sr_proceso = @i_proceso AND sr_idcliente = @i_idcliente --AND sr_identificacion = @i_identificacion AND sr_co_moneda = 0 )B ON --A.sr_incidente = B.sr_incidente A.sr_solicitud = B.sr_solicitud AND A.sr_proceso = B.sr_proceso AND A.sr_idcliente = B.sr_idcliente AND A.sr_identificacion = B.sr_identificacion --[DataSet 3] - DTI por moneda en cada Escenario SELECT DISTINCT sr_incidente, sr_solicitud, sr_proceso, sr_idcliente, sr_identificacion, sr_endeuda_esc_normal = (CONVERT(VARCHAR,CAST((sr_endeuda_esc_normal*100) AS MONEY),1) + ''%''), sr_endeuda_esc_leve = (CONVERT(VARCHAR,CAST((sr_endeuda_esc_leve*100) AS MONEY),1) + ''%''), sr_endeuda_esc_moderado = (CONVERT(VARCHAR,CAST((sr_endeuda_esc_moderado*100) AS MONEY),1) + ''%''), sr_endeuda_esc_severo = (CONVERT(VARCHAR,CAST((sr_endeuda_esc_severo*100) AS MONEY),1) + ''%'') FROM BPMPRENDARIO.Prendario.SensibilizacionResumen WHERE ---sr_incidente = @i_incidente sr_solicitud = @i_idsolicitud AND sr_proceso = @i_proceso AND sr_idcliente = @i_idcliente --AND sr_identificacion = @i_identificacion END END IF @i_opcion = 3 BEGIN IF(CHARINDEX(''PRENDARIO'', @i_proceso, 0) > 0) BEGIN SELECT DISTINCT sr_incidente, sr_solicitud, sr_proceso, sr_idcliente, sr_identificacion, sr_endeuda_esc_normal, sr_endeuda_esc_leve, sr_endeuda_esc_moderado, sr_endeuda_esc_severo FROM BPMPRENDARIO.Prendario.SensibilizacionResumen WHERE ---sr_incidente = @i_incidente sr_solicitud = @i_idsolicitud AND sr_proceso = @i_proceso AND sr_idcliente = @i_idcliente --AND sr_identificacion = @i_identificacion END END ' END GO /****** Object: UserDefinedFunction [dbo].[F_getCuotaDTI] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[F_getCuotaDTI]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) BEGIN execute dbo.sp_executesql @statement = N' /* SELECT [dbo].[F_getCuotaDTI](''DEUDOR'',15, 0, 118.80, 980849.25,''1'') SELECT [dbo].[F_getCuotaDTI](''DEUDOR'',0, 0, 0, 0,''1'') */ CREATE FUNCTION [dbo].[F_getCuotaDTI] (@i_condicion VARCHAR(50) = ''DEUDOR'', --DEUDOR, CODEUDOR, FIADOR @i_porc_tasa_nominal FLOAT = 0, --Porcentaje de Tasa Anual @i_porc_shock_tasa FLOAT = 0, --Porcentaje de Incremento de Tasa @i_plazo_meses FLOAT = 0, --Cantidad de Meses @i_saldo_monto FLOAT = 0, --Saldo o Monto del Crédito @i_tipo_operacion VARCHAR(50) = 0, --Tipo de Operacion de SUGEF --1 - 98 DIRECTA --3 - TARJETAS DE CRÉDITO --6 - LÍNEA DE CRÉDITO SIN COMPROMISO @i_escenario INT = 0 --0 - NORMAL --1 - LEVE --2 - MODERADO --3 - SEVERO ) RETURNS FLOAT --float AS BEGIN DECLARE @Value FLOAT IF((@i_tipo_operacion = ''3'' OR @i_tipo_operacion = ''6''))---AND @i_escenario = 0) SET @Value = (@i_saldo_monto * 0.04) ELSE SET @Value = (dbo.F_pmt(CONVERT(FLOAT,(@i_porc_tasa_nominal + @i_porc_shock_tasa))/12, @i_plazo_meses, (-1 * @i_saldo_monto), 0,0)) SET @Value = CASE WHEN @i_condicion = ''DEUDOR'' THEN @Value WHEN @i_condicion = ''FIADOR'' THEN 0 WHEN @i_condicion IN (''CODEUDOR'', ''CO-DEUDOR'') THEN @Value / 2 ELSE 0 END RETURN @Value END ' END GO /****** Object: UserDefinedFunction [dbo].[F_pmt] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[F_pmt]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) BEGIN execute dbo.sp_executesql @statement = N' /* declare @tasa float select @tasa = CONVERT(FLOAT,15)/12 SELECT [dbo].[F_pmt](@tasa, 118.80, -980849.25,0,0) SELECT [dbo].[F_pmt](0, 0, 0,0,0) */ CREATE FUNCTION [dbo].[F_pmt] (@InterestRate FLOAT, --Rate is the interest rate per period. @Nper FLOAT, --Nper is the total number of payment --periods in an annuity. @Pv FLOAT, --Pv is the present value, or the --lump-sum amount that a series of --future payments is worth right now. --If pv is omitted, it is assumed to be --0 (zero). PV must be entered as a --negative number. @Fv FLOAT, --Fv is the future value, or the --lump-sum amount that a series of --future payments is worth right now. --If pv is omitted, it is assumed to --be 0 (zero). PV must be entered as a --negative number. @Type BIT --Type is the number 0 or 1 and --indicates when payments are due. --If type is omitted, it is assumed --to be 0 which represents at the end --of the period. --If payments are due at the beginning --of the period, type should be 1. ) RETURNS FLOAT --float AS BEGIN DECLARE @Value FLOAT IF(@Pv IS NULL OR @Pv = 0) --Si el monto es cero o nulo retorna cero SET @Value = 0 ELSE IF(@Nper IS NULL OR @Nper = 0) -- Si el plazo es cero o nulo retorna cero SET @Value = 0 ELSE IF (@InterestRate IS NULL OR @InterestRate = 0) -- Si el interes es cero o nulo retona monto entre plazo SET @Value = ABS(@Pv / @Nper) ELSE BEGIN DECLARE @w_interes FLOAT SELECT @w_interes = Convert(float,@InterestRate) / 100 SELECT @Value = CASE WHEN @Type=0 THEN @w_interes /((Power(1+@InterestRate/100,@Nper))-1) *(-(@Pv*Power(1 + @InterestRate/100,@Nper)+@Fv)) WHEN @Type=1 THEN Convert(float,@InterestRate / 100) / (Power(Convert(float,(1 + @InterestRate / 100)),@Nper)-1) * -(@Pv*Power(Convert(float,(1 + @InterestRate / 100)),@Nper) +@Fv) /(1 + Convert(float,(@InterestRate / 100))) END END RETURN @Value END ' END GO /****** Object: Table [Parametros].[WFGradualidadCobertura] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Parametros].[WFGradualidadCobertura]') AND type in (N'U')) BEGIN CREATE TABLE [Parametros].[WFGradualidadCobertura]( [gc_codigo] [int] NOT NULL, [gc_anho] [int] NOT NULL, [gc_tipo_credito] [nvarchar](50) NOT NULL, [gc_porc_esc_normal] [float] NULL, [gc_porc_esc_severo] [float] NULL, [gc_estado] [bit] NULL, CONSTRAINT [PK_WF_GRADUALIDAD_COBERTURA] PRIMARY KEY CLUSTERED ( [gc_codigo] ASC, [gc_anho] ASC, [gc_tipo_credito] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] END GO /****** Object: Table [Parametros].[WFShockTasaInteres] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Parametros].[WFShockTasaInteres]') AND type in (N'U')) BEGIN CREATE TABLE [Parametros].[WFShockTasaInteres]( [st_codigo] [int] NOT NULL, [st_esc_normal] [decimal](18, 2) NOT NULL, [st_esc_leve] [decimal](18, 2) NOT NULL, [st_esc_moderado] [decimal](18, 2) NOT NULL, [st_esc_severo] [decimal](18, 2) NOT NULL, [st_cod_moneda] [int] NOT NULL, [st_estado] [bit] NOT NULL, CONSTRAINT [PK_WF_SHOCK_TASA_INTERES] PRIMARY KEY CLUSTERED ( [st_codigo] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] END GO /****** Object: Table [Parametros].[WFShockTipoCambio] Script Date: 16/02/2018 10:43:05 a.m. ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Parametros].[WFShockTipoCambio]') AND type in (N'U')) BEGIN CREATE TABLE [Parametros].[WFShockTipoCambio]( [st_codigo] [int] NOT NULL, [st_esc_normal] [decimal](18, 2) NOT NULL, [st_esc_leve] [decimal](18, 2) NOT NULL, [st_esc_moderado] [decimal](18, 2) NOT NULL, [st_esc_severo] [decimal](18, 2) NOT NULL, [st_cod_moneda] [int] NOT NULL, [st_estado] [bit] NOT NULL, CONSTRAINT [PK_WF_SHOCK_TIPO_CAMBIO] PRIMARY KEY CLUSTERED ( [st_codigo] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] END GO