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
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Regeneracion_Documentacion
/*
@periodo int,
@IDCliente int,
@led_seccion varchar(1)
*/
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ERRORNUMBER SMALLINT
/*
BEGIN
EXEC Carga_Led_Inicio_Periodo
END
*/
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 @periodoYear = convert(varchar(4),datepart(year,getdate()))
SET @periodoMonth = convert(varchar(2),datepart(month,getdate()))
SET @periodoYear = datepart(year,getdate())
SET @periodoMonth = datepart(month,getdate())
SET @periodoA = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())),2)
SeT @StartOfMonth = convert(date,DATEADD(month, DATEDIFF(month, 0, getdate()), 0))
set @ActualDate = getdate()
/*
select @StartOfMonth,@ActualDate,@periodoV,@periodoA,@periodoVAnt,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
/*
set @periodoMonth = 1
*/
if (@periodoMonth = 1)
begin
set @periodoV = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),12),2)
set @periodoVAnt = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),11),2)
end
if (@periodoMonth > 1)
begin
set @periodoV = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-1),2)
set @periodoVAnt = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-2),2)
end
set @periodoVAnt = dbo.PeriodoMenosDos()
set @periodoV = dbo.PeriodoVencido()
set @periodoA = dbo.PeriodoAdelantado()
/*
select @StartOfMonth as startofmonth,@ActualDate as actualdate,@periodoV as periodoV,@periodoA as periodoA,@periodoVAnt as periodoVANT,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
begin
/*
select @periodoV as periodoV,@periodoA as periodoA
*/
/*Averiguamos la lista de clientes a procesar */
DECLARE LedClientesActivos Cursor
FOR
/*
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -1 and estado_contratista='A'
union all
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion from led_empleados where created > getdate() -1 and estado_empleado='A'
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion from led_empleado_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select contratista,cliente,contratista_1,null as empleado,vehiculo,'V' AS led_seccion from led_vehiculos where created > getdate() -1 and estado_vehiculo='A'
*/
/*
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
group by contratista,cliente,contratista_1
order by contratista desc
*/
/*
truncate table led_reprocesa_docs
go
*/
/*
insert into led_reprocesa_docs (contratista,cliente,contratista_1,led_seccion)
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
group by contratista,cliente,contratista_1
order by contratista desc
*/
/* select distinct cliente from led_reprocesa_docs */
select top 100 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro
from led_reprocesa_docs
where procesado = 0
order by contratista desc
Open LedClientesActivos
Fetch NEXT FROM LedClientesActivos INTO @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro
While @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
/*
SELECT @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion
*/
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
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
update led_reprocesa_docs set procesado=1 where idRepro=@idRepro
END TRY
BEGIN CATCH
SET @ERRORNUMBER = 1
END CATCH
Fetch NEXT FROM LedClientesActivos INTO @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro
END
CLOSE LedClientesActivos
DEALLOCATE LedClientesActivos
select 'FIN'
end
END
GO
GO
/*
EXEC Imperium_Regeneracion_Documentacion
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Regeneracion_Documentacion
/*
@periodo int,
@IDCliente int,
@led_seccion varchar(1)
*/
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ERRORNUMBER SMALLINT
/*
BEGIN
EXEC Carga_Led_Inicio_Periodo
END
*/
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 @periodoYear = convert(varchar(4),datepart(year,getdate()))
SET @periodoMonth = convert(varchar(2),datepart(month,getdate()))
SET @periodoYear = datepart(year,getdate())
SET @periodoMonth = datepart(month,getdate())
SET @periodoA = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())),2)
SeT @StartOfMonth = convert(date,DATEADD(month, DATEDIFF(month, 0, getdate()), 0))
set @ActualDate = getdate()
/*
select @StartOfMonth,@ActualDate,@periodoV,@periodoA,@periodoVAnt,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
/*
set @periodoMonth = 1
*/
if (@periodoMonth = 1)
begin
set @periodoV = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),12),2)
set @periodoVAnt = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),11),2)
end
if (@periodoMonth > 1)
begin
set @periodoV = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-1),2)
set @periodoVAnt = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-2),2)
end
set @periodoVAnt = dbo.PeriodoMenosDos()
set @periodoV = dbo.PeriodoVencido()
set @periodoA = dbo.PeriodoAdelantado()
/*
select @StartOfMonth as startofmonth,@ActualDate as actualdate,@periodoV as periodoV,@periodoA as periodoA,@periodoVAnt as periodoVANT,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
begin
/*
select @periodoV as periodoV,@periodoA as periodoA
*/
/*Averiguamos la lista de clientes a procesar */
DECLARE LedClientesActivos Cursor
FOR
/*
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -1 and estado_contratista='A'
union all
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion from led_empleados where created > getdate() -1 and estado_empleado='A'
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion from led_empleado_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select contratista,cliente,contratista_1,null as empleado,vehiculo,'V' AS led_seccion from led_vehiculos where created > getdate() -1 and estado_vehiculo='A'
*/
/*
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
group by contratista,cliente,contratista_1
order by contratista desc
*/
/*
truncate table led_reprocesa_docs
go
*/
/*
insert into led_reprocesa_docs (contratista,cliente,contratista_1,led_seccion)
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) 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 from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
group by contratista,cliente,contratista_1
order by contratista desc
*/
/* select distinct cliente from led_reprocesa_docs */
select top 100 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro
from led_reprocesa_docs
where procesado = 0
order by contratista desc
Open LedClientesActivos
Fetch NEXT FROM LedClientesActivos INTO @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro
While @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
/*
SELECT @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion
*/
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
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
update led_reprocesa_docs set procesado=1 where idRepro=@idRepro
END TRY
BEGIN CATCH
SET @ERRORNUMBER = 1
END CATCH
Fetch NEXT FROM LedClientesActivos INTO @contratista,@cliente,@contratista_1,@empleado,@vehiculo,@led_seccion,@idRepro
END
CLOSE LedClientesActivos
DEALLOCATE LedClientesActivos
select 'FIN'
end
END
GO
Depends On
8Used By
No items found