dbo.Imperium_Regeneracion_Documentacion30Min_DEV

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

/*

EXEC Imperium_Regeneracion_Documentacion30Min

*/


CREATE OR ALTER PROCEDURE  dbo.Imperium_Regeneracion_Documentacion30Min_DEV
AS

BEGIN
 SET NOCOUNT ON;

DECLARE @ERRORNUMBER int

DECLARE @StartOfMonth DATE
DECLARE @ActualDate DATE
DECLARE @periodoV INT = NULL
DECLARE @periodoVAnt INT = NULL
DECLARE @periodoA INT = NULL
DECLARE @IDCliente int = NULL
DECLARE @Modalidad varchar(1)
DECLARE @NombreCliente varchar(200)
DECLARE @periodoYear INT = NULL
DECLARE @periodoMonth INT = NULL

DECLARE @contratista INT ,@cliente INT ,@contratista_1 INT ,@empleado INT ,@vehiculo INT
DECLARE @led_seccion VARCHAR(1)

DECLARE @idRepro INT

set @periodoVAnt = dbo.PeriodoMenosDos()
set @periodoV = dbo.PeriodoVencido()
set @periodoA = dbo.PeriodoAdelantado()


 begin
 
  delete led_reprocesa_docs2
  Insert into led_reprocesa_docs2 (contratista,cliente,contratista_1,led_seccion,empleado,vehiculo) 
  Select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion,
  NULL AS EMPLEADO,NULL AS VEHICULO from led_contratistas 
  where created > getdate() -0.2 and estado_contratista='A'
  union all 
  select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion,
  NULL AS EMPLEADO,NULL AS VEHICULO  from led_contratista_multi 
  where (created > getdate() -0.2 or modified > getdate()-0.2) 
  and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
  union all 
  select distinct contratista,cliente,contratista_1,'E' AS led_seccion,EMPLEADO,NULL AS VEHICULO  from led_empleados where created > getdate() -0.2 and estado_empleado='A'
  union all 
  select distinct contratista,cliente,contratista_1,'E' AS led_seccion,EMPLEADO,NULL AS VEHICULO  from led_empleado_multi  where (created > getdate() -0.2 or modified > getdate()-0.2) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
  union all
  select distinct contratista,cliente,contratista_1,'V' AS led_seccion,NULL AS EMPLEADO,VEHICULO  from led_vehiculos where created > getdate() -0.2 and estado_vehiculo='A'
 
 /* Averiguamos la lista de clientes a procesar -0.2*/
  DECLARE LedClientesActivos Cursor
  FOR
  
  select top 150 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro 
  from led_reprocesa_docs2 
  where procesado = 0
  Open LedClientesActivos


  Fetch NEXT FROM LedClientesActivos INTO @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro

  While (@@FETCH_STATUS = 0)
  BEGIN

/*
SELECT @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro as Repro
*/


  IF (@led_seccion = 'V')
  BEGIN
   exec Imperium_Carga_Docs_Vehiculos_Contratista @periodoA,@cliente,@contratista,'A'
   exec Imperium_Carga_Docs_Vehiculos_Contratista @periodoV,@cliente,@contratista,'V'
  END
  IF (@led_seccion = 'S')
  BEGIN
   exec Imperium_Carga_Docs_Sub_Contratista_Contratista @periodoA,@cliente,@contratista
   exec Imperium_Carga_Docs_Sub_Contratista_Contratista @periodoV,@cliente,@contratista
  END

  IF (@led_seccion = 'C')
  BEGIN
   EXEC Imperium_Multi_Carga_Docs_Contratista @cliente,@contratista,@periodoA,'A'
   EXEC Imperium_Multi_Carga_Docs_Contratista @cliente,@contratista,@periodoV,'V'
  END
  IF (@led_seccion = 'E')
  BEGIN

   exec Imperium_Multi_Carga_Docs_Empleados @cliente,@empleado,@periodoA,'A'
   exec Imperium_Multi_Carga_Docs_Empleados @cliente,@empleado,@periodoV,'V'
  END
  
  update led_reprocesa_docs2 set procesado=1 where idRepro=@idRepro

  Fetch NEXT FROM LedClientesActivos INTO @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro

  END

  CLOSE LedClientesActivos
  DEALLOCATE LedClientesActivos


end
END

GO

Used By

No items found