dbo.LN_doc_actualizar_directorio

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

24
Name Data Type Length Description
@contraparte int 4
@doc_id int 4
@fecha_acta varchar 10
@ultimo_dir tinyint 1
@nombre_1 varchar 60
@ident_1 varchar 20
@numero_1 varchar 40
@cargo_1 varchar 20
@nombre_2 varchar 60
@ident_2 varchar 20
@numero_2 varchar 40
@cargo_2 varchar 20
@nombre_3 varchar 60
@ident_3 varchar 20
@numero_3 varchar 40
@cargo_3 varchar 20
@nombre_4 varchar 60
@ident_4 varchar 20
@numero_4 varchar 40
@cargo_4 varchar 20
@nombre_5 varchar 60
@ident_5 varchar 20
@numero_5 varchar 40
@cargo_5 varchar 20

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_doc_actualizar_directorio 
 -- Add the parameters for the stored procedure here

 @contraparte           int = NULL,
 @doc_id             int = NULL,
 @fecha_acta            varchar(10) = NULL,
 @ultimo_dir            tinyint = 1,
 @nombre_1            varchar(60) = NULL,
 @ident_1            varchar(20) = NULL,
 @numero_1            varchar(40) = NULL,
 @cargo_1            varchar(20) = NULL,
 @nombre_2            varchar(60) = NULL,
 @ident_2            varchar(20) = NULL,
 @numero_2            varchar(40) = NULL,
 @cargo_2            varchar(20) = NULL,
 @nombre_3            varchar(60) = NULL,
 @ident_3            varchar(20) = NULL,
 @numero_3            varchar(40) = NULL,
 @cargo_3            varchar(20) = NULL,
 @nombre_4            varchar(60) = NULL,
 @ident_4            varchar(20) = NULL,
 @numero_4            varchar(40) = NULL,
 @cargo_4            varchar(20) = NULL,
 @nombre_5            varchar(60) = NULL,
 @ident_5            varchar(20) = NULL,
 @numero_5            varchar(40) = NULL,
 @cargo_5            varchar(20) = NULL

 
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here
 declare @d1 int = 0
 declare @d2 int = 0
 declare @d3 int = 0
 declare @d4 int = 0
 declare @d5 int = 0

 declare @cuit varchar(30) = NULL

 declare @anio varchar(10) = NULL
 declare @mes varchar(10) = NULL
 declare @periodo_desde varchar(10) = NULL

 if (@contraparte > 0 AND @doc_id > 0) begin

  select @cuit = padrones.identificacion from LN_contrapartes 
            inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
            where LN_contrapartes.contraparte = @contraparte

  if (@nombre_1 is not null AND @numero_1 is not null) begin   
   if not exists (select id_padron
       from padrones
       where identificador = @ident_1
       and numero = @numero_1) begin    
    exec backend_insertar_padron @ident_1, @numero_1, @nombre_1, 'F', 'M', 1
   end

   select @d1 = id_padron from padrones where identificador = @ident_1 and numero = @numero_1
  end


  if (@nombre_2 is not null AND @numero_2 is not null) begin   
   if not exists (select id_padron
       from padrones
       where identificador = @ident_2
       and numero = @numero_2) begin    
    exec backend_insertar_padron @ident_2, @numero_2, @nombre_2, 'F', 'M', 1
   end

   select @d2 = id_padron from padrones where identificador = @ident_2 and numero = @numero_2
  end


  if (@nombre_3 is not null AND @numero_3 is not null) begin   
   if not exists (select id_padron
       from padrones
       where identificador = @ident_3
       and numero = @numero_3) begin    
    exec backend_insertar_padron @ident_3, @numero_3, @nombre_3, 'F', 'M', 1
   end

   select @d3 = id_padron from padrones where identificador = @ident_3 and numero = @numero_3
  end


  if (@nombre_4 is not null AND @numero_4 is not null) begin   
   if not exists (select id_padron
       from padrones
       where identificador = @ident_4
       and numero = @numero_4) begin    
    exec backend_insertar_padron @ident_4, @numero_4, @nombre_4, 'F', 'M', 1
   end

   select @d4 = id_padron from padrones where identificador = @ident_4 and numero = @numero_4
  end


  if (@nombre_5 is not null AND @numero_5 is not null) begin   
   if not exists (select id_padron
       from padrones
       where identificador = @ident_5
       and numero = @numero_5) begin    
    exec backend_insertar_padron @ident_5, @numero_5, @nombre_5, 'F', 'M', 1
   end

   select @d5 = id_padron from padrones where identificador = @ident_5 and numero = @numero_5
  end


  /*********************************************/

  if (@d1 > 0 OR @d2 > 0 OR @d3 > 0 OR @d4 > 0 OR @d5 > 0) begin

   if (@ultimo_dir > 0) 
    update socios set c04_ultimo = 'N' where c01_cuit = @cuit

   if (@fecha_acta is not null) begin
    -- Doy vuelta las fecha para grabar en tabla
    set @anio = SUBSTRING(@fecha_acta, 7,4)
    set @mes = SUBSTRING(@fecha_acta, 4, 2)
    set @periodo_desde = SUBSTRING(@fecha_acta, 7,4) + '-' + SUBSTRING(@fecha_acta, 4, 2)
   end

   if (@d1 > 0)
    insert into socios
    (c01_cuit, c01_cuit_soc, car_codigo, c04_periodo_mes, c04_periodo_ano, c04_ultimo, c04_periodo_desde, created, id_padron, visible)
    values
    (@cuit, @numero_1, @cargo_1, @mes, @anio, iif(@ultimo_dir > 0, 'S', 'N'), @periodo_desde, GETDATE(), @d1, 1)

   if (@d2 > 0)
    insert into socios
    (c01_cuit, c01_cuit_soc, car_codigo, c04_periodo_mes, c04_periodo_ano, c04_ultimo, c04_periodo_desde, created, id_padron, visible)
    values
    (@cuit, @numero_2, @cargo_2, @mes, @anio, iif(@ultimo_dir > 0, 'S', 'N'), @periodo_desde, GETDATE(), @d2, 1)

   if (@d3 > 0)
    insert into socios
    (c01_cuit, c01_cuit_soc, car_codigo, c04_periodo_mes, c04_periodo_ano, c04_ultimo, c04_periodo_desde, created, id_padron, visible)
    values
    (@cuit, @numero_3, @cargo_3, @mes, @anio, iif(@ultimo_dir > 0, 'S', 'N'), @periodo_desde, GETDATE(), @d3, 1)

   if (@d4 > 0)
    insert into socios
    (c01_cuit, c01_cuit_soc, car_codigo, c04_periodo_mes, c04_periodo_ano, c04_ultimo, c04_periodo_desde, created, id_padron, visible)
    values
    (@cuit, @numero_4, @cargo_4, @mes, @anio, iif(@ultimo_dir > 0, 'S', 'N'), @periodo_desde, GETDATE(), @d4, 1)

   if (@d5 > 0)
    insert into socios
    (c01_cuit, c01_cuit_soc, car_codigo, c04_periodo_mes, c04_periodo_ano, c04_ultimo, c04_periodo_desde, created, id_padron, visible)
    values
    (@cuit, @numero_5, @cargo_5, @mes, @anio, iif(@ultimo_dir > 0, 'S', 'N'), @periodo_desde, GETDATE(), @d5, 1)

  end

 end
 
END
GO

Used By

No items found