dbo.LN_producto_tipo_doc_

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

10
Name Data Type Length Description
@action varchar 10
@p_producto int 4
@p_tipo_doc int 4
@p_requiere_upload tinyint 1
@p_requiere_verificacion tinyint 1
@p_verifica_backend tinyint 1
@p_verifica_cliente tinyint 1
@p_tolerancia_carga tinyint 1
@p_activo tinyint 1
@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_producto_tipo_doc_
 -- Add the parameters for the stored procedure here
 @action           varchar(10),
 @p_producto          int,
 @p_tipo_doc          int,
 @p_requiere_upload        tinyint,
 @p_requiere_verificacion      tinyint,
 @p_verifica_backend        tinyint,
 @p_verifica_cliente        tinyint,
 @p_tolerancia_carga        tinyint,
 @p_activo          tinyint,
 @p_user_id          int

 
AS

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

 DECLARE @ord int
 DECLARE @tipo_doc_ant int
 DECLARE @cant int

    -- Insert statements for procedure here
 IF (@action = 'INSERT') BEGIN

  IF NOT EXISTS (SELECT producto, tipo_doc 
      from LN_producto_tipo_doc
      where producto = @p_producto
      AND tipo_doc = @p_tipo_doc) begin


   select @ord = ISNULL(max(orden),0)+1
   from LN_producto_tipo_doc
   where producto = @p_producto   

   INSERT INTO LN_producto_tipo_doc 
   (producto, tipo_doc, requiere_upload, requiere_verificacion, verifica_backend,
   verifica_cliente, tolerancia_carga, activo, orden, created, created_by, modified, modified_by)
   VALUES
   (@p_producto, @p_tipo_doc, @p_requiere_upload, @p_requiere_verificacion, @p_verifica_backend,
   @p_verifica_cliente, @p_tolerancia_carga, @p_activo, @ord, GETDATE(), @p_user_id, NULL, NULL)


  end

 END ELSE

  IF (@action = 'UPDATE') BEGIN

   UPDATE LN_producto_tipo_doc SET
   requiere_upload = @p_requiere_upload, 
   requiere_verificacion = @p_requiere_verificacion, 
   verifica_backend = @p_verifica_backend,
   verifica_cliente = @p_verifica_cliente, 
   tolerancia_carga = @p_tolerancia_carga,
   activo = @p_activo, 
   modified = GETDATE(), 
   modified_by = @p_user_id
   WHERE producto = @p_producto
   AND tipo_doc = @p_tipo_doc
 
  END ELSE

   IF (@action = 'DELETE') BEGIN

    SELECT @ord = orden
    FROM LN_producto_tipo_doc
    WHERE producto = @p_producto
    AND tipo_doc = @p_tipo_doc

    DELETE FROM LN_producto_tipo_doc
    WHERE producto = @p_producto
    AND tipo_doc = @p_tipo_doc

    UPDATE LN_producto_tipo_doc SET orden = orden-1
    where tipo_doc = @p_tipo_doc
    and producto = @p_producto
    and orden > @ord

   END ELSE

    IF (@action = 'SELECT') BEGIN

     SELECT LN_producto_tipo_doc.producto, LN_producto_tipo_doc.tipo_doc,
     LN_producto_tipo_doc.requiere_upload, LN_producto_tipo_doc.requiere_verificacion,
     LN_producto_tipo_doc.verifica_backend, LN_producto_tipo_doc.verifica_cliente,
     LN_producto_tipo_doc.tolerancia_carga, LN_producto_tipo_doc.orden, LN_producto_tipo_doc.ponderacion,
     LN_producto_tipo_doc.activo, LN_producto_tipo_doc.created_by, LN_producto_tipo_doc.modified_by,
     CONVERT(VARCHAR(19), LN_producto_tipo_doc.created, 121) as created,
     CONVERT(VARCHAR(19), LN_producto_tipo_doc.modified, 121) as modified,
     LN_productos.nombre_producto, LN_tipos_doc.nombre_tipo_doc, LN_tipos_doc.modalidad,
     LN_tipos_doc.tipo_vigencia, LN_tipos_doc.dia_vigencia, LN_tipos_doc.mes_vigencia,
     LN_tipos_doc.es_balance, LN_productos.country_code, country.country_name,
     users.first_name + ' ' + users.last_name as created_by_user,
     users2.first_name + ' ' + users2.last_name as modified_by_user
     FROM LN_producto_tipo_doc
     INNER JOIN LN_productos ON LN_producto_tipo_doc.producto = LN_productos.producto
     inner join LN_tipos_doc ON LN_producto_tipo_doc.tipo_doc = LN_tipos_doc.tipo_doc
     inner join country ON LN_productos.country_code = country.country_code
     left outer join users on LN_producto_tipo_doc.created_by = users.user_id
     left outer join users users2 on LN_producto_tipo_doc.modified_by = users2.user_id
     WHERE LN_producto_tipo_doc.producto = @p_producto
     AND LN_producto_tipo_doc.tipo_doc = @p_tipo_doc


    END ELSE 

     IF (@action = 'SEARCH') BEGIN

      SELECT LN_producto_tipo_doc.producto, LN_producto_tipo_doc.tipo_doc,
      LN_producto_tipo_doc.requiere_upload, LN_producto_tipo_doc.requiere_verificacion,
      LN_producto_tipo_doc.verifica_backend, LN_producto_tipo_doc.verifica_cliente,
      LN_producto_tipo_doc.tolerancia_carga, LN_producto_tipo_doc.orden, LN_producto_tipo_doc.ponderacion,
      LN_producto_tipo_doc.activo, LN_producto_tipo_doc.created_by, LN_producto_tipo_doc.modified_by,
      CONVERT(VARCHAR(19), LN_producto_tipo_doc.created, 121) as created,
      CONVERT(VARCHAR(19), LN_producto_tipo_doc.modified, 121) as modified,
      LN_productos.nombre_producto, LN_tipos_doc.nombre_tipo_doc, LN_tipos_doc.modalidad,
      LN_tipos_doc.tipo_vigencia, LN_tipos_doc.dia_vigencia, LN_tipos_doc.mes_vigencia,
      LN_tipos_doc.es_balance, LN_productos.country_code, country.country_name,
      users.first_name + ' ' + users.last_name as created_by_user,
      users2.first_name + ' ' + users2.last_name as modified_by_user
      FROM LN_producto_tipo_doc
      INNER JOIN LN_productos ON LN_producto_tipo_doc.producto = LN_productos.producto
      inner join LN_tipos_doc ON LN_producto_tipo_doc.tipo_doc = LN_tipos_doc.tipo_doc
      inner join country ON LN_productos.country_code = country.country_code
      left outer join users on LN_producto_tipo_doc.created_by = users.user_id
      left outer join users users2 on LN_producto_tipo_doc.modified_by = users2.user_id
      WHERE LN_producto_tipo_doc.producto = @p_producto
      ORDER BY LN_producto_tipo_doc.orden, LN_tipos_doc.nombre_tipo_doc

     END ELSE

      IF (@action = 'ACTIVAR') BEGIN

       UPDATE LN_producto_tipo_doc SET 
        activo = iif(cfg.activo = 1, 0, 1),
        modified = GETDATE(),
        modified_by = @p_user_id
       FROM LN_producto_tipo_doc inner join LN_producto_tipo_doc cfg
       ON (LN_producto_tipo_doc.producto = cfg.producto
        AND LN_producto_tipo_doc.tipo_doc = cfg.tipo_doc)
       WHERE LN_producto_tipo_doc.producto = @p_producto
       AND LN_producto_tipo_doc.tipo_doc = @p_tipo_doc

      END ELSE

       IF (@action = 'UP') BEGIN

        SELECT @ord = orden 
        from LN_producto_tipo_doc
        where tipo_doc = @p_tipo_doc
        and producto = @p_producto

        IF (@ord > 1) BEGIN

         SELECT @tipo_doc_ant = tipo_doc
         from LN_producto_tipo_doc
         where producto = @p_producto
         and orden = (@ord-1)

         UPDATE LN_producto_tipo_doc SET
          orden = @ord - 1
         where producto = @p_producto
         and tipo_doc = @p_tipo_doc

         UPDATE LN_producto_tipo_doc SET
          orden = @ord
         where producto = @p_producto
         and tipo_doc = @tipo_doc_ant

        END

       END ELSE

        IF (@action = 'DOWN') BEGIN

         SELECT @ord = orden 
         from LN_producto_tipo_doc
         where tipo_doc = @p_tipo_doc
         and producto = @p_producto

         SELECT @cant = MAX(orden)
         from LN_producto_tipo_doc
         where producto = @p_producto

         IF (@ord < @cant) BEGIN

          SELECT @tipo_doc_ant = tipo_doc
          from LN_producto_tipo_doc
          where producto = @p_producto
          and orden = (@ord+1)


          UPDATE LN_producto_tipo_doc SET
           orden = @ord + 1
          where producto = @p_producto
          and tipo_doc = @p_tipo_doc


          UPDATE LN_producto_tipo_doc SET
           orden = @ord
          where producto = @p_producto
          and tipo_doc = @tipo_doc_ant


         END

        END




END

GO

Used By

No items found