dbo.Imperium_contratista_doc_upload

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@p_doc_id bigint 8
@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.Imperium_contratista_doc_upload 
 -- Add the parameters for the stored procedure here

 @p_doc_id          bigint = NULL,
 @p_user_id          int = 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 @estado_doc varchar(1)
 DECLARE @doc_version int = 0
 DECLARE @doc_log varchar(max)
 DECLARE @parcial tinyint
 DECLARE @usuario varchar(100) = ''
 DECLARE @ahora datetime = GETDATE()
 DECLARE @preffix varchar(200)

 if (@p_doc_id > 0) begin

  select @estado_doc = estado_doc, @doc_version = doc_version, @doc_log = convert(varchar(max),doc_log), @parcial = isnull(aprobacion_parcial,0) from led_docs where doc_id = @p_doc_id

  if (@p_user_id is not null) begin
   select @usuario = isnull(first_name,'') + ' ' + isnull(last_name,'') from users where user_id = @p_user_id
  end

  SET @preffix = '['+@usuario+' - '+convert(varchar(10),@ahora,103) + ' ' + substring(convert(varchar,@ahora,121),12,5)+']: '

  UPDATE led_docs SET
   estado_doc = 'I',
   ingresado = @ahora,
   ingresado_por = @p_user_id,
   doc_log = isnull(convert(varchar(max),doc_log),'')+CHAR(13)+CHAR(10)+@preffix+' Subida de archivo.',
   compliance_doc = 'I',
   aprobacion_parcial = @parcial,
   reapertura_por_alta = 0,
   parcial_actualizado = iif(@parcial = 1, 1, 0),
   replicated_doc_id = NULL
  WHERE doc_id = @p_doc_id

  /* Para evitar que si se sube un doc de periodo anterior al actual y tiene un reemplazo (caso rechazados) quede inexacto el estado con su última versión */
  if (@doc_version > 0) begin
   update led_docs_aux set estado_doc = 'I' where doc_id = @p_doc_id and doc_version = @doc_version
  end

  EXEC Imperium_Status_Doc @p_doc_id         

 end
 
END
GO

Used By

No items found