dbo.LN_contraparte_dossier

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

3
Name Data Type Length Description
@accion varchar 30
@p_contraparte int 4
@p_user_id int 4

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_contraparte_dossier 
 -- Add the parameters for the stored procedure here
 @accion           varchar(30),
 @p_contraparte         int,
 @p_user_id          int
 
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here

 if (@p_contraparte is not null) begin

  if (@accion = 'consultar')

   select LN_contrapartes.contraparte, LN_contrapartes.cliente, LN_contrapartes.id_padron,
     padrones.identificador, padrones.nombre_persona, padrones.identificacion, identificadores.abreviatura,
     padrones.numero, identificadores.country_code, country.country_name, clientes.nombre_cliente,

   ISNULL(LN_contrapartes.solicitud_dossier, 0) AS solicitud_dossier, 
   CONVERT(VARCHAR, LN_contrapartes.fecha_solicitud, 103) AS fecha_solicitud,
   LN_contrapartes.solicitado_por, LN_contrapartes.estado_solicitud, 
   CONVERT(VARCHAR, LN_contrapartes.fecha_cancelacion, 103) AS fecha_cancelacion, 
   LN_contrapartes.cancelado_por,
   users.first_name + ' ' + users.last_name as solicitado_por_usuario,
   users2.first_name + ' ' + users2.last_name as cancelado_por_usuario

   from LN_contrapartes 
   inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
   inner join identificadores on padrones.identificador = identificadores.identificador
   inner join country on identificadores.country_code = country.country_code
   inner join clientes on LN_contrapartes.cliente = clientes.cliente
   left outer join users on LN_contrapartes.solicitado_por = users.user_id
   left outer join users users2 on LN_contrapartes.cancelado_por = users2.user_id

   where LN_contrapartes.contraparte = @p_contraparte

  else

   if (@accion = 'solicitar') begin

    if exists (select contraparte
       from LN_contrapartes
       where contraparte = @p_contraparte
       and ISNULL(solicitud_dossier, 0) = 0)

     UPDATE LN_contrapartes SET
      solicitud_dossier = 1,
      estado_solicitud = 'S',
      fecha_solicitud = getdate(),
      solicitado_por = @p_user_id
     WHERE contraparte = @p_contraparte

   end else

    if (@accion = 'cancelar') begin

     if exists (select contraparte
        from LN_contrapartes
        where contraparte = @p_contraparte
        and solicitud_dossier = 1
        and estado_solicitud = 'S')

      UPDATE LN_contrapartes SET
       solicitud_dossier = 0,
       estado_solicitud = 'C',
       fecha_cancelacion = getdate(),
       cancelado_por = @p_user_id
      WHERE contraparte = @p_contraparte

    end else

     if (@accion = 'iniciar') begin

      if exists (select contraparte
         from LN_contrapartes
         where contraparte = @p_contraparte
         and solicitud_dossier = 1
         and estado_solicitud = 'S')

       UPDATE LN_contrapartes SET
        estado_solicitud = 'E'
       WHERE contraparte = @p_contraparte

     end else

      if (@accion = 'finalizar') begin

       if exists (select contraparte
          from LN_contrapartes
          where contraparte = @p_contraparte
          and solicitud_dossier = 1
          and estado_solicitud = 'E')

        UPDATE LN_contrapartes SET
         estado_solicitud = 'F'
        WHERE contraparte = @p_contraparte

      end

    


 end
 
END
GO

Used By

No items found