dbo.monitoreos_cheques_99

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
--Store para el monitoreo de cheques en proceso batch, para saber si tiene alguna actualizacion
--exec monitoreos_cheques
CREATE OR ALTER PROCEDURE dbo.monitoreos_cheques_99

AS
BEGIN
    SET NOCOUNT ON;

 declare @r_cuit varchar(20),@r_nro_cheque varchar(20)
DECLARE bn CURSOR

FOR

 select distinct cuit, nro_cheque from monitoreos 
  where visible = 1 
    and seccion_mantenimiento = 99 
    and (fecha_vigencia_mantenimiento is null or convert(date, fecha_vigencia_mantenimiento) >= convert(date,getdate()))
-- apertura del cursor

OPEN bn 
 
-- Lectura de la primera fila del cursor
Fetch next from bn INTO @r_cuit, @r_nro_cheque

WHILE (@@FETCH_STATUS <> -1 )
 
BEGIN

        declare @yesterday date = getdate() - 1
 
  set @r_nro_cheque = RTRIM(ltrim(@r_nro_cheque))

  if (@r_nro_cheque = '') 
  begin 
      set @r_nro_cheque = null 
  end 
 
  --Inicio otro cursor para poder pegar por ID.
  declare @r_id_cheque int
  DECLARE chc CURSOR
  FOR
   /*
    select distinct(id_cheque)
          from ChequesBCRA 
      where cuit_firmante = @r_cuit 
           and ((convert(date,created) = @yesterday and created is not null) or (modified = @yesterday and modified is not null))
           and (nro_cheque = @r_nro_cheque or @r_nro_cheque is null)
       and visible = 1
       */


      -- Si hay un cheque exactamente igual como no visible, es porque no se modifico el cheque.
      select distinct (id_cheque)         
       from ChequesBCRA a
       where cuit_firmante = @r_cuit 
            and ((convert(date,created) = @yesterday and created is not null) or (modified = @yesterday and modified is not null))
            and (nro_cheque = @r_nro_cheque or @r_nro_cheque is null)
         and visible = 1
      and not exists 
      (select * from ChequesBCRA b
        where ISNULL(b.cuit_firmante,'')     = ISNULL(a.cuit_firmante,'')
       and ISNULL(b.cuit_relacionado, '') = ISNULL(a.cuit_relacionado, '') 
       and ISNULL(b.nro_cheque,0)         = ISNULL(a.nro_cheque,0)
       and ISNULL(b.importe, 0)           = ISNULL(a.importe, 0)
       and ISNULL(b.fecha_rechazo,'1901-01-01')       = ISNULL(a.fecha_rechazo,'1901-01-01')  
       and ISNULL(b.fecha_pago,'1901-01-01')          = ISNULL(a.fecha_pago,'1901-01-01')  
       and ISNULL(b.fecha_levantamiento,'1901-01-01') = ISNULL(a.fecha_levantamiento,'1901-01-01')  
       and visible = 0)
      
  -- apertura del cursor

  OPEN chc
 
  FETCH next from chc INTO @r_id_cheque

  WHILE (@@FETCH_STATUS <> -1 )
   BEGIN

   insert into monitoreos_resultados 
              (nro_cheque,    id_tabla,     tabla,       cuit,    seccion_mantenimiento, fecha,     novedad, tipo_novedad)
        values(@r_nro_cheque, @r_id_cheque, 'Cheques99', @r_cuit, 99,                    @yesterday, 1,       'Cheques');
   update monitoreos 
      set fecha_ultimo_procesamiento = getdate(),
          fecha_modificacion=getdate()
       where cuit = @r_cuit and (nro_cheque = @r_nro_cheque or @r_nro_cheque is null)

    FETCH next from chc INTO @r_id_cheque

  end
  CLOSE chc
  DEALLOCATE chc

  FETCH next from bn INTO @r_cuit, @r_nro_cheque

END

-- Cierra el cursor
CLOSE bn
-- Libera los recursos del cursor
DEALLOCATE bn 

END

GO

Used By

No items found