← Índice de manuales
Manual funcional · Sistema Plenario v14

Reportes — Factoring e Inversiones

Catálogo de los stored procedures de reportería del módulo de Factoring (descuento de cheques, valores, firmantes, liquidaciones, planillas de cobranza) y del módulo de Inversiones (operaciones, posiciones e…

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

Reportes — Factoring e Inversiones

Catálogo de los stored procedures de reportería del módulo de Factoring (descuento de cheques, valores, firmantes, liquidaciones, planillas de cobranza) y del módulo de Inversiones (operaciones, posiciones e inversores). Cada entrada documenta el SP real tal como está en la base v14, sus parámetros, las tablas/módulos que cruza y el SQL completo.

La mayoría de estos reportes arman el SQL dinámicamente (SQL string + Exec(@strSQL)), con filtros opcionales por rangos (cliente, oficial, banco, firmante, especie, fechas) y dejan un Print @strSQL para depuración. Las fechas se formatean en estilo 103 (dd/mm/yyyy).


Listado de Valores Extendido (Factoring)

  • SP/archivo: Documentos_Listado_Valores_Extendido.proc.sql
  • Tipo: Reporte
  • Parámetros: @intClienteDesde, @intClienteHasta, @intOficialDesde, @intOficialHasta, @intBancoDesde, @intBancoHasta, @dFechaDesde, @dFechaHasta, @strOrden, @intFirmanteDesde, @intFirmanteHasta, @bCartera, @bCustodia, @bDepositados, @bAcreditados, @bRechazados, @bEntregados, @bVendidos, @bOPs, @bFacturas, @bDocumentos, @intEspecieDesde, @intEspecieHasta
  • Relación con módulos: Documentos, Liquidaciones / Liquidaciones_Detalle, Entregas / Entregas_Detalle, Ventas / Ventas_Detalle, OrdenesDePago / OrdenesDePago_Detalle, Clientes, Oficiales, Firmantes, Bancos, Inversores, Documentos_Inversores, Especies, Recibos / Recibos_Detalle

Reporte maestro de valores (cheques, documentos y facturas) que cruza todo el ciclo de factoring: cartera, custodia, depositados, acreditados, rechazados, entregados, vendidos y órdenes de pago. Los flags @b* activan cada estado a incluir en el WHERE armado dinámicamente; devuelve datos de liquidación y venta por cada valor.

CREATE  PROCEDURE [dbo].[Documentos_Listado_Valores_Extendido]
                        @intClienteDesde Int = 1, 
                        @intClienteHasta Int = 99999, 
                        @intOficialDesde Int = 1, 
                        @intOficialHasta Int = 99999, 
                        @intBancoDesde Int = 1, 
                        @intBancoHasta Int = 99999, 
                        @dFechaDesde Datetime = '1/1/2001',
                        @dFechaHasta Datetime = '1/1/2020',
                        @strOrden Varchar(50) = ' Order By Fecha_Deposito', 
                        @intFirmanteDesde Int = 0, 
                        @intFirmanteHasta Int = 99999,
                        @bCartera Bit = 1, 
                        @bCustodia Bit = 0, 
                        @bDepositados Bit = 0, 
                        @bAcreditados Bit = 0, 
                        @bRechazados Bit = 0, 
                        @bEntregados Bit = 0, 
                        @bVendidos Bit = 0, 
                        @bOPs Bit = 0, 
                        @bFacturas Bit = 0, 
                        @bDocumentos Bit = 0,
                        @intEspecieDesde Int = 0,
                        @intEspecieHasta Int = 0

As

Declare @strDepositados VarChar(500),
        @strAcreditados VarChar(500), 
        @strRechazados  VarChar(500),
        @strEntregados  VarChar(500), 
        @strVendidos    VarChar(500),
        @strOps         VarChar(500),
        @strCartera     VarChar(500),
        @strDocumentos  VarChar(500),
        @strFacturas    VarChar(500),
        @strCustodia    VarChar(500),
        @strSQL         VarChar(8000),
        @strWhere       VarChar(8000)

Set @strWhere = ''

Set @strSQL = 'Select
Clase = (Case   when D.Id_DocumentoTipo = 1 then ''C''  
                when D.Id_DocumentoTipo = 2 then ''D''  
                when D.Id_DocumentoTipo = 3 then ''F''  
         End),  

Tipo  = (Case   When Id_DocumentoTipo = 1 And Liquidaciones.Dto_Gestion = 1 then ''Dto'' 
                When Id_DocumentoTipo = 1 And Liquidaciones.Dto_Gestion = 2 then ''Ges'' 
                When (Select count(*) from recibos_detalle where id_documento  = D.Id) <> 0 then ''Rec N'' + convert(char, (select Recibos.Id from recibos inner join recibos_detalle on recibos_detalle.id_recibo = recibos.id where id_documento = D.Id))
                Else ''Ext'' 
         End), 
Nro_Cheque = Nro_Comprobante, 
Id_Banco, 
BancoNombre = Bancos.Nombre, 
Sucursal, 
Fecha_Emision  = (Case When IsNull(Liquidaciones.Id,0) <> 0 then Liquidaciones.Fecha 
               When (Select count(*) from recibos_detalle where id_documento  = D.Id) <> 0 then (select fecha from recibos inner join recibos_detalle on recibos_detalle.id_recibo = recibos.id where id_documento = D.Id)
               Else null End), 
Fecha_Deposito, 
Fecha_Acreditacion, 
Fecha_Depositado, 
Fecha_Acreditado,
Fecha_Rechazado, 
Bruto, 
Clearing, 
Orden = (Case   When D.AlaOrden = 0 then ''NO''  
                Else ''SI''  
         End),  

Estado = Case   When D.Fecha_Rechazado is not null Then ''Rechazado''
                When Entregas.Id is not null Then ''Entregado''
                When Ventas.Id is not null Then ''Vendido''
                When OrdenesDePago.Id is not null Then ''O.P.''
                When Cuenta_Ac <> '''' Then ''Acreditado''
                When Cuenta_Dep <> '''' Then ''Depositado''
                When Documentos_Inversores.Id is not null then ''Custodia''
                Else ''Cartera''
            End,

Nombre_Cliente = Clientes.Nombre,
Id_Cliente    = Clientes.Id, 
Nombre_Firmante = Firmantes.Nombre, 
Firmante_CUIT   = Firmantes.CUIT,
Nombre_Oficial = Oficiales.Nombre,
Id_Oficial     =Oficiales.Id, 
N_Liquidacion  = Liquidaciones.NroComprobante, 
Fecha_Liquidacion = Liquidaciones.Fecha_Confirmacion, 
Liq_Tasa_Porc          = Liquidaciones.Tasa, 
Liq_Gastos_Porc        =Liquidaciones.P_Gastos, 
Liq_GastosVC_Porc        =Liquidaciones.P_Gastos_VC, 
Liq_Comision       = Liquidaciones.P_Comision, 
Liq_ITF = Liquidaciones.ITF, 
Cheque_Gastos     = liquidaciones_Detalle.Gastos, 
Cheque_GastosVC     = liquidaciones_Detalle.Gastos_Vc, 
Cheque_Iva     = liquidaciones_Detalle.Iva, 
Cheque_Comision     = liquidaciones_Detalle.Comision, 
Cheque_Interes     = liquidaciones_Detalle.Interes, 
Cheque_ITF = Liquidaciones_Detalle.ITF, 
Cheque_Neto    = liquidaciones_Detalle.Neto, 
N_Venta        = Ventas.Id, 
Fecha_Venta     = Ventas.Fecha_Confirmacion, 
Venta_Tasa_Porc     = Ventas.Tasa, 
Venta_Gastos_Porc   = Ventas.P_Gastos, 
Venta_GastosVC_Porc  = Ventas.P_Gastos_Vc,
Venta_Gastos    = Ventas_Detalle.Gastos, 
Venta_Gastos_VC = Ventas_Detalle.Gastos_VC,
Venta_Interes   = Ventas_Detalle.Interes,
Venta_Iva       = Ventas_Detalle.Iva,
Venta_Neto     = Ventas_Detalle.Neto,
ID_Especie  = D.Id_Especie,
SiglaEspecie    = E.Sigla
From Documentos D
Left Outer Join Liquidaciones_Detalle on Liquidaciones_Detalle.Id_Documento = D.Id
Left Outer Join Liquidaciones on Liquidaciones.Id = Liquidaciones_Detalle.Id_Liquidacion
Left Outer Join Entregas_Detalle on Entregas_Detalle.Id_Documento = D.Id
Left Outer Join Entregas on Entregas.Id = Entregas_Detalle.Id_Entrega
Left Outer Join Ventas_Detalle on Ventas_Detalle.Id_Documento = D.Id
Left Outer Join Ventas on Ventas.Id = Ventas_Detalle.Id_Venta
Left Outer Join OrdenesDePago_Detalle on OrdenesDePago_Detalle.Id_Documento = D.Id
Left Outer Join OrdenesDePago on OrdenesDePago.Id = OrdenesDePago_Detalle.Id_OrdendePago and OrdenesdePago.Fecha_Anulacion is null
Left Outer Join Clientes on Clientes.Id = D.Id_Cliente
Left Outer Join Oficiales on Oficiales.Id = Clientes.Oficial
Left Outer Join Firmantes on Firmantes.Id = D.Id_Firmante
Left Outer Join Bancos on Bancos.CodigoBCRA = D.Id_Banco
Left Outer Join Inversores on Ventas.Id_Inversor = Inversores.Id
Left Outer Join Documentos_Inversores on Documentos_Inversores.Id_Documento = D.Id and Documentos_Inversores.Fecha_Del is null
Left Outer Join Especies E on E.Id = D.Id_Especie
Where
(D.Anulado = 0 
And Id_Banco Between ' + convert(char, @intBancoDesde) + ' And ' + convert(char, @intBancoHasta) 
+ ' And Id_Firmante Between ' + convert(char, @intFirmanteDesde) + ' And ' +  convert(char, @intFirmanteHasta)
+ ' And D.Id_Cliente Between ' + convert(char, @intClienteDesde) + ' And ' +  convert(char, @intClienteHasta) 
+ ' And D.Id_Especie Between ' + convert(char, @intEspecieDesde) + ' And ' +  convert(char, @intEspecieHasta)
+ ' And Oficial Between ' + convert(char, @intOficialDesde) + ' And ' +  convert(char, @intOficialHasta) + ')'


Set @strCartera = '(D.Id_DocumentoTipo = 1 And D.Fecha_Depositado Is Null And D.Fecha_Rechazado is null And D.Id not In (Select Id_Documento From Documentos_Inversores Where Fecha_Del Is Null))'
Set @strDepositados = '(Fecha_Depositado is Not Null and Fecha_Acreditado is Null And Entregas.Id is null and Ventas.Id is null And OrdenesdePago.Id is null)'
Set @strAcreditados = '(Fecha_Acreditado is Not Null And Fecha_Rechazado Is Null And Entregas.Id is null and Ventas.Id is null And OrdenesdePago.Id is null)'
Set @strRechazados = '(D.Fecha_Rechazado Is Not Null)'
Set @strEntregados = '(D.Fecha_Rechazado is null And Entregas.Id is not null) '
Set @strVendidos = '(Fecha_Rechazado Is Null and Ventas.Id is not null) '
Set @strOps = '(Fecha_Rechazado Is Null And Ordenesdepago.Id is not null) '
Set @strCustodia = '(D.Id In (Select Id_Documento From Documentos_Inversores Where Fecha_Del Is Null))'
Set @strDocumentos = '(Id_DocumentoTipo = 2)'
Set @strFacturas = '(Id_DocumentoTipo = 3)'


If @bCartera <> 0  --Si hay que incluir los cheques en cartera
    If @strWhere = '' 
        Set @strWhere = @strCartera
    Else
        Set @strWhere = ' Or' + @strCartera

If @bDepositados <> 0
    If @strWhere = '' 
        Set @strWhere = @strDepositados
    Else
        Set @strWhere = @strWhere + ' Or ' + @strDepositados

If @bAcreditados <> 0
    If @strWhere = '' 
        Set @strWhere = @strAcreditados
    Else
        Set @strWhere = @strWhere + ' Or ' + @strAcreditados

If @bRechazados <> 0
    If @strWhere = '' 
        Set @strWhere = @strRechazados
    Else
        Set @strWhere = @strWhere + ' Or ' + @strRechazados

If @bVendidos <> 0
    If @strWhere = '' 
        Set @strWhere = @strVendidos
    Else
        Set @strWhere = @strWhere + ' Or ' + @strVendidos

If @bEntregados <> 0
    If @strWhere = '' 
        Set @strWhere = @strEntregados
    Else
        Set @strWhere = @strWhere + ' Or ' + @strEntregados

If @bOPs <> 0
    If @strWhere = '' 
        Set @strWhere = @strOps
    Else
        Set @strWhere = @strWhere + ' Or ' + @strOps

If @bDocumentos <> 0
    If @strWhere = '' 
        Set @strWhere = @strDocumentos
    Else
        Set @strWhere = @strWhere + ' Or ' + @strDocumentos

If @bFacturas <> 0
    If @strWhere = '' 
        Set @strWhere = @strFacturas
    Else
        Set @strWhere = @strWhere + ' Or ' + @strFacturas

If @bFacturas <> 0
    If @strWhere = '' 
        Set @strWhere = @strFacturas
    Else
        Set @strWhere = @strWhere + ' Or ' + @strFacturas

If @bCustodia <> 0
    If @strWhere = '' 
        Set @strWhere = @strCustodia
    Else
        Set @strWhere = @strWhere + ' Or ' + @strCustodia

If @strWhere <> '' 
    Set @strSQL = @strSQL + ' And (' + @strWhere + ')'

If @dFechaDesde <> '01/01/1900' And @dFechaHasta <> '01/01/1900'
    Set @strSQL = @strSQL + ' And D.Fecha_Deposito Between ''' + rtrim(convert(char, @dFechaDesde, 103)) + ''' And ''' +  rtrim(convert(char, @dFechaHasta, 103)) + ''''

Set @strSQL = @strSQL + @strOrden

print @strSQL

Exec(@strSQL)

Listado de Valores — Documentos Propios (Factoring)

  • SP/archivo: Documentos_propios_Listado_Valores.proc.sql
  • Tipo: Reporte
  • Parámetros: @intClienteDesde, @intClienteHasta, @intInversorDesde, @intInversorHasta, @intProveedorDesde, @intProveedorHasta, @intBancoDesde, @intBancoHasta, @dFechaDesde, @dFechaHasta, @intFiltro, @intOrder, @strCuentaDesde, @strCuentaHasta
  • Relación con módulos: Documentos_Propios, Bancos, OrdenesDePago / OrdenesDePago_Detalle, y por subconsulta Firmantes, Clientes, Inversores, Proveedores, Cuentas

Lista los cheques/documentos propios (emitidos por la empresa) clasificados por tipo de entidad (cliente, inversor, proveedor o cuenta). @intFiltro selecciona el subconjunto: 1 = debitados, 2 = rechazados, 3 = pendientes de debitar en cartera. @intOrder ordena por bruto o por fecha de débito.



CREATE PROCEDURE [dbo].[Documentos_propios_Listado_Valores] 
                        @intClienteDesde Int = 1, 
                        @intClienteHasta Int = 9999999, 
                        @intInversorDesde Int = 0, 
                        @intInversorHasta Int = 9999999, 
                        @intProveedorDesde Int = 0, 
                        @intProveedorHasta Int = 9999999,
                        @intBancoDesde Int = 0, 
                        @intBancoHasta Int = 7, 
                        @dFechaDesde Datetime = '01/01/1900',
                        @dFechaHasta Datetime = '01/01/2900',
                        @intFiltro int = 0,
                        @intOrder int = 0,
                        @strCuentaDesde VarChar(8) = '1',
                        @strCuentaHasta VarChar(8) = '99999999'
As

Declare @strSQL VarChar(8000)

set @strSQl = 
'Select
Nro_Comporbante = Nro_Comprobante, 
Id_Banco, 
Nro_Cta=Documentos_Propios.Nro_Cta,
Firmante_Nombre = (Select Firmantes.nombre From Firmantes Where Documentos_Propios.Id_Firmante = Firmantes.Id),
Sucursal, 
Fecha_Emision=Fecha_Emision,
Fecha_Depositado = Fecha_Deposito, 
Fecha_Acreditado = Fecha_Acreditacion, 
Bruto, 
Clearing, 
Letra          = (Case when Documentos_Propios.Fecha_Depositado is not null then ''Si'' else ''No'' end),
Cancelado      = (Case when Documentos_Propios.Fecha_Rechazado is not null then ''Si''  else ''No'' end),
Anulado        = (Case when Documentos_Propios.Anulado =1 then ''Si'' else ''No'' end),
Entidad_Nombre = (Case   when Id_Tipo_Entidad = 1 Then ''Cliente: '' + (Select nombre From Clientes where Id = Documentos_Propios.id_Entidad) 
                         when Id_Tipo_Entidad = 2 Then ''Inversor: '' + (Select nombre From Inversores where Id = Documentos_Propios.id_Entidad) 
                         when Id_Tipo_Entidad = 3 Then ''Proveedor: '' + (Select nombre From Proveedores where Id = Documentos_Propios.id_Entidad)   
                         when Id_Tipo_Entidad = 4 Then ''Cuenta: '' + (Select (Convert(NVarChar,(LTrim(Rtrim(Nro_Cta))) + '' - '' + (LTrim(Rtrim(Nombre))))) From Cuentas Where Nro_Cta = Documentos_Propios.Id_Entidad)
                         else ''''  end) ,
Documentos_Propios.id_entidad,
id_tipo_entidad,
Id_Cliente  = Case when Id_Tipo_Entidad = 1 Then Documentos_Propios.Id_Entidad Else '''' End,
Id_Inversor = Case when Id_Tipo_Entidad = 2 Then Documentos_Propios.Id_Entidad Else '''' End, 
Id_Proveedor= Case when Id_Tipo_Entidad = 3 Then Documentos_propios.id_Entidad Else '''' End,
Banco_Nombre = Bancos.Nombre,
Fecha_rechazado,
AlaOrden = (case when AlaOrden = 0 then ''No'' else ''Si''end),
Documentos_propios.Id,
Concepto = IsNull(OrdenesDePago.Detalle,''-'')
From Documentos_Propios
Left Outer Join Bancos on Bancos.CodigoBCRA = Documentos_Propios.Id_Banco
Left Outer Join OrdenesDePago_Detalle On OrdenesDePago_Detalle.Id_Documento_Propio = Documentos_Propios.Id
Left Outer Join OrdenesDePago On OrdenesDePago.Id = OrdenesDePago_Detalle.Id_OrdenDePago
Where 
    (Id_Banco Between ' + convert(char,@intBancoDesde) + ' And ' + convert(char,@intBancoHasta) + ' 
    And (
    (Id_tipo_entidad = 1 and Documentos_Propios.Id_entidad between ' + convert(char,@intClienteDesde) + ' And ' + convert(char,@intClienteHasta) + ') Or
    (Id_tipo_entidad = 3 and Documentos_Propios.Id_entidad between ' + convert(char,@intProveedorDesde) + ' And ' + convert(char,@intProveedorHasta) + ') Or
    (Id_tipo_entidad = 2 and Documentos_Propios.Id_entidad between ' + convert(char,@IntinversorDesde) + ' And ' + convert(char,@intInversorHasta) + ') Or
    (Id_tipo_entidad = 4 and Documentos_Propios.Id_entidad between ' + convert(char,@strCuentaDesde) + ' And ' + convert(char,@strCuentaHasta) + ')
        ) 
    )'

If @intFiltro = 1 --- Debitados
Begin
    Set @strSQl = @strSQl + 'And Documentos_Propios.Fecha_Depositado is not null'
End 

If @intFiltro = 2  --- Rechazados
Begin
    Set @strSQl = @strSQl + ' And Documentos_propios.fecha_rechazado is not null'
End 

If @intFiltro = 3   ---pend de debitar en carter
Begin
    Set @strSQl = @strSQl + 'And Documentos_Propios.Fecha_Depositado Is Null  And Documentos_Propios.Fecha_Rechazado Is Null And Documentos_Propios.Anulado <> 1'
End 

if @dFechaDesde <> '01/01/1900' or @dFechaHasta <> '01/01/2900' 
    Set @strSQl = @strSQl + ' And Fecha_Deposito between ''' + RTrim(Convert(Char,@dFechaDesde,103)) + ''' and ''' + RTrim(Convert(Char,@dFechaHasta,103)) + ''''


If @intOrder = 1
    set @strSQL = @strSQl + ' Order By Documentos_Propios.Bruto'

If @intOrder = 2
    set @strSQL = @strSQl + ' Order By Documentos_Propios.Fecha_Depositado'

Print @strSQL

Exec(@strSQL)

Listado Última Operación (Factoring)

  • SP/archivo: Factoring_ListadoUltimaOperacion.proc.sql
  • Tipo: Reporte
  • Parámetros: @Fecha_Hasta, @Cliente_Desde, @Cliente_Hasta, @Id_Usuario_Search
  • Relación con módulos: Liquidaciones / Liquidaciones_Detalle, Documentos, Clientes, función fn_Get_Categorias_Visibles_x_Usuario (seguridad por categoría/usuario)

Para cada cliente devuelve su última liquidación (la de fecha máxima) con el bruto operado y el plazo en días entre la confirmación y @Fecha_Hasta. Usa tablas temporales (#LiquidacionesClientes, #MaximasPorCliente) y respeta la visibilidad de categorías por usuario.

CREATE Procedure [dbo].[Factoring_ListadoUltimaOperacion]
                            @Fecha_Hasta DateTime = '20160414',
                            @Cliente_Desde Int = 1,
                            @Cliente_Hasta Int = 20,
                            @Id_Usuario_Search int = 0
As
Select Fecha_Confirmacion, 
       Liquidaciones.Id_Cliente,
       Clientes.Nombre,
       Bruto = Sum(Bruto),
       Plazo = DateDiff(day, Fecha_Confirmacion, @Fecha_Hasta)
Into #LiquidacionesClientes
From Liquidaciones
Inner Join Clientes on Clientes.Id = Liquidaciones.Id_Cliente
Inner Join Liquidaciones_Detalle on Liquidaciones_Detalle.Id_Liquidacion = Liquidaciones.Id
Inner Join Documentos on Documentos.Id = Liquidaciones_Detalle.Id_Documento
Where Clientes.Id_Categoria in (Select Id from dbo.[fn_Get_Categorias_Visibles_x_Usuario](@Id_Usuario_Search))
And Liquidaciones.Id_Cliente between @Cliente_Desde and @Cliente_Hasta
group by Liquidaciones.Id, Fecha_Confirmacion, Liquidaciones.Id_Cliente, Clientes.Nombre
Order by Liquidaciones.Id_Cliente, Fecha_Confirmacion

Alter Table #LiquidacionesClientes Add Id int identity (1, 1)

Select Id = Max(Id), Id_Cliente
Into #MaximasPorCliente
From #LiquidacionesClientes
Group By Id_Cliente

Select #LiquidacionesClientes.*
From #MaximasPorCliente
Inner Join #LiquidacionesClientes on #LiquidacionesClientes.Id = #MaximasPorCliente.Id
---Where #LiquidacionesClientes.Id_Cliente between @Cliente_Desde and @Cliente_Hasta
Order By #LiquidacionesClientes.Id_Cliente

Listado de Firmantes (Factoring)

  • SP/archivo: Firmantes_Listado.proc.sql
  • Tipo: Reporte
  • Parámetros: @id, @nombre, @cuit, @ref_banco, @ref_comercial, @inf_comercial, @visita, @limite_total, @saldo, @Activo, @MotivoBloqueo, @Id_Desde, @Id_Hasta, @bnsolo99, @filtrar_limite
  • Relación con módulos: Firmantes, Calificaciones, y por subconsulta Documentos (cartera/saldo del firmante)

Listado de firmantes con su calificación, importe en cartera (suma de cheques sin acreditar y no anulados) y la diferencia contra el límite total. Filtros opcionales por nombre, CUIT, referencias bancarias/comerciales, motivo de bloqueo y rango de IDs. @bnsolo99 filtra CUITs ficticios 99...9.

CREATE PROCEDURE [dbo].[Firmantes_Listado] 
                                  @id Int = 0,
                                  @nombre Varchar(80) = '',
                                  @cuit Varchar(15) = '',
                                  @ref_banco Varchar(256) = '',
                                  @ref_comercial Varchar(256) = '',
                                  @inf_comercial Varchar(256) = '',
                                  @visita Varchar(256) = '',
                                  @limite_total Numeric(9,2) = 0,
                                  @saldo Numeric(9,2) = 0,
                                  @Activo bit = 0,
                                  @MotivoBloqueo varchar(50) = '',
                                  @Id_Desde Int = 0,
                                  @Id_Hasta Int = 13827,
                                  @bnsolo99 Bit = 0,
                                  @filtrar_limite bit = 1



AS
Declare @Where     VarChar(1000), 
        @Columns   VarChar(1000), 
        @SQLString VarChar(1000), 
        @Inner     VarChar(1000)

Set @Where = ''
Set @Columns = 'Calificacion = Calificaciones.Nombre,
                Firmantes.*,
                Importe_Cartera= IsNull((Select Sum(Bruto) From Documentos Where Id_Firmante = Firmantes.Id And Fecha_Acreditado Is Null  And Documentos.Anulado=0) ,0),
                Importe_Dif = Firmantes.Limite_Total - IsNull((Select Sum(Bruto) From Documentos Where Id_Firmante = Firmantes.Id And Fecha_Acreditado Is Null  And Documentos.Anulado=0 ),0)'


If @id <> 0
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.id = ' + RTrim(Convert(Char,@id))
        Else
                Set @Where = @Where + ' Firmantes.id = ' + RTrim(Convert(Char,@id))

If @nombre <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.nombre Like ''%' + Replace(RTrim(@nombre),' ', '%') + '%'''
        Else
                Set @Where = @Where + ' Firmantes.nombre Like ''%' + Replace(RTrim(@nombre),' ', '%') + '%'''

If @cuit <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.cuit = ''' + Replace(RTrim(@cuit),' ', '%') + ''''
        Else
                Set @Where = @Where + ' Firmantes.cuit = ''' + Replace(RTrim(@cuit),' ', '%') + ''''


If @ref_banco <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.ref_banco Like ''%' + Replace(RTrim(@ref_banco),' ', '%') + '%'''
        Else
                Set @Where = @Where + ' Firmantes.ref_banco Like ''%' + Replace(RTrim(@ref_banco),' ', '%') + '%'''

If @ref_comercial <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.ref_comercial Like ''%' + Replace(RTrim(@ref_comercial),' ', '%') + '%'''
        Else
                Set @Where = @Where + ' Firmantes.ref_comercial Like ''%' + Replace(RTrim(@ref_comercial),' ', '%') + '%'''

If @inf_comercial <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.inf_comercial Like ''%' + Replace(RTrim(@inf_comercial),' ', '%') + '%'''
        Else
                Set @Where = @Where + ' Firmantes.inf_comercial Like ''%' + Replace(RTrim(@inf_comercial),' ', '%') + '%'''

If @visita <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.visita Like ''%' + Replace(RTrim(@visita),' ', '%') + '%'''
        Else
                Set @Where = @Where + ' Firmantes.visita Like ''%' + Replace(RTrim(@visita),' ', '%') + '%'''

If @limite_total <> 0
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.limite_total = '+ RTrim(Convert(Char,@limite_total))
        Else
                Set @Where = @Where + ' Firmantes.limite_total = ' + RTrim(Convert(Char,@limite_total))

If @filtrar_limite <> 0
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.limite_total <> 0 '
        Else
                Set @Where = @Where + ' Firmantes.limite_total <> 0 '
If @saldo <> 0
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.saldo = ' + RTrim(Convert(Char,@saldo))
        Else
                Set @Where = @Where + ' Firmantes.saldo = ' + RTrim(Convert(Char,@saldo))

If @MotivoBloqueo <> ''
        If @Where <> ''
                Set @Where = @Where + ' And Firmantes.MotivoBloqueo Like ''%' + Replace(RTrim(@MotivoBloqueo),' ', '%') + '%'''
        Else
                Set @Where = @Where + ' Firmantes.MotivoBloqueo Like ''%' + Replace(RTrim(@MotivoBloqueo),' ', '%') + '%'''

If @bnsolo99 <> 0
        If @Where <> ''
                Set @Where = @Where + 'And CUIT like ''99%9'''
        Else
                Set @Where = @Where + 'CUIT like ''99%9'''

Set @Inner = '  Inner Join Calificaciones On Calificaciones.Id = Firmantes.Calificacion '

If @Where <> '' 
        Set @SQLString = 'Select ' + @Columns + ' From Firmantes ' + @Inner + ' Where ' + @Where + ' And Firmantes.Id Between ' + RTrim(Convert(Char,@Id_Desde)) + ' And ' + RTrim(Convert(Char,@Id_Hasta))
Else 
        Set @SQLString = 'Select ' + @Columns + ' From Firmantes ' + @Inner + ' Where Firmantes.Id Between ' + RTrim(Convert(Char,@Id_Desde)) + ' And ' + RTrim(Convert(Char,@Id_Hasta))
Exec(@SQLString) 
Print @SQLString

Control de Carga de Planillas de Cobranza — Datos (Factoring)

  • SP/archivo: Listado_ControlCargaPlanillasCobranza_Datos.proc.sql
  • Tipo: Reporte
  • Parámetros: @FechaDesde, @FechaHasta, @Aplicada, @Transferida, @CobranzaAplicada, @Liquidadas, @Cerrada (flags varchar: Si / No / Todo)
  • Relación con módulos: Prestamos_Cobranza_Comercio / Prestamos_Cobranza_Comercio_Detalles, Clientes

Reporte de control de planillas de cobranza de comercios (proveedores financieros). Cada flag textual añade un filtro por estado: aplicada, transferida (validación), cobranza aplicada (validación II), liquidada (con recibo) y cerrada. Versión por rango de fechas para la app de escritorio.

CREATE procedure [dbo].[Listado_ControlCargaPlanillasCobranza_Datos] 
                                           @FechaDesde datetime = '01/01/1900',
                                           @FechaHasta datetime = '31/12/2020' ,
                                           @Aplicada varchar(10) = 'Todo',      
                                           @Transferida varchar(10) = 'Todo' ,
                                           @CobranzaAplicada varchar(10) = 'Todo',
                                           @Liquidadas varchar(10) = 'Todo',
                                           @Cerrada varchar(10) = 'Todo'

as 
Declare @Where     VarChar(1000),
         @SQLString VarChar(8000)

Set @Where = ''
set  @SQLString= '
Select Planilla = Prestamos_Cobranza_Comercio.Id, 
Fecha_Validacion = Case When Fecha_Validacion is Null then ''NO'' else convert(char, Fecha_Validacion, 103) End, 
Fecha_Validacion_II = Case When Fecha_Validacion_II is Null then ''NO'' else convert(char, Fecha_Validacion_II, 103) End, 
Fecha_Aplicacion  = Case When Fecha_Aplicacion is Null then ''NO'' else convert(char, Fecha_Aplicacion, 103) End, 
ProveedorFinanciero=Razon_Social, 
Liquidada = ConRecibo, 
Fecha_Pago, 
Nro_Documento, 
Id_Cliente,
Clientes.Nombre, 
Importe
From Prestamos_Cobranza_Comercio
Inner Join Prestamos_Cobranza_Comercio_Detalles on Prestamos_Cobranza_Comercio_Detalles.Id_Cobranza_Comercio = Prestamos_Cobranza_Comercio.Id
Inner Join Clientes on Clientes.Id = Prestamos_Cobranza_Comercio_Detalles.Id_Cliente'

if @FechaDesde  <> '01/01/1900' or @FechaHasta <> '01/01/1900'      
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha Between '''     + RTrim(Convert(Char,@FechaDesde,103)) + ''' and ''' + RTrim(Convert(Char,@FechaHasta,103))+ ''''
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha Between ''' + RTrim(Convert(Char,@FechaDesde,103)) + ''' and ''' + RTrim(Convert(Char,@FechaHasta,103))+ ''''
If @Aplicada = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Aplicacion is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Aplicacion is not null  ' 
If @Aplicada = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Aplicacion is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Aplicacion is null  ' 
If @Transferida = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion is not null  ' 
If @Transferida = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion is null  ' 

If @CobranzaAplicada = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion_II is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion_II is not null  ' 
If @CobranzaAplicada = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion_II is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion_II is null  ' 

If @Cerrada = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Cierre is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Cierre is not null  ' 
If @Cerrada = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Cierre is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Cierre is null  ' 

If @Liquidadas = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.ConRecibo  = ''Si''  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.ConRecibo = ''Si'' ' 
If @Liquidadas = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.ConRecibo = ''No''  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.ConRecibo  = ''No''  ' 



If @Where <> '' 
        Set @SQLString = @SQLString + ' Where ' +  @Where
Else 
        Set @SQLString = @SQLString 
Exec(@SQLString) 
Print @SQLString

Control de Carga de Planillas de Cobranza — Datos Web (Factoring)

  • SP/archivo: Listado_ControlCargaPlanillasCobranza_Datos_Web.proc.sql
  • Tipo: Reporte
  • Parámetros: @Id, @Aplicada, @Transferida, @CobranzaAplicada, @Liquidadas, @Cerrada, @Comercio (flags varchar: Si / No / Todo)
  • Relación con módulos: Prestamos_Cobranza_Comercio / Prestamos_Cobranza_Comercio_Detalles, Clientes

Variante web del control de planillas de cobranza: en vez de filtrar por rango de fechas, filtra por planilla puntual (@Id) y por comercio (@Comercioid_entidad). Mismos flags de estado que la versión de escritorio.

CREATE procedure [dbo].[Listado_ControlCargaPlanillasCobranza_Datos_Web] 
                                           @Id Int =0 ,
                                           @Aplicada varchar(10) = 'No',        
                                           @Transferida varchar(10) = 'No' ,
                                           @CobranzaAplicada varchar(10) = 'No',
                                           @Liquidadas varchar(10) = 'Todo',
                                           @Cerrada varchar(10) = 'No',
                                           @Comercio Int = 0

as 
Declare @Where     VarChar(1000),
         @SQLString VarChar(8000)

Set @Where = ''
set  @SQLString= '
Select Planilla = Prestamos_Cobranza_Comercio.Id, 
Fecha_Validacion = Case When Fecha_Validacion is Null then ''NO'' else convert(char, Fecha_Validacion, 103) End, 
Fecha_Validacion_II = Case When Fecha_Validacion_II is Null then ''NO'' else convert(char, Fecha_Validacion_II, 103) End, 
Fecha_Aplicacion  = Case When Fecha_Aplicacion is Null then ''NO'' else convert(char, Fecha_Aplicacion, 103) End, 
ProveedorFinanciero=Razon_Social, 
Liquidada = ConRecibo, 
Fecha_Pago, 
Nro_Documento, 
Id_Cliente,
Clientes.Nombre, 
Importe
From Prestamos_Cobranza_Comercio
Inner Join Prestamos_Cobranza_Comercio_Detalles on Prestamos_Cobranza_Comercio_Detalles.Id_Cobranza_Comercio = Prestamos_Cobranza_Comercio.Id
Inner Join Clientes on Clientes.Id = Prestamos_Cobranza_Comercio_Detalles.Id_Cliente'

if @Id <> 0
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Id = ' + RTrim(Convert(Char,@Id))
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Id = ' + RTrim(Convert(Char,@Id))

If @Aplicada = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Aplicacion is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Aplicacion is not null  ' 

If @Aplicada = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Aplicacion is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Aplicacion is null  ' 

If @Transferida = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion is not null  ' 

If @Transferida = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion is null  ' 

If @CobranzaAplicada = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion_II is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion_II is not null  ' 

If @CobranzaAplicada = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Validacion_II is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Validacion_II is null  ' 

If @Liquidadas = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.ConRecibo  = ''Si''  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.ConRecibo = ''Si'' ' 

If @Liquidadas = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.ConRecibo = ''No''  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.ConRecibo  = ''No''  ' 

If @Cerrada = 'Si'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Cierre is not null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Cierre is not null  ' 

If @Cerrada = 'No'
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.Fecha_Cierre is null  ' 
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.Fecha_Cierre is null  ' 

if @Comercio <> 0
        If @Where <> ''
                Set @Where = @Where + ' And Prestamos_Cobranza_Comercio.id_entidad = ' + RTrim(Convert(Char,@Comercio))
        Else
                Set @Where = @Where + ' Prestamos_Cobranza_Comercio.id_entidad = ' + RTrim(Convert(Char,@Comercio))

If @Where <> '' 
        Set @SQLString = @SQLString + ' Where ' +  @Where
Else 
        Set @SQLString = @SQLString 
Exec(@SQLString) 
Print @SQLString

Deudas por Oficial (Factoring)

  • SP/archivo: Listado_DeudasXOficial.proc.sql
  • Tipo: Reporte
  • Parámetros: @Cliente_Desde, @Cliente_Hasta, @Filtro (0=todos, 1=positivos, 2=negativos), @Monto_Desde, @Monto_Hasta
  • Relación con módulos: Clientes_CtaCte, Clientes, Oficiales

Saldo de cuenta corriente por cliente agrupado por oficial, calculado como SUM(Ingreso - Egreso) sobre la especie 1 (pesos). @Filtro segmenta entre saldos positivos, negativos o todos los distintos de cero. (Los parámetros @Monto_Desde/@Monto_Hasta están declarados pero no se aplican en el cuerpo.)

CREATE   PROCEDURE [dbo].[Listado_DeudasXOficial]       
    @Cliente_Desde int = 1,
    @Cliente_Hasta int = 713,
    @Filtro int = 0,
    @Monto_Desde decimal=-9999999,
    @Monto_Hasta Decimal=999999999 
AS

IF @Filtro = 1 -- POSITIVOS
    SELECT 
        Id_Cliente = C.Id, 
        Nombre_Cliente = C.Nombre,
        Id_Oficial = C.Oficial,
        Oficial = O.Nombre,
        Importe_Ctacte = SUM(CC.Ingreso-CC.Egreso),
        Cuit = C.Cuit
    FROM Clientes_CtaCte CC
    INNER JOIN Clientes C ON C.ID = CC.Id_Cliente
    INNER JOIN Oficiales O on O.id = C.Oficial
    WHERE C.Eliminado = 0 
        AND C.id BETWEEN @Cliente_Desde AND @Cliente_Hasta 
        AND CC.Id_Especie = 1
    GROUP BY C.id, C.nombre, C.oficial, O.Nombre,C.cuit
    HAVING SUM(CC.Ingreso-CC.Egreso) > 0

ELSE IF @Filtro = 2 -- NEGATIVOS

    SELECT 
        Id_Cliente = C.Id, 
        Nombre_Cliente = C.Nombre,
        Id_Oficial = C.Oficial,
        Oficial = O.Nombre,
        Importe_Ctacte = SUM(CC.Ingreso-CC.Egreso),
        Cuit = C.Cuit
    FROM Clientes_CtaCte CC
    INNER JOIN Clientes C ON C.ID = CC.Id_Cliente
    INNER JOIN Oficiales O on O.id = C.Oficial
    WHERE C.Eliminado = 0 
        AND C.id BETWEEN @Cliente_Desde AND @Cliente_Hasta 
        AND CC.Id_Especie = 1
    GROUP BY C.id, C.nombre, C.oficial, O.Nombre,C.cuit
    HAVING SUM(CC.Ingreso-CC.Egreso) < 0

ELSE -- TODOS
    SELECT 
        Id_Cliente = C.Id, 
        Nombre_Cliente = C.Nombre,
        Id_Oficial = C.Oficial,
        Oficial = O.Nombre,
        Importe_Ctacte = SUM(CC.Ingreso-CC.Egreso),
        Cuit = C.Cuit
    FROM Clientes_CtaCte CC
    INNER JOIN Clientes C ON C.ID = CC.Id_Cliente
    INNER JOIN Oficiales O on O.id = C.Oficial
    WHERE C.Eliminado = 0 
        AND C.id BETWEEN @Cliente_Desde AND @Cliente_Hasta 
        AND CC.Id_Especie = 1
    GROUP BY C.id, C.nombre, C.oficial, O.Nombre,C.cuit
    HAVING SUM(CC.Ingreso-CC.Egreso) <> 0

Listado de Operaciones de Inversiones (Factoring)

  • SP/archivo: Listado_Inversiones_Operaciones.proc.sql
  • Tipo: Reporte
  • Parámetros: @IntCliente_Desde, @IntCliente_Hasta, @IntEspecie_Desde, @IntEspecie_Hasta, @IntTipoOperacion, @dt_FechaDesde, @dt_FechaHasta, @dt_Fecha_Vto_Desde, @dt_Fecha_Vto_Hasta, @dt_Fecha_Conf_Desde, @dt_Fecha_Conf_Hasta, @dt_Fecha_Liq_Desde, @dt_Fecha_Liq_Hasta, @dlb_MontoDesde, @dlb_MontoHasta, @StrOrder
  • Relación con módulos: Inversiones_Operaciones, Clientes, Especies, Inversiones_TipoOperaciones

Listado de operaciones de inversión filtrable por cliente, especie, tipo de operación, montos y múltiples rangos de fechas (operación, vencimiento, confirmación, liquidación). Para tipo de operación 2 (toma/coloca) invierte el signo de importe, interés y monto. SP generado automáticamente (encabezado XML). Nota: en el código fuente hay líneas de If concatenadas sin salto que pueden no compilar limpio; se transcribe tal cual está en el repo.

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


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

CREATE PROCEDURE  [dbo].[Listado_Inversiones_Operaciones] 
                            @IntCliente_Desde  Int = 1,
                            @IntCliente_Hasta  Int = 99999999, 
                            @IntEspecie_Desde Int = 1,
                            @IntEspecie_Hasta  Int = 99999999, 
                            @IntTipoOperacion Int = 0,
                            @dt_FechaDesde  Datetime='01/01/1900',
                            @dt_FechaHasta  Datetime='01/01/3000',
                            @dt_Fecha_Vto_Desde Datetime='01/01/1900',
                            @dt_Fecha_Vto_Hasta  Datetime='01/01/3000',
                            @dt_Fecha_Conf_Desde  Datetime='01/01/1900',
                            @dt_Fecha_Conf_Hasta  Datetime='01/01/3000',
                            @dt_Fecha_Liq_Desde  Datetime='01/01/1900',
                            @dt_Fecha_Liq_Hasta  Datetime='01/01/3000',
                            @dlb_MontoDesde decimal=0,
                            @dlb_MontoHasta decimal=99999999,
                            @StrOrder Varchar(100)='Clientes.Nombre'
 AS

Declare @SQLString VarChar(8000) , @SQLSumarizado VarChar(100)



Set @SQLString = 'Select  Inversiones_Operaciones.id,
    Inversiones_Operaciones.Id_Sucursal , 
    Inversiones_Operaciones.id_Cliente,
    Inversiones_Operaciones.id_Oficial,
    Inversiones_Operaciones.id_Especie,
    Inversiones_Operaciones.Fecha_Operacion,
    Inversiones_Operaciones.Fecha_Confirmacion,
    Inversiones_Operaciones.Fecha_Vencimiento,
    Inversiones_Operaciones.Fecha_Liquidacion,
    NroComprobante, 
    importe =Case when id_TipoOperacion = 2 Then importe *(-1) Else importe End,
    Inversiones_Operaciones.Tasa,
    Inversiones_Operaciones.Plazo,
    interes =Case when id_TipoOperacion = 2 Then interes *(-1) Else interes End,
    Monto = Case when id_TipoOperacion = 2 Then Monto *(-1) Else Monto End,
    Inversiones_Operaciones.observaciones,
    Cliente_Nombre= Clientes.Nombre,
    Especie_Nombre= Especies.Descripcion
    ,Inversiones_TipoOperaciones.Sigla TipoOperacion_Sigla
From Inversiones_Operaciones
Inner Join Clientes On Clientes.id  = Inversiones_Operaciones.id_Cliente
Inner Join Especies On Especies.id = Inversiones_Operaciones.id_Especie
Inner Join Inversiones_TipoOperaciones On Inversiones_TipoOperaciones.id = Inversiones_Operaciones.id_TipoOperacion
Where Inversiones_Operaciones.id_Cliente   Between '+Convert(varchar,@IntCliente_Desde) +'  And  '+Convert(varchar,@IntCliente_Hasta) +'  And
      Inversiones_Operaciones.Fecha_Operacion      Between '''+ Convert(varchar,@dt_FechaDesde,103)  +'''  And '''+ Convert(varchar,@dt_FechaHasta,103)+'''  And 
      Inversiones_Operaciones.Fecha_Vencimiento   Between '''+ Convert(varchar,@dt_Fecha_Vto_Desde,103)  +'''  And '''+ Convert(varchar,@dt_Fecha_Vto_Hasta,103)+'''  And 
      Inversiones_Operaciones.Id_Especie      Between  '+ Convert(varchar,@IntEspecie_Desde) +'  And '+Convert(varchar,@IntEspecie_Hasta)  +' And
      Inversiones_Operaciones.Monto      Between  '+ Convert(varchar,@dlb_MontoDesde) +'  And '+Convert(varchar,@dlb_MontoHasta)  + ' And  
      Inversiones_Operaciones.Fecha_Anulacion is Null '

If @dt_Fecha_Conf_Desde <> '01/01/1900' And @dt_Fecha_Conf_Hasta <> '01/01/1900'
        If @SQLString <> ''
                Set @SQLString = @SQLString + ' And Inversiones_Operaciones.Fecha_Confirmacion Between ''' + RTrim(Convert(Char,@dt_Fecha_Conf_Desde,103)) + ''' And ''' + RTrim(Convert(Char,@dt_Fecha_Conf_Hasta,103)) + ''''If @dt_Fecha_Liq_Desde <> '01/01/1900' And @dt_Fecha_Liq_Hasta <> '01/01/1900'
        If @SQLString <> ''
                Set @SQLString = @SQLString + ' And Inversiones_Operaciones.Fecha_PagoCobro Between ''' + RTrim(Convert(Char,@dt_Fecha_Liq_Desde,103)) + ''' And ''' + RTrim(Convert(Char,@dt_Fecha_Liq_Hasta,103)) + ''''If @IntTipoOperacion=1 
    Set @SQLString = @SQLString +'  And Inversiones_TipoOperaciones.TomoColoco=1'
Else
    If @IntTipoOperacion=2
    Set @SQLString = @SQLString +'  And Inversiones_TipoOperaciones.TomoColoco=2'


If @StrOrder <>''
    Set @SQLString = @SQLString + 'Order by '+ @StrOrder

Exec(@SQLString) 
Print @SQLString

Listado de Líneas por Cliente (Factoring / Préstamos)

  • SP/archivo: Listado_de_Lineas_por_Cliente.proc.sql
  • Tipo: Reporte
  • Parámetros: @FechaOtorgamientoDesde, @FechaOtorgamientoHasta
  • Relación con módulos: Prestamos_Solicitudes, Prestamos_Lineas, Prestamos_Entidades, Prestamos_Creditos

Lista las solicitudes de préstamo otorgadas (con Fecha_Otorgado no nula y sin anulación) dentro del rango de fechas, mostrando línea, entidad, nombre del solicitante y monto. Ordenado por línea y entidad.

CREATE Procedure [dbo].[Listado_de_Lineas_por_Cliente]
                                                        @FechaOtorgamientoDesde     DateTime = '',
                                                        @FechaOtorgamientoHasta     DateTime = ''

As

Select
Id_Solicitud = Prestamos_Solicitudes.Id, 
Linea        = Prestamos_Lineas.Descripcion,
Entidad      = Prestamos_Entidades.Nombre, 
Nombre       = Prestamos_Solicitudes.Apellido + ', ' + Prestamos_Solicitudes.Nombre, 
Monto        = Importe
From Prestamos_Solicitudes
Inner Join Prestamos_Lineas on Prestamos_Lineas.Id = Prestamos_Solicitudes.Id_Linea
Inner Join Prestamos_Entidades on Prestamos_Entidades.Id = Prestamos_Solicitudes.Id_Entidad
Inner Join Prestamos_creditos on Prestamos_Creditos.Id_Solicitud = Prestamos_Solicitudes.Id 
Where Fecha_Otorgado is not null and Fecha_Anulacion is Null
And Fecha_Otorgado Between @FechaOtorgamientoDesde And @FechaOtorgamientoHasta
Order By Prestamos_Lineas.Descripcion,Prestamos_Entidades.Nombre

Listado Soporte Banco Patagonia — Ventas (Factoring)

  • SP/archivo: Ventas_ListadoSoporte_BancoPatagonia.sql
  • Tipo: Reporte (exportación / archivo de soporte)
  • Parámetros: @Id_Venta
  • Relación con módulos: Ventas_Detalle, Documentos, Firmantes, Clientes, Bancos, Parametros

Genera el detalle de cheques de una venta para el soporte/archivo del Banco Patagonia, con campos zero-padded (nro de comprobante, banco, cuenta, sucursal) y CUITs sin guiones. El CUIT de la empresa se toma del parámetro Empresa.CUIT.

CREATE PROCEDURE Ventas_ListadoSoporte_BancoPatagonia 
    @Id_Venta Integer = 12

As

    Select 
        CUIT_Empresa = Replace((Select valor From Parametros Where Parametro = 'Empresa.CUIT'),'-',''),
        Nro_Comprobante = Right('000000000' + convert(varchar(8),Documentos.Nro_Comprobante),9),
        Id_Banco = Right('000' + Convert(Varchar(3),Documentos.Id_Banco),3),
        Cuenta = Right('00000000000' + Convert(Varchar(11),Documentos.Nro_Cta),11),
        Sucursal = Right('000' + Convert(Varchar(3),Documentos.Sucursal),3),
        Bruto = Documentos.Bruto,
        F_Deposito = Convert(Varchar(10),Documentos.Fecha_Deposito,103),
        CUIT_Cliente = Replace(Clientes.cuit,'-',''),
        CUIT_Firmante = Replace(Firmantes.cuit,'-',''),
        Cliente = Clientes.nombre,
        Firmante = Firmantes.nombre,
        Id_Cliente = Clientes.Id,
        Id_Firmante = Firmantes.id,
        Id_Documento = Documentos.Id,
        Banco_Nombre = Bancos.nombre

    From Ventas_detalle  
    Inner Join Documentos on Ventas_detalle.Id_documento = documentos.id  
    Inner Join Firmantes on Firmantes.id = Documentos.Id_Firmante  
    Inner Join Clientes on Documentos.Id_Cliente=Clientes.id  
    Inner Join Bancos on Bancos.id = Documentos.Id_Banco
    where Ventas_Detalle.Id_Venta = @Id_Venta 

Listado de Netos Contables de Inversores (Inversiones)

  • SP/archivo: Inversores_Listado_NetosContables.proc.sql (carpeta Inversiones\)
  • Tipo: Reporte
  • Parámetros: @Id_Inversor_Desde, @Id_Inversor_Hasta
  • Relación con módulos: Inversores, Inversores_CtaCte, Documentos, Ventas / Ventas_Detalle, Entregas / Entregas_Detalle, Parametros

Calcula el neto contable por inversor a la fecha de trabajo (parámetro FechaDeTrabajo): saldo de cuenta corriente en especie 1 más el resultado de ventas y entregas de cheques acreditados desde esa fecha. Usa tabla temporal #tmp y solo devuelve inversores con neto distinto de cero.


CREATE PROCEDURE [dbo].[Inversores_Listado_NetosContables]      
@Id_Inversor_Desde int=0,
@Id_Inversor_Hasta int=30
AS
declare @fecha as datetime

set @fecha = (Select Valor from parametros where Parametro = 'FechaDeTrabajo')
Select Inversores.Id,
       Inversores.Nombre,
       Inversores.Cuit,
       NetoContable  = IsNull((Select sum(ingreso-Egreso) from Inversores_ctacte where id_inversor =Inversores.Id and id_especie = 1),0)
                            +
                            IsNull((Select -Sum(neto)+ sum(bruto) 
                            From Documentos 
                            Inner Join Ventas_Detalle On Ventas_Detalle.Id_Documento = Documentos.Id
                            Inner Join Ventas On Ventas.Id = Ventas_Detalle.Id_Venta
                            Where Documentos.Fecha_Acreditacion is not null  And   
                            Documentos.Fecha_Acreditacion >= @Fecha and
                            Ventas.Id_Inversor = Inversores.Id and ventas.Fecha_Confirmacion is not null),0)
                            +IsNull((Select -Sum(neto) + sum(bruto)
                            From Documentos 
                            Inner Join Entregas_Detalle On Entregas_Detalle.Id_Documento = Documentos.Id
                            Inner Join Entregas On Entregas.Id = Entregas_Detalle.Id_Entrega
                            Where Entregas.Id_Inversor = Inversores.Id and entregas.Fecha_Confirmacion Is Not Null
                            and documentos.cancelado = 0 and Documentos.Fecha_Acreditacion >= @Fecha),0)
Into #tmp
From Inversores
Where id between @Id_Inversor_Desde and @Id_Inversor_Hasta

Select * From #tmp Where NetoContable <> 0
Drop Table #tmp
¿Te resultó útil este manual?