dbo.Imperium_Regeneracion_Nati

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

CREATE OR ALTER PROCEDURE  dbo.Imperium_Regeneracion_Nati
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 @Fecha datetime = null
DECLARE @contratista INT ,@cliente INT ,@contratista_1 INT ,@empleado INT ,@vehiculo INT
DECLARE @led_seccion VARCHAR(1)
DECLARE @idRepro INT
DECLARE @CantPendientes int = 0
  
set @periodoVAnt = dbo.PeriodoMenosDos()
set @periodoV = dbo.PeriodoVencido()
set @periodoA = dbo.PeriodoAdelantado()


set @periodoVAnt = 202404
set @periodoV = 202405
set @periodoA = 202406

/*

EXEC Imperium_Regeneracion_Nati

*/



 begin
  
  select @CantPendientes = count(*) from led_reprocesa_docs2 where procesado = 0
-- select * from led_reprocesa_docs2 where procesado = 0
  if (@CantPendientes = 0)
  begin
   delete led_reprocesa_docs2
   Insert into led_reprocesa_docs2 (contratista,cliente,contratista_1,led_seccion,empleado,vehiculo) 
   select distinct contratista,2046807993 as cliente,contratista_1,'E' AS led_seccion,EMPLEADO,NULL AS VEHICULO
   from led_empleados_periodo  where periodo = 202405 and contratista in (10706,10707,10708,10709,10710,10711,10712,10713,10714,10715,10716)

  end

 /* Averiguamos la lista de clientes a procesar -0.23.3*/
  DECLARE LedClientesActivos Cursor
  FOR

  select top 1000 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro,fecha 
  from led_reprocesa_docs2 
  where procesado = 0
  order by idRepro desc
  Open LedClientesActivos


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

  While (@@FETCH_STATUS = 0)
  BEGIN

  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'
   exec Imperium_Carga_Docs_Vehiculos_Contratista @periodoV,@cliente,@contratista,'A'
  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'
   EXEC Imperium_Multi_Carga_Docs_Contratista @cliente,@contratista,@periodoV,'A'
  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'
   exec Imperium_Multi_Carga_Docs_Empleados @cliente,@empleado,@periodoV,'A'
  END
  
  update led_reprocesa_docs2 set procesado=1 where idRepro=@idRepro
   delete led_reprocesa_docs2 where procesado=1 and idRepro=@idRepro

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

  END

  CLOSE LedClientesActivos
  DEALLOCATE LedClientesActivos


end
END
GO

Used By

No items found