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_Documentacion_OD
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Regeneracion_Documentacion_OD_Original
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_docs
Insert into led_reprocesa_docs (contratista,cliente,contratista_1,led_seccion,empleado,vehiculo)
select distinct contratista,cliente,contratista_1,'E' AS led_seccion,EMPLEADO,NULL AS VEHICULO from led_empleados where
estado_empleado='A' and empleado in (select distinct empleado from led_empleados_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos()) and empleado in (select distinct empleado from led_empleados where estado_empleado = 'A' and cliente not in (9335603,9700868))) and cliente not in (9335603,9700868) and contratista > 0
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 activo=1 and cliente not in (9335603,9700868) and contratista in (select distinct subcontratista from led_subcontratista_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos()) and subcontratista > 0)
union all
select distinct contratista,cliente,contratista_1,'V' AS led_seccion,NULL AS EMPLEADO,VEHICULO from led_vehiculos where estado_vehiculo='A'
and vehiculo in (select distinct vehiculo from led_vehiculos_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos())) and cliente not in (9335603,9700868) and contratista > 0
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 activo=1 and cliente not in (9335603,9700868) and contratista in (select distinct contratista from led_contratista_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos()) and contratista > 0)
delete led_reprocesa_docs
Insert into led_reprocesa_docs (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() -100 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() -100 or modified > getdate()-100)
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() -100 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() -100 or modified > getdate()-100) 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() -100 and estado_vehiculo='A'
*/
/* Averiguamos la lista de clientes a procesar -100*/
DECLARE LedClientesActivos Cursor
FOR
select top 1000 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro
from led_reprocesa_docs
where procesado = 0
/*
and contratista = 1043
*/
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_docs 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
GO
/*
EXEC Imperium_Regeneracion_Documentacion_OD
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Regeneracion_Documentacion_OD_Original
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_docs
Insert into led_reprocesa_docs (contratista,cliente,contratista_1,led_seccion,empleado,vehiculo)
select distinct contratista,cliente,contratista_1,'E' AS led_seccion,EMPLEADO,NULL AS VEHICULO from led_empleados where
estado_empleado='A' and empleado in (select distinct empleado from led_empleados_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos()) and empleado in (select distinct empleado from led_empleados where estado_empleado = 'A' and cliente not in (9335603,9700868))) and cliente not in (9335603,9700868) and contratista > 0
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 activo=1 and cliente not in (9335603,9700868) and contratista in (select distinct subcontratista from led_subcontratista_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos()) and subcontratista > 0)
union all
select distinct contratista,cliente,contratista_1,'V' AS led_seccion,NULL AS EMPLEADO,VEHICULO from led_vehiculos where estado_vehiculo='A'
and vehiculo in (select distinct vehiculo from led_vehiculos_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos())) and cliente not in (9335603,9700868) and contratista > 0
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 activo=1 and cliente not in (9335603,9700868) and contratista in (select distinct contratista from led_contratista_periodo where periodo in (dbo.PeriodoVencido(),dbo.PeriodoAdelantado(),dbo.PeriodoMenosDos()) and contratista > 0)
delete led_reprocesa_docs
Insert into led_reprocesa_docs (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() -100 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() -100 or modified > getdate()-100)
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() -100 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() -100 or modified > getdate()-100) 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() -100 and estado_vehiculo='A'
*/
/* Averiguamos la lista de clientes a procesar -100*/
DECLARE LedClientesActivos Cursor
FOR
select top 1000 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro
from led_reprocesa_docs
where procesado = 0
/*
and contratista = 1043
*/
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_docs 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
Depends On
8Used By
No items found