← Índice de manuales
Manual funcional · Sistema Plenario v14

Reportes — Préstamos (Créditos)

Este catálogo reúne los stored procedures y funciones del módulo de Préstamos (Créditos) de Plenario v14 utilizados para generar informes y reportes: cancelaciones, estado de préstamos, listados para aseguradora…

Módulo: ReportesVersión: 1.0Actualizado: 2026-06-23

Reportes — Préstamos (Créditos)

Este catálogo reúne los stored procedures y funciones del módulo de Préstamos (Créditos) de Plenario v14 utilizados para generar informes y reportes: cancelaciones, estado de préstamos, listados para aseguradora, novedades de otorgamiento, informes de ventas/cesiones de cartera, cuotas acordadas, cuotas impagas y listados de créditos (detallado/resumido). Cada bloque incluye el nombre legible, el archivo fuente, el tipo de objeto, sus parámetros, las tablas/módulos que cruza y el SQL completo tal cual está en el repositorio. Las tablas principales son Prestamos_Creditos (cabecera del crédito) y Prestamos_Creditos_Detalle (cuotas), cruzadas con Clientes, Prestamos_Entidades, Prestamos_Comercializadores, Prestamos_Lineas, Prestamos_Solicitudes, Sucursales, Inversores y las tablas de ventas de cartera (Prestamos_Creditos_Ventas / _Detalle).

Datos para filtros del Informe de Cancelaciones

  • SP/archivo: Prestamos_Creditos_Cancelaciones_ObtenerDatosParaFiltrosDeInformeDeCancelaciones.proc.sql
  • Tipo: Helper de proceso
  • Parámetros: ninguno
  • Relación con módulos: Inversores (Inversores/Cartera), Prestamos_Comercializadores (Comercializadores) y Sucursales (Estructura). Devuelve solo rangos min/máx de Id.

Helper que alimenta los controles de filtro del informe de cancelaciones: devuelve los valores mínimo y máximo de Id de inversores, comercializadores y sucursales, para inicializar los rangos "desde/hasta" en pantalla. No es un reporte de usuario final.

/*
IMPORTANTE: NO MODIFICAR ESTE C?DIGO YA QUE FUE GENERADO AUTOM?TICAMENTE.


<CompoundXmlDocument>
  <User Name="PLENARIO\frocha" />
</CompoundXmlDocument>
*/

CREATE PROCEDURE [dbo].[Prestamos_Creditos_Cancelaciones_ObtenerDatosParaFiltrosDeInformeDeCancelaciones]
As

Set NoCount On

Select
    *
From
    (
    Select
        Min(I.Id) Inversores_Min
        , Max(I.Id) Inversores_Max
    From
        Inversores I
    ) T1

    , (
    Select
        Min(PCOM.Id) Comercializadores_Min
        , Max(PCOM.Id) Comercializadores_Max
    From
        Prestamos_Comercializadores PCOM
    ) T2

    , (
    Select
        Min(SUC.Id) Sucursales_Min
        , Max(SUC.Id) Sucursales_Max
    From
        Sucursales SUC
    ) T3

Reporte de Créditos Cancelados

  • SP/archivo: Prestamos_Creditos_Cancelaciones_Reportes_ObtenerCreditosCancelados.proc.sql
  • Tipo: Reporte
  • Parámetros: @Fecha_Credito_Desde, @Fecha_Credito_Hasta, @Fecha_Cancelacion_Desde, @Fecha_Cancelacion_Hasta, @Id_ProvFinan_Desde, @Id_ProvFinan_Hasta, @Id_Comercializador_Desde, @Id_Comercializador_Hasta, @IntId_Venta_Desde, @IntId_Venta_Hasta, @IntId_Inversor_Desde, @IntId_Inversor_Hasta, @IntId_Filial_Desde, @IntId_Filial_Hasta
  • Relación con módulos: Prestamos_Creditos + Prestamos_Creditos_Detalle (Préstamos), Clientes (Clientes), Prestamos_Entidades, Prestamos_Lineas, Prestamos_Comercializadores, y Prestamos_Creditos_Ventas / Prestamos_Prestadores / Inversores (Cartera/Ventas).

Lista los créditos efectivamente cancelados (Fecha_Cancelacion Is Not Null) en un rango de fechas de otorgamiento y de cancelación, con filtros por proveedor financiero/inversor, comercializador, venta y filial. Devuelve datos del cliente, capital, valor de cuota, plazo, importe total y entidad/línea/comercializador.

--================================================================================================================================================================
--================================================================================================================================================================
--================================================================================================================================================================
/*
IMPORTANTE: NO MODIFICAR ESTE CÓDIGO YA QUE FUE GENERADO AUTOMÁTICAMENTE.


<CompoundXmlDocument>
  <User Name="PLENARIO\rmarseglia" />
</CompoundXmlDocument>
*/



CREATE PROCEDURE [dbo].[Prestamos_Creditos_Cancelaciones_Reportes_ObtenerCreditosCancelados]
    @Fecha_Credito_Desde DateTime 
    , @Fecha_Credito_Hasta DateTime 
    , @Fecha_Cancelacion_Desde DateTime 
    , @Fecha_Cancelacion_Hasta DateTime 

    , @Id_ProvFinan_Desde Int=-1 
    , @Id_ProvFinan_Hasta Int=-1 
    , @Id_Comercializador_Desde Int 
    , @Id_Comercializador_Hasta Int 

    , @IntId_Venta_Desde int=-1
    , @IntId_Venta_Hasta int=-1
    , @IntId_Inversor_Desde int=-1
    , @IntId_Inversor_Hasta int=-1

    , @IntId_Filial_Desde int 
    , @IntId_Filial_Hasta int 

As

Set NoCount On

Select
    PC.Id
    , PC.Fecha_Otorgado
    , PC.Id_Cliente
    , C.Nombre Nombre_Cliente
    , C.NroDoc NroDoc_Cliente
    , C.NroBeneficiario
    , C.NroLegajo
    , PC.Capital
    , PC.ValorCuota
    , PC.Plazo
    , PC.ValorCuota * PC.Plazo Importe_Total_Prestamo
    , PC.Fecha_Cancelacion
    , PC.Id_Entidad
    , PE.Nombre Nombre_Entidad
    , PC.Id_Linea
    , PL.Descripcion Nombre_Linea
    , PC.Id_Comercializador
    , PCO.Nombre Nombre_Comercializador
From
    Prestamos_Creditos PC Inner Join Clientes C
        On PC.Id_Cliente = C.Id
    Inner Join [dbo].[Prestamos_Creditos_Detalle] PCD
        On PC.Id = PCD.Id_Credito
    Inner Join Prestamos_Entidades PE
        On PC.Id_Entidad = PE.Id
    Inner Join Prestamos_Comercializadores PCO
        On PC.Id_Comercializador = PCO.Id
    Inner Join Prestamos_Lineas PL
        On PL.Id = PC.Id_Linea
    Left Join Prestamos_Creditos_Ventas PCV
        On PCV.id = PCD.Id_Venta 

    Left Join Prestamos_Prestadores PP On PCD.Id_Prestador_Cobranza = PP.id
    Left Join Inversores I On PP.Id_Inversor = I.id

Where
    PC.Fecha_Cancelacion Is Not Null

    And PC.Fecha_Otorgado Between @Fecha_Credito_Desde And @Fecha_Credito_Hasta
    And PC.Fecha_Cancelacion Between @Fecha_Cancelacion_Desde And @Fecha_Cancelacion_Hasta
    And (@Id_ProvFinan_Desde=-1 or I.id Between @Id_ProvFinan_Desde And @Id_ProvFinan_Hasta)
    And PC.Id_Comercializador Between @Id_Comercializador_Desde And @Id_Comercializador_Hasta
    And (@IntId_Venta_Desde = -1 or PCD.Id_Venta between @IntId_Venta_Desde And @IntId_Venta_Hasta) 
    And (@IntId_Inversor_Desde = -1 or PCV.Id_Inversor between @IntId_inversor_Desde And @IntId_inversor_Hasta)
    And PC.Id_Sucursal Between @IntId_Filial_Desde And @IntId_Filial_Hasta

group by PC.Id
    , PC.Fecha_Otorgado
    , PC.Id_Cliente
    , C.Nombre 
    , C.NroDoc 
    , C.NroBeneficiario
    , C.NroLegajo
    , PC.Capital
    , PC.ValorCuota
    , PC.Plazo
    , PC.ValorCuota * PC.Plazo 
    , PC.Fecha_Cancelacion
    , PC.Id_Entidad
    , PE.Nombre 
    , PC.Id_Linea
    , PL.Descripcion 
    , PC.Id_Comercializador
    , PCO.Nombre 

Datos para el Estado de Préstamos (cancelación)

  • SP/archivo: Prestamos_Creditos_Cancelaciones_Reportes_ObtenerDatosParaEstadoDePrestamos.proc.sql
  • Tipo: Helper de proceso
  • Parámetros: @Id_Credito
  • Relación con módulos: Prestamos_Creditos + Prestamos_Creditos_Detalle + Prestamos_Creditos_MediosDeCobro (Préstamos), Clientes (Clientes). Invoca al SP Prestamos_Creditos_Cancelaciones_ObtenerCuotasPresentadasYNoCobradas.

Calcula el estado de un préstamo de cara a su cancelación: capital pendiente (capital total menos cobrado menos presentado-no-cobrado), cuota desde (primera cuota presentada o última cuota paga), cuota hasta (última cuota del plan), valor de la primera cuota y última cuota paga. Insumo del formulario de cancelación anticipada.

CREATE PROCEDURE [dbo].[Prestamos_Creditos_Cancelaciones_Reportes_ObtenerDatosParaEstadoDePrestamos]
    @Id_Credito Int
As

