dbo.Imperium_desafectados

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

7
Name Data Type Length Description
@accion varchar 20
@seccion char 1
@p_recurso int 4
@contratista int 4
@contratista_1 int 4
@p_periodo int 4
@p_user_id int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: Maria Ines Soria
-- Create date: 29/05/2020
-- Description:
-- search:     Busca si el recurso esta desafectado
-- desafectar: Desafectado el recurso en ese periodo. Elimina el registro de la tabla de periodos
-- afectar:    Agrega el registro de la tabla de periodos

-- =============================================
CREATE OR ALTER PROCEDURE dbo.Imperium_desafectados
 @accion    varchar(20),
 @seccion   char(1), 
 @p_recurso int, 
 @contratista int, 
 @contratista_1 int, 
 @p_periodo int, 
 @p_user_id int = null 
AS
BEGIN
 SET NOCOUNT ON;
 declare @cliente int 
 declare @contraparte int 
 declare @nombre varchar(200) 
 declare @nombre_sub varchar(200) 
 declare @txt varchar(max) 

 select @contraparte = contraparte from ln_contrapartes 
 where id_imperium = @contratista_1

 select @nombre_sub = nombre_persona 
  from led_contratistas 
  inner join padrones on padrones.id_padron = led_contratistas.id_padron 
  where contratista = @contratista

 IF (@seccion = 'E')
 begin

  select @cliente = cliente, @nombre = nombre_persona 
   from led_empleados 
   inner join padrones on padrones.id_padron = led_empleados.id_padron 
   where empleado = @p_recurso

  if (@accion = 'search')
  begin 
  if (select count(*) 
     from led_empleados_periodo 
    where empleado = @p_recurso and periodo = @p_periodo) = 0 
    select 'S' as desafectado -- Desafectado
    else 
    select 'N' as desafectado -- No Desafectado
  end 

  if (@accion = 'desafectar')
  begin 
   delete
     from led_empleados_periodo 
    where empleado = @p_recurso and periodo = @p_periodo

    set @txt = 'Se ha desafectado al empleado ' + @nombre
    if (@contratista != @contratista) 
    set @txt = @txt + ' del subcontratista ' + @nombre_sub
    set @txt = @txt + ' del período ' + 
     SUBSTRING(convert(varchar,@p_periodo), 5, 2) + '/' + SUBSTRING(convert(varchar,@p_periodo), 1,4)
    exec insertar_trazabilidad  @txt, @cliente, 'DESAFECTAR_EMPLEADO_IMPETRIUM', 'IMPE', @contraparte, @p_user_id, null, '73'

   select 'ok'
  end
  
  if (@accion = 'afectar')
  begin 
   insert into
      led_empleados_periodo(empleado, contratista, contratista_1, periodo, fecha_afectacion)
    values (@p_recurso, @contratista, @contratista_1, @p_periodo, getdate()) 

   set @txt = 'Se ha afectado al empleado ' + @nombre
    if (@contratista != @contratista) 
    set @txt = @txt + ' del subcontratista ' + @nombre_sub
    set @txt = @txt + ' del período ' + 
     SUBSTRING(convert(varchar,@p_periodo), 5, 2) + '/' + SUBSTRING(convert(varchar,@p_periodo), 1,4)
    exec insertar_trazabilidad  @txt, @cliente, 'AFECTAR_EMPLEADO_IMPETRIUM', 'IMPE', @contraparte, @p_user_id, null, '73'

   select 'ok'
  end
 end 

 IF (@seccion = 'V')
 begin

  select @cliente = cliente, @nombre = dominio 
   from led_vehiculos  
   where vehiculo = @p_recurso

  if (@accion = 'search')
  begin 
  if (select count(*) 
     from led_vehiculos_periodo 
    where vehiculo = @p_recurso and periodo = @p_periodo) = 0 
    select 'S' as desafectado -- Desafectado
    else 
    select 'N' as desafectado -- No Desafectado
  end 
  
  if (@accion = 'desafectar')
  begin 
   delete
     from led_vehiculos_periodo 
    where vehiculo = @p_recurso and periodo = @p_periodo

    set @txt = 'Se ha desafectado al vehiculo con dominio ' + @nombre
    if (@contratista != @contratista) 
    set @txt = @txt + ' del subcontratista ' + @nombre_sub
    set @txt = @txt + ' del período ' + 
     SUBSTRING(convert(varchar,@p_periodo), 5, 2) + '/' + SUBSTRING(convert(varchar,@p_periodo), 1,4)
    exec insertar_trazabilidad  @txt, @cliente, 'DESAFECTAR_VEHICULO_IMPETRIUM', 'IMPE', @contraparte, @p_user_id, null, '73'



   select 'ok'
  end
  
  if (@accion = 'afectar')
  begin 
   insert into
      led_vehiculos_periodo(vehiculo, contratista, contratista_1, periodo, fecha_afectacion)
    values (@p_recurso, @contratista, @contratista_1, @p_periodo, getdate()) 

   set @txt = 'Se ha afectado al vehiculo con dominio ' + @nombre
    if (@contratista != @contratista) 
    set @txt = @txt + ' del subcontratista ' + @nombre_sub
    set @txt = @txt + ' del período ' + 
     SUBSTRING(convert(varchar,@p_periodo), 5, 2) + '/' + SUBSTRING(convert(varchar,@p_periodo), 1,4)
    exec insertar_trazabilidad  @txt, @cliente, 'AFECTAR_VEHICULO_IMPETRIUM', 'IMPE', @contraparte, @p_user_id, null, '73'


   select 'ok'
  end
 end 

 IF (@seccion = 'S')
 begin
  if (@accion = 'search')
  begin 
  if (select count(*) 
     from led_subcontratista_periodo 
    where subcontratista = @p_recurso and periodo = @p_periodo) = 0 
    select 'S' as desafectado -- Desafectado
    else 
    select 'N' as desafectado -- No Desafectado
  end 
  
  if (@accion = 'desafectar')
  begin 
   delete
     from led_subcontratista_periodo 
    where subcontratista = @p_recurso and periodo = @p_periodo
   select 'ok'
  end
  
  if (@accion = 'afectar')
  begin 
   insert into
      led_subcontratista_periodo(subcontratista, contratista, contratista_1, periodo, fecha_afectacion)
    values (@p_recurso, @contratista, @contratista_1, @p_periodo, getdate()) 
   select 'ok'
  end
 end 
END
GO

Used By

No items found