dbo.backend_juicios_errores

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

4
Name Data Type Length Description
@accion varchar 20
@fecha date 3
@tipo_novedad varchar 200
@id_tipo_causa varchar 10

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

--select * from juicios_errores_BT where procesado = 1
--select * from juicios where created >= '2024-05-29 12:35'
-- =============================================
CREATE OR ALTER PROCEDURE dbo.backend_juicios_errores 
 @accion varchar(20),
 @fecha date = null,
 @tipo_novedad varchar(200) = null, 
 @id_tipo_causa varchar(10) = null

AS
BEGIN

 SET NOCOUNT ON;
 declare @id_juicio int = NULL,
   @tipo_de_novedad varchar(500) = NULL,
   @fecha_causa date = NULL,
   @expediente varchar(50) = NULL,
   @actor varchar(500) = NULL,
   @demandado varchar(500) = NULL,
   @juzgado varchar(50) = NULL,
   @secretaria varchar(50) = NULL,
   @autos_caratula varchar(500) = NULL,
   @fuente varchar(100) = NULL,
   @fecha_fuente date = NULL,
   @created datetime = NULL,
   @procesado bit = null 

 if (@fecha is null) set @fecha = GETDATE()
 
 if (@accion = 'cantidad_errores')
 begin
  select COUNT(*) from juicios_errores_BT where fecha_fuente = @fecha and procesado = 0
 end

 if (@accion = 'novedades_error')
 begin
  select distinct tipo_de_novedad from juicios_errores_BT where fecha_fuente = @fecha and procesado = 0
 end

 if (@accion = 'tipos_causas')
 begin
  select id_tipo_causa, nombre_causa from tipos_causas order by nombre_causa
 end

 if (@accion = 'asigna_tipos_causas')
 begin
  if not exists (select * from tarea_juicios where tipo_de_novedad_vieja = @tipo_de_novedad) 
  begin
   insert into tarea_juicios (tipo_de_novedad_vieja,id_tipo_novedad,terminada)
   values (@tipo_novedad,@id_tipo_causa,1)
  end
 end

 if (@accion = 'procesar')
 begin

  DECLARE C_cursor CURSOR FOR

   select  id_juicio, 
     tipo_de_novedad,
     fecha_causa,
     expediente,
     actor,
     demandado,
     juzgado,
     secretaria,
     autos_caratula,
     fuente, 
     fecha_fuente
   FROM juicios_errores_BT
   WHERE procesado = 0 and fecha_fuente = @fecha

  OPEN C_cursor
  FETCH NEXT FROM C_cursor INTO   @id_juicio,
          @tipo_de_novedad,
          @fecha_causa,
          @expediente,
          @actor,
          @demandado,
          @juzgado,
          @secretaria,
          @autos_caratula,
          @fuente,
          @fecha_fuente
      
  WHILE @@fetch_status = 0
  BEGIN 
    DECLARE @anio int = datepart(YYYY,@fecha_causa)
    if exists (select * from tarea_juicios where tipo_de_novedad_vieja = @tipo_de_novedad) 
    begin
     exec [backend_juicios_insertar] 
        @expediente,
        NULL,
        @anio,
        @actor,
        NULL,
        @demandado,
        NULL,
        NULL,
        NULL,
        NULL,
        @autos_caratula,
        @tipo_de_novedad,
        NULL,
        NULL,
        @fuente,
        @juzgado,
        @secretaria,
        @fecha_causa,
        @fecha_fuente
     update juicios_errores_BT set procesado = 1 where id_juicio = @id_juicio
    end
    FETCH NEXT FROM C_cursor INTO   @id_juicio,
       @tipo_de_novedad,
       @fecha_causa,
       @expediente,
       @actor,
       @demandado,
       @juzgado,
       @secretaria,
       @autos_caratula,
       @fuente,
       @fecha_fuente
  END
  CLOSE C_cursor
  DEALLOCATE C_cursor
 end
  
END

GO

Used By

No items found