Set NoCount On


Declare @Suma_Capital_Presentado Decimal(19, 2)
Declare @Suma_Importe_Presentado Decimal(19, 2)
Exec Prestamos_Creditos_Cancelaciones_ObtenerCuotasPresentadasYNoCobradas @Id_Credito, 0, @Suma_Capital_Presentado Output, @Suma_Importe_Presentado Output
Set @Suma_Capital_Presentado = IsNull(@Suma_Capital_Presentado, 0)
Set @Suma_Importe_Presentado = IsNull(@Suma_Importe_Presentado, 0)



-- 17/01/2011
--Declare @CuotaDesde Decimal(19, 2)
--Select
--  @CuotaDesde = Min(PCD.Nro_Cuota)
--From
--  Prestamos_Creditos_MediosDeCobro PCM Inner Join [dbo].[Prestamos_Creditos_Detalle] PCD
--      On PCM.Id_Credito = PCD.Id_Credito
--      And PCM.NroCuota = PCD.Nro_Cuota
--Where
--  PCD.Id_Credito = @Id_Credito
--  And PCM.Importe_Presentado < PCD.Capital + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Administrativos + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Gastos_Primera_Cuota + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Interes + PCD.IvaCuotaSocial + PCD.IvaGastos + PCD.IvaInteres - .01 --+ PCD.IvaPunitorios
--  And PCD.Fecha_Cobro Is Null


-- 17/01/2011
-- Obtener última cuota presentada
Declare @CuotaDesde Decimal(19, 2)
Select
    @CuotaDesde = Min(PCD.Nro_Cuota)
From
    Prestamos_Creditos_MediosDeCobro PCM Inner Join [dbo].[Prestamos_Creditos_Detalle] PCD
        On PCM.Id_Credito = PCD.Id_Credito
        And PCM.NroCuota = PCD.Nro_Cuota
Where
    PCD.Id_Credito = @Id_Credito
    --And PCM.Importe_Presentado < PCD.Capital + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Administrativos + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Gastos_Primera_Cuota + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Interes + PCD.IvaCuotaSocial + PCD.IvaGastos + PCD.IvaInteres - .01 --+ PCD.IvaPunitorios
    And PCD.Fecha_Cobro Is Null
    And PCM.Importe_Presentado > 0
    And PCM.Fecha_Presentado Is Not Null



If @CuotaDesde Is Null
Begin
    Select
        @CuotaDesde = IsNull(Max(PCD.Nro_Cuota), 1)
    From
        Prestamos_Creditos_Detalle PCD
    Where
        PCD.Id_Credito = @Id_Credito
        And PCD.Fecha_Cobro Is Not Null
End


Select
    PC.Capital - (Select Sum(PCD2.Cob_Capital) From [dbo].[Prestamos_Creditos_Detalle] PCD2 Where PCD2.Id_Credito = @Id_Credito) - @Suma_Capital_Presentado Capital

    , @CuotaDesde CuotaDesde

    , (Select Max(Nro_Cuota) From [dbo].[Prestamos_Creditos_Detalle] PCD Where PCD.Id_Credito = @Id_Credito) CuotaHasta

    , C.Nombre
    , C.NroDoc

    , (
        Select 
            PCD.Capital + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Administrativos + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Gastos_Primera_Cuota + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Interes + PCD.IvaCuotaSocial + PCD.IvaGastos + PCD.IvaInteres + PCD.IvaPunitorios ValorCuota
        From
            Prestamos_Creditos_Detalle PCD
        Where
            PCD.Id_Credito = PC.Id
            And PCD.Nro_Cuota = 1
    ) ValorCuota

    , (
        Select
            Max(Nro_Cuota)
        From
            Prestamos_Creditos_Detalle PCD
        Where
            PCD.Fecha_Cobro Is Not Null
            And PCD.Id_Credito = @Id_Credito
    ) UltimaCuotaPaga

From
    Prestamos_Creditos PC Inner Join Clientes C
        On PC.Id_Cliente = C.Id
Where
    PC.Id = @Id_Credito


Saldo de Cancelación

  • SP/archivo: Prestamos_Creditos_Cancelaciones_Reportes_ObtenerSaldoDeCancelacion.proc.sql
  • Tipo: Helper de proceso
  • Parámetros: @Id_Credito, @RecargoPorCancelacionAnticipada, @CuotaDesde, @CuotaHasta
  • Relación con módulos: Prestamos_Creditos_Detalle (Préstamos). Devuelve un único escalar SaldoDeCancelacion.

Calcula el saldo de cancelación de un crédito sumando el capital de las cuotas impagas en el rango indicado: las vencidas (sin recargo) más las no vencidas (con el recargo por cancelación anticipada). Insumo del proceso de cancelación anticipada.

CREATE PROCEDURE [dbo].[Prestamos_Creditos_Cancelaciones_Reportes_ObtenerSaldoDeCancelacion]
    @Id_Credito Int
    , @RecargoPorCancelacionAnticipada Decimal(19,2)
    , @CuotaDesde Int
    , @CuotaHasta Int
As

Set NoCount On



Declare @v1 Decimal(19,2)
Declare @v2 Decimal(19,2)

Select
/*
    @v1 = IsNull(Sum((PCD.Capital + PCD.Interes + PCD.IvaInteres + PCD.IvaGastos + PCD.IvaCuotaSocial + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Punitorios + PCD.Compensatorios + PCD.Gastos_Administrativos + PCD.Gastos_Primera_Cuota + PCD.IvaPunitorios)
        - (PCD.Cob_Capital + PCD.Cob_Interes + PCD.Cob_IvaInteres + PCD.Cob_IvaGastos + PCD.Cob_IvaCuotaSocial + PCD.Cob_CapitalCooperativo + PCD.Cob_CuotaSocial + PCD.Cob_Gastos + PCD.Cob_Gastos_Seguro + PCD.Cob_Gastos_Servicio + PCD.Cob_Gastos_Otros + PCD.Cob_Gastos_Otros2 + PCD.Cob_Gastos_Otros3 + PCD.Cob_Punitorios + PCD.Cob_Gastos_Primera_Cuota + PCD.Cob_IvaPunitorios)), 0)
*/
    @v1 = IsNull(Sum(PCD.Capital), 0)
From
    Prestamos_Creditos_Detalle PCD
Where
    PCD.Id_Credito = @Id_Credito
    And PCD.Nro_Cuota Between @CuotaDesde And @CuotaHasta
    And PCD.Fecha_Cobro Is Null --Si se cobró de manera parcial, la fecha de cobro es nulo.
    And PCD.Fecha_Vencimiento < GETDATE()


Select
/*
    @v2 = IsNull(Sum((PCD.Capital + PCD.Interes + PCD.IvaInteres + PCD.IvaGastos + PCD.IvaCuotaSocial + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Punitorios + PCD.Compensatorios + PCD.Gastos_Administrativos + PCD.Gastos_Primera_Cuota + PCD.IvaPunitorios)), 0)
        + @RecargoPorCancelacionAnticipada
*/
    @v2 = IsNull(Sum(PCD.Capital), 0) + @RecargoPorCancelacionAnticipada
From
    Prestamos_Creditos_Detalle PCD
Where
    PCD.Id_Credito = @Id_Credito
    And PCD.Nro_Cuota Between @CuotaDesde And @CuotaHasta
    And PCD.Fecha_Cobro Is Null --Si se cobró de manera parcial, la fecha de cobro es nulo.
    And PCD.Fecha_Vencimiento >= GETDATE()


Select @v1 + @v2 SaldoDeCancelacion


/*
Select
    T1.Id_Credito

    -- Saldo de cancelación = ImporteVencido - ImporteCobrado + ImporteNoVencido + RecargoPorCancelacionAnticipada
    , Sum(T1.Val + T2.Val) SaldoDeCancelacion
From
(
Select
    PCD.Id_Credito
    , PCD.Nro_Cuota
    , (PCD.Capital + PCD.Interes + PCD.IvaInteres + PCD.IvaGastos + PCD.IvaCuotaSocial + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Punitorios + PCD.Compensatorios + PCD.Gastos_Administrativos + PCD.Gastos_Primera_Cuota + PCD.IvaPunitorios)
        - (PCD.Cob_Capital + PCD.Cob_Interes + PCD.Cob_IvaInteres + PCD.Cob_IvaGastos + PCD.Cob_IvaCuotaSocial + PCD.Cob_CapitalCooperativo + PCD.Cob_CuotaSocial + PCD.Cob_Gastos + PCD.Cob_Gastos_Seguro + PCD.Cob_Gastos_Servicio + PCD.Cob_Gastos_Otros + PCD.Cob_Gastos_Otros2 + PCD.Cob_Gastos_Otros3 + PCD.Cob_Punitorios + PCD.Cob_Gastos_Primera_Cuota + PCD.Cob_IvaPunitorios) Val

From
    Prestamos_Creditos_Detalle PCD
Where
    PCD.Fecha_Vencimiento < GETDATE()
    And PCD.Fecha_Cobro Is Null --Si se cobró de manera parcial, la fecha de cobro es nulo.
) T1

, (
Select
    PCD.Id_Credito
    , PCD.Nro_Cuota
    , (PCD.Capital + PCD.Interes + PCD.IvaInteres + PCD.IvaGastos + PCD.IvaCuotaSocial + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Punitorios + PCD.Compensatorios + PCD.Gastos_Administrativos + PCD.Gastos_Primera_Cuota + PCD.IvaPunitorios)
        + @RecargoPorCancelacionAnticipada Val

From
    Prestamos_Creditos_Detalle PCD
Where
    PCD.Fecha_Vencimiento >= GETDATE()
    And PCD.Fecha_Cobro Is Null --Si se cobró de manera parcial, la fecha de cobro es nulo.
) T2

Where
    T1.Id_Credito = T2.Id_Credito
    And T1.Id_Credito = @Id_Credito
    And T1.Nro_Cuota Between @CuotaDesde And @CuotaHasta
    And T2.Nro_Cuota Between @CuotaDesde And @CuotaHasta
Group By
    T1.Id_Credito

*/

Listado para Aseguradora

  • SP/archivo: Prestamos_Creditos_ListadoParaAseguradora.proc.sql
  • Tipo: Reporte
  • Parámetros: @Anio, @Mes, @Id_Entidad_Desde, @Id_Entidad_Hasta, @Id_Comercializador_Desde, @Id_Comercializador_Hasta
  • Relación con módulos: Prestamos_Creditos + Prestamos_Creditos_Detalle (Préstamos), Prestamos_Solicitudes (Solicitudes), Prestamos_Entidades (Entidades). Usa funciones dbo.DiasEnMes y dbo.CreditoIsEnMora.

Genera el archivo de novedades de seguros para la compañía aseguradora: arma un registro de longitud fija (RegistroSeguro) con datos del crédito y del titular (documento, nombre, sexo, domicilio, provincia codificada, teléfono, CP) para el mes/año indicado, incluyendo créditos otorgados en el período o que no estén en mora. SQL dinámico vía Exec(@SQLString).


CREATE PROCEDURE  [dbo].[Prestamos_Creditos_ListadoParaAseguradora]                                               
                                        @Anio int = 2008,
                                        @Mes int = 12,
                                        @Id_Entidad_Desde Int = 0,
                                        @Id_Entidad_Hasta Int = 0,
                                        @Id_Comercializador_Desde Int = 0,
                                        @Id_Comercializador_Hasta Int = 0




AS
Declare @SQLString VarChar(8000) 
Declare @Filtros Varchar(8000)
Declare @FechaDesde Datetime
Declare @FechaHasta Datetime

Set @FechaDesde = '01' + '/' + Convert(Char,@Mes) + '/' + Convert(Char,@Anio)
Set @FechaHasta =  Convert(Char,dbo.DiasEnMes(@FechaDesde)) + '/' + Convert(Char,@Mes) + '/' + Convert(Char,@Anio)
print @FechaDesde
print @FechaHasta 



--Set @FechaHasta = 

Set @Filtros = ''
Set @SQLString = 'Select 
        RegistroSeguro = ''    '' + 
                        Right(''000000000000000'' + rtrim(convert(char, Prestamos_Creditos.Id)), 15 )  + 
                        Right(''00'' + rtrim(convert(char,day(Prestamos_Creditos.fecha_otorgado))),2) + Right(''00'' + rtrim(convert(char,month(Prestamos_Creditos.fecha_otorgado))),2) +  Right(''0000'' + rtrim(convert(char,year(fecha_otorgado))),4) +
                        Right(''000'' + rtrim(convert(char,Prestamos_Creditos.Plazo)),3) +
                        Right(''00000000000'' + rtrim(convert(char, replace(Prestamos_Creditos.Capital,''.'',''''))),11) +
                        Right(''00000000000'' + rtrim(convert(char,replace(Prestamos_Solicitudes.ValorCuota_Final,''.'',''''))),11) +
                        Right(''0000000000000000'' + Rtrim(convert(char,replace((Prestamos_Creditos.Capital - (Select Count(*) from [dbo].[Prestamos_Creditos_Detalle] where Prestamos_Creditos_Detalle.Id_Credito = Id And Fecha_Cobro Is Not Null) * Prestamos_Solicitudes.ValorCuota_Final),''.'',''''))),16) +
                        Right(''0000'' + rtrim(convert(char,' + Rtrim(convert(char,@Anio)) + ')),4) + Right(''00'' + rtrim(convert(char,'+ Rtrim(convert(char,@Mes)) +')),2)   + 
                        ''PES''  +
                        (case when Prestamos_Solicitudes.TipoDoc = ''DNI'' then 
                             ''05''
                        when Prestamos_Solicitudes.TipoDoc = ''CI'' then 
                             ''04''
                        when Prestamos_Solicitudes.TipoDoc = ''LE'' then 
                             ''03''
                        when Prestamos_Solicitudes.TipoDoc = ''LC'' then 
                             ''02''
                        when Prestamos_Solicitudes.TipoDoc = ''PA'' then 
                             ''01''
                        end) +
                        Left(Rtrim(convert(char,Prestamos_Solicitudes.NroDoc))+ ''           '',11)  +
                        Left((Rtrim(convert(char,Prestamos_Solicitudes.Apellido)) + '' '' + Rtrim(convert(char,Prestamos_Solicitudes.Nombre))) + ''                                             '',45) +                                          
                        Rtrim(Convert(char,Prestamos_Solicitudes.Sexo)) +
                        Right(''00'' + rtrim(convert(char,day(FechaNacimiento))),2) + Right(''00'' + rtrim(convert(char,month(FechaNacimiento))),2) +  Right(''0000'' + rtrim(convert(char,year(FechaNacimiento))),4) +
                        Left(Convert(char,(Prestamos_Solicitudes.Domicilio + '' '' +  Prestamos_Solicitudes.Domicilio_Nro + '' '' +  Prestamos_Solicitudes.Domicilio_Piso + '' '' +  Prestamos_Solicitudes.Domicilio_Dpto) + ''                                             ''),45) +
                        Left(Convert(char,Prestamos_solicitudes.Localidad) + ''                         '',25) +
                        (case when Prestamos_Solicitudes.Id_Provincia = 0 then 
                             ''C ''
            when Prestamos_Solicitudes.Id_Provincia = 1 then 
                             ''B ''
            when Prestamos_Solicitudes.Id_Provincia = 2 then 
                             ''A ''
            when Prestamos_Solicitudes.Id_Provincia = 3 then 
                             ''X ''
            when Prestamos_Solicitudes.Id_Provincia = 4 then 
                             ''F ''
            when Prestamos_Solicitudes.Id_Provincia = 5 then 
                             ''G ''
            when Prestamos_Solicitudes.Id_Provincia = 6 then 
                             ''I ''
            when Prestamos_Solicitudes.Id_Provincia = 7 then 
                             ''L ''
            when Prestamos_Solicitudes.Id_Provincia = 8 then 
                             ''K ''
            when Prestamos_Solicitudes.Id_Provincia = 9 then 
                             ''O ''
            when Prestamos_Solicitudes.Id_Provincia = 10 then 
                             ''P ''
            when Prestamos_Solicitudes.Id_Provincia = 11 then 
                            ''Q ''
            when Prestamos_Solicitudes.Id_Provincia = 12 then 
                            ''S '' 
            when Prestamos_Solicitudes.Id_Provincia = 13 then 
                             ''U ''
            when Prestamos_Solicitudes.Id_Provincia = 14 then 
                             ''T ''
            when Prestamos_Solicitudes.Id_Provincia = 15 then 
                             ''D ''
            when Prestamos_Solicitudes.Id_Provincia = 16 then 
                             ''E ''
            when Prestamos_Solicitudes.Id_Provincia = 17 then 
                             ''H ''
            when Prestamos_Solicitudes.Id_Provincia = 18 then 
                             ''M ''
            when Prestamos_Solicitudes.Id_Provincia = 19 then 
                            ''W ''
            when Prestamos_Solicitudes.Id_Provincia = 20 then 
                             ''J ''
            when Prestamos_Solicitudes.Id_Provincia = 21 then 
                             ''N ''
            when Prestamos_Solicitudes.Id_Provincia = 22 then 
                             ''R ''
            when Prestamos_Solicitudes.Id_Provincia = 23 then 
                             ''V ''
            end) +
            Left(Rtrim(convert(char,Prestamos_Solicitudes.Telefono)) + ''                    '',20) +
            Left(Rtrim(convert(char,Prestamos_Solicitudes.CodigoPostal)) + ''        '',08),
       NroPrestamo = Prestamos_Creditos.Id,
       Prestamos_Creditos.Id_Solicitud, 
       Prestamos_Creditos.Id_Cliente, 
       Nombre  = Prestamos_Solicitudes.Apellido + '' '' + Prestamos_Solicitudes.Nombre,
       Prestamos_Creditos.Capital,
       Prestamos_Creditos.Plazo, 
       Entidad = Prestamos_Entidades.Nombre
From Prestamos_Creditos
Inner Join Prestamos_Solicitudes On Prestamos_solicitudes.Id = Prestamos_Creditos.Id_Solicitud
Inner Join Prestamos_Entidades On Prestamos_Entidades.Id = Prestamos_Creditos.Id_Entidad
Where 
    Fecha_Otorgado Is Not Null And
    ((year(Prestamos_creditos.Fecha_Otorgado) = ''' + Rtrim(convert(char,@Anio)) + ''' and month(Prestamos_creditos.Fecha_Otorgado) = ''' + Rtrim(convert(char,@Mes)) + ''' )
    or 
    (dbo.CreditoIsEnMora(Prestamos_Creditos.Id, ''' + Rtrim(convert(datetime,@FechaDesde)) + ''', ''' + Rtrim(convert(datetime,@FechaHasta)) + ''')) = 0
    ) and Fecha_anulacion is null and fecha_cancelacion is null'


If @Id_Comercializador_Desde <> 0 And @Id_Comercializador_Hasta <> 0
    Set @Filtros = @Filtros + ' And Prestamos_Creditos.Id_Comercializador Between ' + Rtrim(convert(char,@Id_Comercializador_Desde)) + ' And ' + Rtrim(convert(char,@Id_Comercializador_Hasta))

If @Id_Entidad_Desde <> 0 And @Id_Entidad_Hasta <> 0
    Set @Filtros = @Filtros + ' And Prestamos_Creditos.Id_Entidad Between ' + Rtrim(convert(char,@Id_Entidad_Desde)) + ' And ' + Rtrim(convert(char,@Id_Entidad_Hasta))

--Set @Filtros = @Filtros + ' And (dbo.CreditoIsEnMora(Prestamos_Creditos.Id, ''' + Rtrim(convert(datetime,@FechaDesde)) + ''', ''' + Rtrim(convert(datetime,@FechaHasta)) + ''')) = 0'

Set @SQLString = @SQLString + @Filtros


Exec(@SQLString) 
Print @SQLString

Listado de Novedades (créditos otorgados)

  • SP/archivo: Prestamos_Creditos_Listado_Novedades.proc.sql
  • Tipo: Reporte
  • Parámetros: @Fecha_Desde, @Fecha_Hasta, @Id_Entidad_Desde, @Id_Entidad_Hasta, @Orden
  • Relación con módulos: Prestamos_Creditos (Préstamos), Clientes + Prestamos_Solicitudes_MediosCobro / _DatosAdicionales (Clientes/Medios de cobro/CBU), Prestamos_Comercializadores, Prestamos_Solicitudes, Sucursales, Prestamos_Entidades, Prestamos_Prestadores.

Lista las novedades de créditos otorgados en un rango de fechas y entidades: documento, nombre, asociado, solicitud, número de crédito, capital, neto, fecha de otorgamiento, prestador, sucursal, comercializador, CBU y observaciones. Permite ordenar por seis criterios (@Orden). SQL dinámico vía Exec(@Str).


CREATE Procedure [dbo].[Prestamos_Creditos_Listado_Novedades]
    @Fecha_Desde Datetime = '01/01/1900',
    @Fecha_Hasta Datetime = '01/01/3000',
    @Id_Entidad_Desde Int = 0,
    @Id_Entidad_Hasta Int = 99999999,
    @Orden Int = 0
As
Declare @str varchar(2000)
Set @str='Select distinct
    TipoDoc = Case When Clientes.TipoDoc='''' Then ''DNI'' Else Clientes.TipoDoc End,
    Clientes.DNI1,
    Clientes.Nombre,
    Clientes.Id_asociado,
    Creditos.Id_solicitud,
    Comprobante = ''Prestamo'',
    Nro_credito = Creditos.id,
    Creditos.Capital,
    Creditos.Neto,
    Creditos.Fecha_Otorgado,
    Prestador = Case When creditos.Id_Prestador = 0 Then ''MUPEDUC'' Else (Select Nombre from Prestamos_Prestadores where id= creditos.id_Prestador) End,
    Id_sucursal = isnull((Select sucursales.Descripcion from sucursales where id=Creditos.Id_Sucursal),''N/D''),
    Comercializador = IsNull(Comercializadores.Nombre,''-''),
    CBU = IsNull(Clientes_CBU.campo1 + '' - Suc: '' + substring(Clientes_CBU.campo1,11,4) + '' N Cta: '' + substring(Clientes_CBU.campo1,15,7),''-'') ,
    Observ = Case When Prestamos_solicitudes.Observaciones = '''' Then '''' Else ''Observaciones: '' + Prestamos_solicitudes.Observaciones End,
    Creditos.Id_Entidad,
    Nombre_Entidad = Entidades.Nombre
From Prestamos_Creditos
    As Creditos
Inner Join Clientes On Creditos.Id_Cliente = Clientes.Id
Left Outer Join Prestamos_Comercializadores
        As Comercializadores
    On Comercializadores.Id = creditos.Id_Comercializador
Left Outer Join Prestamos_solicitudes on Prestamos_solicitudes.id=creditos.id_solicitud
Left Outer Join Prestamos_Solicitudes_MediosCobro On Prestamos_Solicitudes_MediosCobro.Id_Solicitud = Prestamos_Solicitudes.Id
Left Outer Join Prestamos_Solicitudes_MediosCobro_DatosAdicionales as Clientes_CBU On Clientes_CBU.Id_Prestamos_Solicitudes_MediosCobro = Prestamos_Solicitudes_MediosCobro.Id
Inner Join Prestamos_Entidades
        As Entidades
    On Creditos.Id_Entidad = Entidades.Id
Where Creditos.Fecha_Otorgado Between ''' + convert(char,@Fecha_Desde,103) + ''' And ''' + convert(char,@Fecha_Hasta,103) + '''
And Entidades.Id Between ' + convert(char,@Id_Entidad_Desde) + ' And ' + convert(char,@Id_Entidad_Hasta)
If @Orden = 1
    Set @Str = @Str + ' Order By Clientes.DNI1'
If @Orden = 2
    Set @Str = @Str + ' Order By Clientes.Nombre'
If @Orden = 3
    Set @Str = @Str + ' Order By Clientes.Id_asociado'
If @Orden = 4
    Set @Str = @Str + ' Order By Clientes.Id_solicitud'
If @Orden = 5
    Set @Str = @Str + ' Order By Creditos.id'
If @Orden = 6
    Set @Str = @Str + ' Order By Creditos.Fecha_Otorgado'
Exec(@Str) 
Print @Str

Listado de Novedades — Cálculo

  • SP/archivo: Prestamos_Creditos_Listado_Novedades_Calculo.proc.sql
  • Tipo: Reporte
  • Parámetros: @Fecha_Desde, @Fecha_Hasta, @PrestadorDesde, @PrestadorHasta, @Orden
  • Relación con módulos: Prestamos_Creditos (Préstamos), Clientes (Clientes), Prestamos_Tipo_Calculo (Tipos de cálculo), Prestamos_Solicitudes (Solicitudes), Prestamos_Prestadores.

Variante del listado de novedades orientada al cálculo: por cada crédito otorgado en el rango de fechas y prestadores devuelve documento, cliente, capital, cantidad de cuotas, valor de cuota de costo, prestador, tipo de cálculo y monto total (cuota de costo × plazo). Permite ordenar por cuatro criterios. SQL dinámico vía Exec(@Str).


CREATE Procedure [dbo].[Prestamos_Creditos_Listado_Novedades_Calculo]
    @Fecha_Desde Datetime = '01/01/1900',
    @Fecha_Hasta Datetime = '01/01/3000',
                @PrestadorDesde int =0,
                @PrestadorHasta int =0,
    @Orden Int = 0
As
Declare @str varchar(2000)
Set @str='Select
    TipoDoc = Case When Clientes.TipoDoc='''' Then ''DNI'' Else Clientes.TipoDoc End,
    Clientes.DNI1,
    Clientes.Nombre,
    Clientes.Id_asociado,
    Prestamos_Creditos.Id,
    Prestamos_Creditos.Capital,
    Cuotas = Prestamos_Creditos.Plazo,
    Cta_Prestamo = (Select Valor_Cuota_Costo from Prestamos_solicitudes where id= Prestamos_Creditos.id_Solicitud) ,
    Prestador = Case When Prestamos_Creditos.Id_Prestador = 0 Then ''Propio'' Else (Select Nombre from Prestamos_Prestadores where id= Prestamos_Creditos.id_Prestador) End,
    Prestamos_Creditos.Id_Tipo_Calculo,
    TipCal.Descripcion,
    monto_total = (Select Valor_Cuota_Costo from Prestamos_solicitudes where id= Prestamos_Creditos.id_Solicitud) * Prestamos_Creditos.plazo
From Prestamos_Creditos
Inner Join Clientes On Prestamos_Creditos.Id_Cliente = Clientes.Id
Inner Join Prestamos_Tipo_Calculo
        As TipCal
    On Prestamos_Creditos.Id_Tipo_Calculo = TipCal.Id
Where Prestamos_Creditos.Fecha_Otorgado Between ''' + convert(char,@Fecha_Desde,103) + ''' And ''' + convert(char,@Fecha_Hasta,103) + '''
And Prestamos_Creditos.Id_Prestador Between ' + convert(char,@PrestadorDesde) + ' And ' + convert(char,@PrestadorHasta) 
If @Orden = 1
    Set @Str = @Str + ' Order By Clientes.DNI1'
If @Orden = 2
    Set @Str = @Str + ' Order By Clientes.Nombre'
If @Orden = 3
    Set @Str = @Str + ' Order By Clientes.Id_asociado'
If @Orden = 4
    Set @Str = @Str + ' Order By Creditos.Id'
Exec(@Str) 
Print @Str

Créditos Cedidos en una Venta — para Informe

  • SP/archivo: Prestamos_Creditos_Ventas_ObtenerCreditosCedidosEnUnaVentaParaInforme.proc.sql
  • Tipo: Reporte
  • Parámetros: @Id_Venta
  • Relación con módulos: Prestamos_Creditos_Ventas_Detalle + Prestamos_Creditos_Detalle + Prestamos_Creditos (Préstamos/Ventas de cartera), Clientes (Clientes).

Detalla, para una venta/cesión de cartera, las cuotas cedidas con sus componentes: cliente, fecha de operación, capital del crédito y de la cuota, vencimiento, fecha de cobro/pago a banco, desglose de intereses y gastos (devengados y cobrados) y el valor actual cedido. Insumo del informe de cesión por venta.

CREATE PROCEDURE [dbo].[Prestamos_Creditos_Ventas_ObtenerCreditosCedidosEnUnaVentaParaInforme]
    @Id_Venta Int
AS

Set NoCount On

Select
    @Id_Venta Id_Venta
    , PC.Id_Solicitud
    , C.Id Id_Cliente
    , C.Nombre Nombre_Cliente
    , PC.Fecha_Operacion
    , PC.Capital Capital_Credito
    , PCD.Capital Capital_Cuota
    , PCD.Nro_Cuota
    , PCD.Fecha_Vencimiento
    , PCD.Fecha_Cobro
    , PCD.Fecha_PagoBanco


    , PCD.Interes
    , PCD.CapitalCooperativo
    , PCD.CuotaSocial
    , PCD.Gastos
    , PCD.Gastos_Seguro
    , PCD.Gastos_Servicio
    , PCD.Gastos_Otros
    , PCD.Gastos_Otros2
    , PCD.Gastos_Otros3
    , PCD.Gastos_Primera_Cuota

    , PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Gastos_Primera_Cuota Suma_Gastos

    , PCD.Cob_Capital
    , PCD.Cob_Interes
    , PCD.Cob_CapitalCooperativo
    , PCD.Cob_CuotaSocial
    , PCD.Cob_Gastos
    , PCD.Cob_Gastos_Seguro
    , PCD.Cob_Gastos_Servicio
    , PCD.Cob_Gastos_Otros
    , PCD.Cob_Gastos_Otros2
    , PCD.Cob_Gastos_Otros3
    , PCD.Cob_Gastos_Primera_Cuota

    , PCD.Cob_Gastos + PCD.Cob_Gastos_Seguro + PCD.Cob_Gastos_Servicio + PCD.Cob_Gastos_Otros + PCD.Cob_Gastos_Otros2 + PCD.Cob_Gastos_Otros3 + PCD.Cob_Gastos_Primera_Cuota Suma_Cob_Gastos

    , PCVD.ValorActual

    , PC.Id Id_Prestamos_Credito

From
    Prestamos_creditos_ventas_detalle PCVD Inner Join [dbo].[Prestamos_Creditos_Detalle] PCD
        On PCVD.Id_Prestamos_Creditos_Detalle = PCD.Id
    Inner Join Prestamos_Creditos PC
        On PC.Id = PCD.Id_Credito
    Inner Join Clientes C
        On PC.Id_Cliente = C.Id

Where
    PCVD.Id_Prestamos_Creditos_Ventas = @Id_Venta

Créditos Cedidos en una Venta — Informe Resumen Mensual

  • SP/archivo: Prestamos_Creditos_Ventas_ObtenerCreditosCedidosEnUnaVentaParaInformeResumenMensual.proc.sql
  • Tipo: Reporte
  • Parámetros: @Id_Venta
  • Relación con módulos: Prestamos_Creditos_Ventas_Detalle + Prestamos_Creditos_Detalle + Prestamos_Creditos (Préstamos/Ventas de cartera), Clientes (Clientes).

Versión resumida mensual del informe de cesión: por cada cuota cedida en una venta devuelve número de cuota, fechas (vencimiento, cobro, pago a banco), suma de gastos, total cobrado (todos los componentes Cob_), suma de gastos cobrados y valor actual cedido. Insumo del resumen mensual de la cesión.

--================================================================================================================================================================
--================================================================================================================================================================
--================================================================================================================================================================
/*
IMPORTANTE: NO MODIFICAR ESTE C?DIGO YA QUE FUE GENERADO AUTOM?TICAMENTE.


<CompoundXmlDocument>
  <User Name="PLENARIO\frocha" />
</CompoundXmlDocument>
*/



CREATE PROCEDURE [dbo].[Prestamos_Creditos_Ventas_ObtenerCreditosCedidosEnUnaVentaParaInformeResumenMensual]
    @Id_Venta Int
AS

Set NoCount On

Select
    @Id_Venta Id_Venta
    , PCD.Nro_Cuota
    , PCD.Fecha_Vencimiento
    , PCD.Fecha_Cobro
    , PCD.Fecha_PagoBanco
    ,PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Gastos_Primera_Cuota Suma_Gastos
    , [Total Cobrado] = (PCD.Cob_Capital +PCD.Cob_Interes + PCD.Cob_CapitalCooperativo
                             + PCD.Cob_CuotaSocial
                             + PCD.Cob_Gastos
                             + PCD.Cob_Gastos_Seguro
                             + PCD.Cob_Gastos_Servicio
                             + PCD.Cob_Gastos_Otros
                             + PCD.Cob_Gastos_Otros2
                             + PCD.Cob_Gastos_Otros3
                             + PCD.Cob_Gastos_Primera_Cuota)

    , PCD.Cob_Gastos + PCD.Cob_Gastos_Seguro + PCD.Cob_Gastos_Servicio + PCD.Cob_Gastos_Otros + PCD.Cob_Gastos_Otros2 + PCD.Cob_Gastos_Otros3 + PCD.Cob_Gastos_Primera_Cuota Suma_Cob_Gastos
    , PCVD.ValorActual
    , PC.Id Id_Prestamos_Credito

From
    Prestamos_creditos_ventas_detalle PCVD Inner Join [dbo].[Prestamos_Creditos_Detalle] PCD
        On PCVD.Id_Prestamos_Creditos_Detalle = PCD.Id
    Inner Join Prestamos_Creditos PC
        On PC.Id = PCD.Id_Credito
    Inner Join Clientes C
        On PC.Id_Cliente = C.Id

Where
    PCVD.Id_Prestamos_Creditos_Ventas = @Id_Venta

Datos para filtros del Informe de Pagos (Ventas)

  • SP/archivo: Prestamos_Creditos_Ventas_ObtenerDatosParaFiltrosDeInformeDePagos.proc.sql
  • Tipo: Helper de proceso
  • Parámetros: ninguno
  • Relación con módulos: Inversores (Inversores), Prestamos_Creditos_Ventas (Ventas de cartera). Devuelve solo rangos min/máx.

Helper que alimenta los filtros del informe de pagos a inversores: devuelve valores mínimo y máximo de Id de inversores, Id de ventas y número de comprobante, para inicializar los rangos "desde/hasta" del informe. No es un reporte de usuario final.

CREATE PROCEDURE [dbo].[Prestamos_Creditos_Ventas_ObtenerDatosParaFiltrosDeInformeDePagos]
As

Set NoCount On

Select
    *
From
    (
    Select
        Min(I.Id) Inversores_Min
        , Max(I.Id) Inversores_Max
    From
        Inversores I
    ) T1

    , (
    Select
        Min(PCV.Id) Ventas_Min
        , Max(PCV.Id) Ventas_Max
    From
        Prestamos_Creditos_Ventas PCV
    ) T2

    , (
    Select
        Min(PCV.Nro_Comprobante) Nro_Comprobante_Min
        , Max(PCV.Nro_Comprobante) Nro_Comprobante_Max
    From
        Prestamos_Creditos_Ventas PCV
    ) T3

Informe de Pagos (Ventas / Inversores)

  • SP/archivo: Prestamos_Creditos_Ventas_ObtenerDatosParaInformeDePagos.proc.sql
  • Tipo: Reporte
  • Parámetros: @Id_Inversor_Desde, @Id_Inversor_Hasta, @Fecha_Pago_Desde, @Fecha_Pago_Hasta, @Id_Venta_Desde, @Id_Venta_Hasta, @Tipo_Responsabilidad, @Nro_Comprobante_Desde, @Nro_Comprobante_Hasta
  • Relación con módulos: Prestamos_Creditos + Prestamos_Creditos_Detalle + Prestamos_Creditos_Ventas / _Detalle (Préstamos/Ventas), Inversores (Inversores), Clientes, Prestamos_Entidades.

Informe de pagos a inversores por cuotas cobradas de cartera cedida: lista inversor, fecha de pago al banco, venta, comprobante, crédito, cliente, entidad, cuota, importe cobrado e importe pagado, filtrando por inversor, fecha de pago, venta, tipo de responsabilidad y comprobante (excluye ventas anuladas). Ordenado por inversor/venta/cuota.

--================================================================================================================================================================
--================================================================================================================================================================
--================================================================================================================================================================
/*



<CompoundXmlDocument />
*/

CREATE PROCEDURE [dbo].[Prestamos_Creditos_Ventas_ObtenerDatosParaInformeDePagos]
    @Id_Inversor_Desde Int
    , @Id_Inversor_Hasta Int
    , @Fecha_Pago_Desde DateTime
    , @Fecha_Pago_Hasta DateTime
    , @Id_Venta_Desde Int
    , @Id_Venta_Hasta Int
    , @Tipo_Responsabilidad Int
    , @Nro_Comprobante_Desde Int
    , @Nro_Comprobante_Hasta Int
As

Set NoCount On

Select
    I.Id Id_Inversor
    , I.Nombre Nombre_Inversor
    , PCD.Fecha_PagoBanco
    , PCV.Id Id_Venta
    , PCV.Nro_Comprobante
    , PC.Id Id_Credito
    , C.Id Id_Cliente
    , C.Nombre Nombre_Cliente
    , PE.Id Id_Entidad
    , PE.Nombre Nombre_Entidad
    , PCD.Fecha_Vencimiento
    , PCD.Nro_Cuota
    , PCD.Fecha_Cobro
    , PCD.Cob_Capital + PCD.Cob_Interes + PCD.Cob_IvaInteres + PCD.Cob_IvaGastos + PCD.Cob_IvaCuotaSocial + PCD.Cob_CapitalCooperativo + PCD.Cob_CuotaSocial + PCD.Cob_Gastos + PCD.Cob_Gastos_Seguro + PCD.Cob_Gastos_Servicio + PCD.Cob_Gastos_Otros + PCD.Cob_Gastos_Otros2 + PCD.Cob_Gastos_Otros3 + PCD.Cob_Punitorios + PCD.Cob_Gastos_Primera_Cuota + PCD.Cob_IvaPunitorios ImporteCobrado
    , PCD.Capital + PCD.Interes + PCD.CapitalCooperativo + PCD.CuotaSocial + PCD.Gastos + PCD.Gastos_Seguro + PCD.Gastos_Servicio + PCD.Gastos_Otros + PCD.Gastos_Otros2 + PCD.Gastos_Otros3 + PCD.Gastos_Primera_Cuota ImportePagado
From
    Prestamos_Creditos PC Inner Join [dbo].[Prestamos_Creditos_Detalle] PCD
        On PC.Id = PCD.Id_Credito
    Inner Join Prestamos_Creditos_Ventas_Detalle PCVD
        On PCVD.Id_Prestamos_Creditos = PC.Id
        And PCVD.Id_Prestamos_Creditos_Detalle = PCD.Id
    Inner Join Prestamos_Creditos_Ventas PCV
        On PCV.Id = PCVD.Id_Prestamos_Creditos_Ventas
    Inner Join Inversores I
        On I.Id = PCV.Id_Inversor
    Inner Join Clientes C
        On PC.Id_Cliente = C.Id
    Inner Join Prestamos_Entidades PE
        On PC.Id_Entidad = PE.Id
Where
    PCV.Id_Inversor Between @Id_Inversor_Desde And @Id_Inversor_Hasta
    And PCD.Fecha_PagoBanco Between @Fecha_Pago_Desde And @Fecha_Pago_Hasta
    And PCV.Id Between @Id_Venta_Desde And @Id_Venta_Hasta
    And (@Tipo_Responsabilidad > 0 And (PCV.TipoResponsabilidad = @Tipo_Responsabilidad) Or (@Tipo_Responsabilidad = 0))
    And PCV.Nro_Comprobante Between @Nro_Comprobante_Desde And @Nro_Comprobante_Hasta
    And PCV.Fecha_Anulacion Is Null
Order By
    I.Id
    , PCV.Id
    , PCD.Nro_Cuota

Informe de Cuotas de Créditos Acordados

  • SP/archivo: Prestamos_Informe_CuotasCreditosAcordados.proc.sql
  • Tipo: Reporte
  • Parámetros: @FechaOperacion_Desde, @FechaOperacion_Hasta, @Entidad_Desde, @Entidad_Hasta, @Tasa
  • Relación con módulos: Prestamos_Creditos_Detalle + Prestamos_Creditos (Préstamos), Clientes (Clientes), Parametros (parámetro FechaDeTrabajo).

Lista las cuotas de los créditos acordados (otorgados) por rango de fecha de operación y entidad: cliente, crédito, cuota, vencimiento, valor de cuota desglosado (capital, interés, IVAs, gastos) y el valor actual descontado a la tasa indicada (@Tasa) según el plazo hasta el vencimiento desde la fecha de trabajo. Ordenado por otorgamiento/crédito/cuota.

CREATE PROCEDURE [dbo].[Prestamos_Informe_CuotasCreditosAcordados] 
                              @FechaOperacion_Desde datetime = '01/01/1900',
                              @FechaOperacion_Hasta datetime = '01/01/2900',
                              @Entidad_Desde int = 1,
                              @Entidad_Hasta int = 999999,
                              @Tasa decimal(19,2) = 24.00

AS

Declare @Fecha_Trabajo Datetime
Set @Fecha_Trabajo = (Select Valor From Parametros Where Parametro = 'FechaDeTrabajo')

Select  
    Clientes.Id,
    Clientes.Nombre,
    Id_Credito, 
    Nro_Cuota,
    PRestamos_Creditos.Fecha_Otorgado,
    Fecha_Vencimiento,
    PRestamos_Creditos.Id_Entidad,
    ValorCuota = Prestamos_Creditos_Detalle.Capital+Prestamos_Creditos_Detalle.Interes+Prestamos_Creditos_Detalle.IVAInteres+Prestamos_Creditos_Detalle.IvaGastos+Prestamos_Creditos_Detalle.IvaCuotaSocial+Prestamos_Creditos_Detalle.IvaCuotaSocial+Prestamos_Creditos_Detalle.CapitalCooperativo+Prestamos_Creditos_Detalle.CuotaSocial+Prestamos_Creditos_Detalle.Gastos+Prestamos_Creditos_Detalle.Gastos_Seguro+Prestamos_Creditos_Detalle.Gastos_Servicio+Prestamos_Creditos_Detalle.Gastos_Otros+Prestamos_Creditos_Detalle.Gastos_Otros2+Prestamos_Creditos_Detalle.Gastos_Otros3,
    Prestamos_Creditos_Detalle.Capital,
    Prestamos_Creditos_Detalle.Interes,
    Prestamos_Creditos_Detalle.IVAInteres,
    Prestamos_Creditos_Detalle.IvaGastos,
    Prestamos_Creditos_Detalle.IvaCuotaSocial,
    Prestamos_Creditos_Detalle.IvaCuotaSocial,
    Prestamos_Creditos_Detalle.CapitalCooperativo,
    Prestamos_Creditos_Detalle.CuotaSocial,
    Prestamos_Creditos_Detalle.Gastos,
    Prestamos_Creditos_Detalle.Gastos_Seguro,
    Prestamos_Creditos_Detalle.Gastos_Servicio,
    Prestamos_Creditos_Detalle.Gastos_Otros,
    Prestamos_Creditos_Detalle.Gastos_Otros2,
    Prestamos_Creditos_Detalle.Gastos_Otros3,
    Plazo = datediff(day,  @Fecha_Trabajo, Prestamos_Creditos_Detalle.Fecha_Vencimiento),
    ValorActual = convert(decimal(19,2),(Prestamos_Creditos_Detalle.Capital+Prestamos_Creditos_Detalle.Interes+Prestamos_Creditos_Detalle.IVAInteres)/(1+(Plazo * @Tasa / 36500)))
From Prestamos_Creditos_Detalle
Inner Join PRestamos_Creditos On Prestamos_Creditos.Id = Prestamos_Creditos_Detalle.Id_Credito
Inner Join Clientes On Clientes.Id = Prestamos_Creditos.Id_Cliente
Where   Fecha_Operacion Between @FechaOperacion_Desde And @FechaOperacion_Hasta And
        Id_Entidad between @Entidad_Desde and @Entidad_Hasta And
        Fecha_Otorgado is not null
order by Fecha_Otorgado,Id_Credito, Nro_Cuota

Informe de Cuotas Impagas

  • SP/archivo: Prestamos_Informe_CuotasImpagas.proc.sql
  • Tipo: Reporte
  • Parámetros: @Entidad_Desde, @Entidad_Hasta, @Tasa, @IntId_Venta_Desde, @IntId_Venta_Hasta, @IntId_Inversor_Desde, @IntId_Inversor_Hasta
  • Relación con módulos: Prestamos_Creditos_Detalle + Prestamos_Creditos (Préstamos), Clientes (Clientes), Prestamos_Entidades, Prestamos_Creditos_Ventas (Ventas/Cartera), Parametros (FechaDeTrabajo).

Lista las cuotas impagas (Fecha_Cobro Is Null) de créditos otorgados, no anulados ni cancelados, filtrando por entidad, venta e inversor. Devuelve cliente (con nombre/apellido físico, legajo, CUIT), crédito, cuota, vencimiento, valor de cuota desglosado y valor actual descontado a la tasa (neto de lo ya cobrado de capital/interés/IVA interés). Ordenado por otorgamiento/crédito/cuota.

/*
IMPORTANTE: NO MODIFICAR ESTE C?DIGO YA QUE FUE GENERADO AUTOM?TICAMENTE.


<CompoundXmlDocument>
  <User Name="PLENARIO\svanore" />
</CompoundXmlDocument>
*/

CREATE PROCEDURE [dbo].[Prestamos_Informe_CuotasImpagas] 
                              @Entidad_Desde int = 1,
                              @Entidad_Hasta int = 999999,
                              @Tasa decimal(19,2) = 24.00,
                              @IntId_Venta_Desde int=-1,
                              @IntId_Venta_Hasta int=-1,
                              @IntId_Inversor_Desde int=-1,
                              @IntId_Inversor_Hasta int=-1

AS

Declare @Fecha_Trabajo Datetime
Set @Fecha_Trabajo = (Select Valor From Parametros Where Parametro = 'FechaDeTrabajo')

Select 
    Clientes.Id,
    Clientes.Nombre,
    Id_Credito, 
    Nro_Cuota,
    PRestamos_Creditos.Fecha_Otorgado,
    Fecha_Vencimiento,
    PRestamos_Creditos.Id_Entidad,
    ValorCuota =    Prestamos_Creditos_Detalle.Capital +
                    Prestamos_Creditos_Detalle.Interes +
                    Prestamos_Creditos_Detalle.IVAInteres +
                    Prestamos_Creditos_Detalle.IvaGastos +
                    Prestamos_Creditos_Detalle.IvaCuotaSocial +
                    Prestamos_Creditos_Detalle.IvaCuotaSocial + 
                    Prestamos_Creditos_Detalle.CapitalCooperativo + 
                    Prestamos_Creditos_Detalle.CuotaSocial + 
                    Prestamos_Creditos_Detalle.Gastos + 
                    Prestamos_Creditos_Detalle.Gastos_Seguro + 
                    Prestamos_Creditos_Detalle.Gastos_Servicio + 
                    Prestamos_Creditos_Detalle.Gastos_Otros + 
                    Prestamos_Creditos_Detalle.Gastos_Otros2 + 
                    Prestamos_Creditos_Detalle.Gastos_Otros3 + 
                    Prestamos_Creditos_Detalle.Gastos_Primera_Cuota,
    Prestamos_Creditos_Detalle.Capital,
    Prestamos_Creditos_Detalle.Interes,
    Prestamos_Creditos_Detalle.IVAInteres,
    Prestamos_Creditos_Detalle.IvaGastos,
    Prestamos_Creditos_Detalle.IvaCuotaSocial,
    Prestamos_Creditos_Detalle.IvaCuotaSocial,
    Prestamos_Creditos_Detalle.CapitalCooperativo,
    Prestamos_Creditos_Detalle.CuotaSocial,
    Prestamos_Creditos_Detalle.Gastos,
    Prestamos_Creditos_Detalle.Gastos_Seguro,
    Prestamos_Creditos_Detalle.Gastos_Servicio,
    Prestamos_Creditos_Detalle.Gastos_Otros,
    Prestamos_Creditos_Detalle.Gastos_Otros2,
    Prestamos_Creditos_Detalle.Gastos_Otros3,
    Plazo = datediff(day,  @Fecha_Trabajo, Prestamos_Creditos_Detalle.Fecha_Vencimiento),
    ValorActual = convert(decimal(19,2),(Prestamos_Creditos_Detalle.Capital - Prestamos_Creditos_Detalle.Cob_Capital+Prestamos_Creditos_Detalle.Interes-Prestamos_Creditos_Detalle.Cob_Interes+Prestamos_Creditos_Detalle.IVAInteres-Prestamos_Creditos_Detalle.Cob_IvaInteres)/(1+(Plazo * @Tasa / 36500))),
    NombrePila = Clientes.NombreFisico,
    Apellido = Clientes.ApellidoFisico,
    Legajo = Clientes.NroLegajo,
    Cuit = Clientes.Cuit,
    Nombre_Entidad = Prestamos_Entidades.Nombre,
    Plazo_Cuotas = Prestamos_Creditos.Plazo,
    Prestamos_Creditos_Detalle.Gastos_Primera_Cuota


From Prestamos_Creditos_Detalle
Inner Join Prestamos_Creditos On Prestamos_Creditos.Id = Prestamos_Creditos_Detalle.Id_Credito
Inner Join Clientes On Clientes.Id = Prestamos_Creditos.Id_Cliente
Inner Join Prestamos_Entidades on Prestamos_Entidades.Id = Prestamos_Creditos.Id_Entidad
Left Join Prestamos_Creditos_Ventas on Prestamos_Creditos_Ventas.id = Prestamos_creditos_detalle.Id_Venta 
Where   Fecha_Cobro Is Null And 
        Id_Entidad between @Entidad_Desde and @Entidad_Hasta And
        Prestamos_Creditos.Fecha_Otorgado Is Not Null And
        Prestamos_Creditos.Fecha_Anulacion Is Null And
        Prestamos_Creditos.Fecha_Cancelacion Is Null And
        (@IntId_Venta_Desde = -1 or Prestamos_Creditos_Detalle.Id_Venta between @IntId_Venta_Desde And @IntId_Venta_Hasta) And
        (@IntId_Inversor_Desde = -1 or Prestamos_Creditos_Ventas.Id_Inversor between @IntId_inversor_Desde And @IntId_inversor_Hasta)
order by Fecha_Otorgado,Id_Credito, Nro_Cuota

Listado de Créditos — Detallado

  • SP/archivo: Prestamos_ListadosCreditos_Detallado.proc.sql
  • Tipo: Reporte
  • Parámetros: @dFecha_Operacion_Desde, @dFecha_Operacion_Hasta, @IntEntidad_Desde, @IntEntidad_Hasta, @IntEspecie_Desde, @IntEspecie_Hasta, @IntCliente_Desde, @IntCliente_Hasta, @IntOtorgado, @IntExcluirMora
  • Relación con módulos: Prestamos_Creditos_Detalle + Prestamos_Creditos (Préstamos), Prestamos_Comercializadores, Prestamos_Entidades, Clientes, Sucursales, Prestamos_Solicitudes, Parametros (FechadeTrabajo).

Listado detallado de créditos por rango de fecha de operación, entidad, especie y cliente, a nivel de cuota impaga: muestra solicitud, cliente, documento, fecha de nacimiento, entidad, comercializador, sucursal, número de cuota, vencimiento, capital e importe. Permite filtrar otorgados/sin otorgar (@IntOtorgado) y excluir créditos en mora por umbral de días (@IntExcluirMora). SQL dinámico vía Exec(@SQLString).

CREATE  PROCEDURE  [dbo].[Prestamos_ListadosCreditos_Detallado]         @dFecha_Operacion_Desde  Datetime='01/01/1900',
                                                               @dFecha_Operacion_Hasta  Datetime='01/01/2200',
                                                               @IntEntidad_Desde                Int=0,
                                                               @IntEntidad_Hasta                 Int=9999999,
                                                               @IntEspecie_Desde                Int=0,
                                                               @IntEspecie_Hasta                 Int=9999999,
                                                               @IntCliente_Desde                 Int=0,
                                                               @IntCliente_Hasta                  Int=99999999,                                                 
                                                               @IntOtorgado                         Int = 0,  --0 Otorgado 1- Sin Otorgar
                                                               @IntExcluirMora int = 0  

As

Declare @SQLString VarChar(8000) 

Set @SQLString = 'Select  Prestamos_Creditos.Id,
    Solicitud_Id      = Prestamos_Creditos.id_Solicitud,
    Clientes_Id           = clientes.id,
    Clientes_Nombre  = clientes.nombre,
    Clientes_NroDoc   = IsNull(Case When (Select NroDoc From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Is Not Null Then (Select NroDoc From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Else substring(Clientes.Cuit,4,8) End,0),
    Clientes_FechaNac = (Select FechaNacimiento From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud),
    Entidad_Nombre     = Prestamos_Entidades.nombre,
    Comercializador_Nombre= Prestamos_Comercializadores.nombre,
    Sucursales_Descripcion= Sucursales.Descripcion, 
    Fecha_Operacion  = Prestamos_Creditos.Fecha_Operacion,
    Nrocuota    = Prestamos_Creditos_Detalle.nro_cuota,
    Fecha_Vto  = Prestamos_Creditos_Detalle.Fecha_Vencimiento,
    Capital        = SUM(Prestamos_Creditos_Detalle.Capital),
    Importe    = Case When (Select Count(*) * Avg(valorcuota_final) From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Is Not Null Then (Select Count(*) * Avg(valorcuota_final) From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Else SUM(Prestamos_Creditos_Detalle.Capital+Prestamos_Creditos_Detalle.Interes + Prestamos_Creditos_Detalle.IvaInteres + Prestamos_Creditos_Detalle.IvaGastos + Prestamos_Creditos_Detalle.IvaCuotaSocial + Prestamos_Creditos_Detalle.CapitalCooperativo + Prestamos_Creditos_Detalle.CuotaSocial + Prestamos_Creditos_Detalle.Gastos + Prestamos_Creditos_Detalle.Gastos_Seguro + Prestamos_Creditos_Detalle.Gastos_Servicio + Prestamos_Creditos_Detalle.Gastos_Otros + Prestamos_Creditos_Detalle.Gastos_Otros2 + Prestamos_Creditos_Detalle.Gastos_Otros3 + Prestamos_Creditos_Detalle.Punitorios ) End,
    Id_Especie = Prestamos_Creditos.Id_Especie 
From Prestamos_Creditos_Detalle
inner Join Prestamos_Creditos On Prestamos_Creditos.id = Prestamos_Creditos_Detalle.id_Credito
--inner Join Prestamos_Solicitudes On Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud
inner Join Prestamos_Comercializadores On Prestamos_Comercializadores.id = Prestamos_Creditos.id_Comercializador
inner Join Prestamos_entidades On Prestamos_entidades.id = Prestamos_Creditos.id_Entidad
inner Join Clientes On clientes.id = Prestamos_Creditos.id_Cliente
inner Join Sucursales On Sucursales.id = Prestamos_Creditos.id_Sucursal
Where   Prestamos_Creditos.Fecha_Operacion           Between ''' + Convert(varchar,@dFecha_Operacion_Desde,103) +''' And '''+Convert(varchar,@dFecha_Operacion_Hasta,103) +''' And 
    Prestamos_Creditos_detalle.Fecha_Cobro Is Null And
    Prestamos_Creditos.Id_Entidad Between '        + Convert(varchar,@IntEntidad_Desde)           +' And '+ Convert(varchar,@IntEntidad_Hasta)         +' And 
    Prestamos_Creditos.Id_Especie Between '        + Convert(varchar,@IntEspecie_Desde)           +' And '+ Convert(varchar,@IntEspecie_Hasta)         +' And 
    Prestamos_Creditos.Id_Cliente Between '        + Convert(varchar,@IntCliente_Desde)           +' And '+ Convert(varchar,@IntCliente_Hasta)         +' And 
    Prestamos_Creditos.Fecha_anulacion Is Null '

If @IntOtorgado =0 
           Set @SQLString = @SQLString +' And Prestamos_Creditos.Fecha_otorgado Is Not Null '

If @IntExcluirMora <> 0 
           Set @SQLString = @SQLString + ' And Prestamos_Creditos.Id In (Select Id
                                                                            From Prestamos_Creditos
                                                                            Where (Select Top 1 DateDiff(day, Fecha_Vencimiento_2, (select valor From Parametros where parametro = ''FechadeTrabajo''))
                                                                                 From Prestamos_Creditos_Detalle
                                                                                 Where Id_Credito = Prestamos_Creditos.Id And
                                                                                 Fecha_Cobro is Null
                                                                                 Order By nro_cuota) < ' + Convert(varchar,@IntExcluirMora) + ' ) '


Set @SQLString = @SQLString + ' Group By  Prestamos_Creditos.Id,
    Prestamos_Creditos.id_Solicitud,
    clientes.id,
    clientes.nombre,
    Clientes.cuit,
    Prestamos_Entidades.nombre,
    Prestamos_Comercializadores.nombre,
    Sucursales.Descripcion,
    Prestamos_Creditos_Detalle.nro_cuota,
    Prestamos_Creditos_Detalle.Fecha_Vencimiento,
    Prestamos_Creditos.Fecha_Operacion, 
    Prestamos_Creditos.Id_Especie '


Exec(@SQLString) 
Print @SQLString

Listado de Créditos — Resumido

  • SP/archivo: Prestamos_ListadosCreditos_Resumido.proc.sql
  • Tipo: Reporte
  • Parámetros: @dFecha_Operacion_Desde, @dFecha_Operacion_Hasta, @IntEntidad_Desde, @IntEntidad_Hasta, @IntEspecie_Desde, @IntEspecie_Hasta, @IntCliente_Desde, @IntCliente_Hasta, @IntOtorgado, @IntExcluirMora
  • Relación con módulos: Prestamos_Creditos_Detalle + Prestamos_Creditos (Préstamos), Prestamos_Comercializadores, Prestamos_Entidades, Clientes, Sucursales, Prestamos_Solicitudes, Parametros (FechadeTrabajo).

Versión resumida (un renglón por crédito) del listado anterior: agrupa por crédito mostrando cantidad de cuotas, capital total e importe, además de cliente, documento, entidad, comercializador y sucursal. Mismos filtros y opciones de otorgado/excluir mora que el detallado. Ordenado por nombre de cliente. SQL dinámico vía Exec(@SQLString).

--================================================================================================================================================================
--================================================================================================================================================================
--================================================================================================================================================================
/*
IMPORTANTE: NO MODIFICAR ESTE CÓDIGO YA QUE FUE GENERADO AUTOMÁTICAMENTE.


<CompoundXmlDocument>
  <User Name="PLENARIO\Eyanson" />
</CompoundXmlDocument>
*/



CREATE  PROCEDURE  [dbo].[Prestamos_ListadosCreditos_Resumido]        @dFecha_Operacion_Desde  Datetime='01/01/1900',
                                                               @dFecha_Operacion_Hasta  Datetime='01/01/2200',
                                                               @IntEntidad_Desde                Int=0,
                                                               @IntEntidad_Hasta                 Int=9999999,
                                                               @IntEspecie_Desde                Int=0,
                                                               @IntEspecie_Hasta                 Int=9999999,
                                                               @IntCliente_Desde                 Int=0,
                                                               @IntCliente_Hasta                  Int=99999999,                                                 
                                   @IntOtorgado                         Int = 0,  --0 Otorgado  1- Sin Otorgar
                                   @IntExcluirMora int = 0  
As

Declare @SQLString VarChar(8000) 

Set @SQLString = 'Select  Prestamos_Creditos.Id,
    Solicitud_Id      = Prestamos_Creditos.id_Solicitud,
    Clientes_Id       = clientes.id,
    Clientes_Nombre     = clientes.nombre,
    Clientes_NroDoc   = IsNull(Case When (Select NroDoc From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Is Not Null Then (Select NroDoc From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Else substring(Clientes.Cuit,4,8) End,0),
    Clientes_FechaNac = (Select FechaNacimiento From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud),
    Entidad_Nombre      = Prestamos_Entidades.nombre,
    Comercializador_Nombre= Prestamos_Comercializadores.nombre,
    Sucursales_Descripcion= Sucursales.Descripcion,
    Fecha_Operacion   = Prestamos_Creditos.Fecha_Operacion,
    Cantidad_Cuotas    = COUNT(Prestamos_Creditos_Detalle.Nro_Cuota),
    Capital                    = SUM(Prestamos_Creditos_Detalle.Capital),


    Importe           = 
    Case 
        When (Select Count(*) * Avg(valorcuota_final) From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) Is Not Null 
            and (Select Count(*) * Avg(valorcuota_final) From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) <>0 Then 

            (Select Count(*) * Avg(valorcuota_final) From Prestamos_Solicitudes Where Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud) 
        Else 
            SUM(Prestamos_Creditos_Detalle.Capital+Prestamos_Creditos_Detalle.Interes + Prestamos_Creditos_Detalle.IvaInteres + Prestamos_Creditos_Detalle.IvaGastos + Prestamos_Creditos_Detalle.IvaCuotaSocial + Prestamos_Creditos_Detalle.CapitalCooperativo + Prestamos_Creditos_Detalle.CuotaSocial + Prestamos_Creditos_Detalle.Gastos + Prestamos_Creditos_Detalle.Gastos_Seguro + Prestamos_Creditos_Detalle.Gastos_Servicio + Prestamos_Creditos_Detalle.Gastos_Otros + Prestamos_Creditos_Detalle.Gastos_Otros2 + Prestamos_Creditos_Detalle.Gastos_Otros3 + Prestamos_Creditos_Detalle.Punitorios ) 
        End ,



    Id_Especie          = Prestamos_Creditos.Id_Especie 
From Prestamos_Creditos_Detalle
inner Join Prestamos_Creditos On Prestamos_Creditos.id = Prestamos_Creditos_Detalle.id_Credito
--inner Join Prestamos_Solicitudes On Prestamos_Solicitudes.id = Prestamos_Creditos.id_Solicitud
inner Join Prestamos_Comercializadores On Prestamos_Comercializadores.id = Prestamos_Creditos.id_Comercializador
inner Join Prestamos_entidades On Prestamos_entidades.id = Prestamos_Creditos.id_Entidad
inner Join Clientes On clientes.id = Prestamos_Creditos.id_Cliente
inner Join Sucursales On Sucursales.id = Prestamos_Creditos.id_Sucursal
Where   Prestamos_Creditos.Fecha_Operacion           Between ''' + Convert(varchar,@dFecha_Operacion_Desde,103) +''' And '''+Convert(varchar,@dFecha_Operacion_Hasta,103) +''' And 
    Prestamos_Creditos_detalle.Fecha_Cobro Is Null  And
    Prestamos_Creditos.Id_Entidad Between '        + Convert(varchar,@IntEntidad_Desde)           +' And '+ Convert(varchar,@IntEntidad_Hasta)         +' And 
    Prestamos_Creditos.Id_Especie Between '        + Convert(varchar,@IntEspecie_Desde)           +' And '+ Convert(varchar,@IntEspecie_Hasta)         +' And 
    Prestamos_Creditos.Id_Cliente Between '        + Convert(varchar,@IntCliente_Desde)           +' And '+ Convert(varchar,@IntCliente_Hasta)         +' And 
    Prestamos_Creditos.Fecha_anulacion Is Null '


If @IntOtorgado =0 
           Set @SQLString = @SQLString +' And Prestamos_Creditos.Fecha_otorgado Is Not Null '

If @IntExcluirMora <> 0 
           Set @SQLString = @SQLString + ' And Prestamos_Creditos.Id In (Select Id
                                                                            From Prestamos_Creditos
                                                                            Where (Select Top 1 DateDiff(day, Fecha_Vencimiento_2, (select valor From Parametros where parametro = ''FechadeTrabajo''))
                                                                                 From Prestamos_Creditos_Detalle
                                                                                 Where Id_Credito = Prestamos_Creditos.Id And
                                                                                 Fecha_Cobro is Null
                                                                                 Order By nro_cuota) < ' + Convert(varchar,@IntExcluirMora) + ' ) '


Set @SQLString = @SQLString + ' Group By  Prestamos_Creditos.Id,
    Prestamos_Creditos.id_Solicitud,
    clientes.id,
    clientes.nombre,
    Clientes.cuit,
    Prestamos_Entidades.nombre,
    Prestamos_Comercializadores.nombre,
    Sucursales.Descripcion,
    Prestamos_Creditos.Fecha_Operacion, 
    Prestamos_Creditos.Id_Especie 
Order by clientes.nombre'


Exec(@SQLString) 
Print @SQLString

Días de Mora (listado) — Función

  • SP/archivo: Prestamos_Creditos_Dias_Mora_listado.function.sql
  • Tipo: Función
  • Parámetros: @Id_Credito, @Fecha, @bPrimerVto
  • Relación con módulos: Prestamos_Creditos_Detalle (Préstamos), Parametros (FechaDeTrabajo). Usa la función dbo.IsNegative. Ubicación: carpeta Functions\.

Función escalar que devuelve la cantidad de días de mora de un crédito a una fecha dada (por defecto la fecha de trabajo): calcula los días entre la fecha de vencimiento más antigua de las cuotas impagas (primer vencimiento o Fecha_Vencimiento_2 según @bPrimerVto) y la fecha de corte, devolviendo 0 si no hay atraso. Se usa como columna calculada dentro de los listados de créditos.

create  Function [dbo].[Prestamos_Creditos_Dias_Mora_listado](@Id_Credito Int, @Fecha DateTime = '01/01/1900',@bPrimerVto bit)
Returns Integer 
BEGIN 
    Declare @Dias Int                                                     
    Set @Dias = 0

    If @Fecha = '01/01/1900'
    Begin
        Set @Fecha = (Select Valor from Parametros where Parametro='FechaDeTrabajo')
    End
    Set @Dias = IsNull((Select dbo.IsNegative(DateDiff(day,Min(Case When @bPrimerVto = 1 then Prestamos_Creditos_Detalle.Fecha_Vencimiento else Fecha_Vencimiento_2 End), @Fecha),0) 
                            From [dbo].[Prestamos_Creditos_Detalle] 
                            Where Id_Credito = @Id_Credito And 
                                  ((Fecha_Cobro Is Null) Or (Fecha_Cobro is not null and fecha_Cobro > @Fecha))),0)
    --Set @Dias = ( DateDiff(Day,(Select Min(Fecha_Vencimiento)
    --              From Prestamos_Resumenes
    --              Where Id_Cliente = @Id_Cliente And 
    --              Fecha_Pago Is Null And
    --              Fecha_Vencimiento > (Select IsNull(Max(Fecha_Pago),'01/01/1900') From Prestamos_Resumenes Where Id_Cliente = @Id_Cliente) And
    --              Importe_Pendiete_Aplicacion = 0), @Fecha)
    --          )
    Return @Dias

END
¿Te resultó útil este manual?