Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
3| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_contratista_1 | int | 4 | |
| @p_contratista | int | 4 | |
| @p_seccion | varchar | 1 |
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_Pendientes_Ratificar
-- Add the parameters for the stored procedure here
/*
El SP devuelve:
0: nómina pendiente de ratificar en el período vencido
1: nómina ratificada en el período vencido
-1: el contratista no está ingresado en el período vencido o no tiene empleados en el período vencido
Requiere los dos parametros p_contratista_1 y p_contratista, que pueden ser el mismo para recursos
directos y distintos para nómina de recursos de subcontratista. En caso de ser distintos, si
led_seccion='S' se ignora ya que la nómina de subcontratistas de subcontratistas (>2do nivel) la
ratifica también el contratista de 1er nivel.
06/02/18 : cambio en la lógica. No se chequea la existencia de recursos en el período, sólo devuelve -1
cuando el contratista no está en el período. Esto es porque siempre se tiene que ratificar la nómina,
haya o no recursos afectados.
*/
@p_contratista_1 int,
@p_contratista int,
@p_seccion varchar(1)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @periodo_venc INT = CONVERT(INT, CONVERT(VARCHAR(4),YEAR(DATEADD(MONTH,-1,GETDATE()))) + RIGHT('00' + CONVERT(VARCHAR(2),MONTH(DATEADD(MONTH,-1,GETDATE()))), 2))
DECLARE @sin_ratificar int
-- Insert statements for procedure here
IF(@p_seccion = 'E') BEGIN
IF (@p_contratista_1 = @p_contratista) BEGIN
IF EXISTS (SELECT ISNULL(ratif_empleados,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_empleados,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END
ELSE BEGIN
IF EXISTS (SELECT ISNULL(ratif_empleados,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc)
BEGIN
SELECT @sin_ratificar = ISNULL(ratif_empleados,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc
END
END
END ELSE BEGIN
IF(@p_seccion = 'V') BEGIN
IF (@p_contratista_1 = @p_contratista) BEGIN
IF EXISTS (SELECT ISNULL(ratif_vehiculos,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_vehiculos,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END ELSE BEGIN
IF EXISTS (SELECT ISNULL(ratif_vehiculos,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_vehiculos,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc
END
END
END ELSE BEGIN
IF (@p_seccion = 'S') BEGIN
IF EXISTS (SELECT ISNULL(ratif_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END ELSE
IF (@p_seccion = 'R') BEGIN
/* Recursos de subcontratistas */
IF EXISTS (SELECT contratista
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_rec_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END
END
END
SELECT @sin_ratificar AS sin_ratificar
/*
SELECT @sin_ratificar AS sin_ratificar
*/
/*IF EXISTS (select led_contratista_periodo.contratista,
led_contratista_periodo.periodo
from led_contratista_periodo inner join led_empleados on
led_contratista_periodo.contratista = led_empleados.contratista_1
inner join led_empleados_periodo on
(led_empleados.empleado = led_empleados_periodo.empleado
and led_contratista_periodo.periodo = led_empleados_periodo.periodo)
where led_contratista_periodo.contratista = @p_contratista_1
and led_empleados.contratista_1 = @p_contratista_1
and led_empleados.contratista = @p_contratista
and led_contratista_periodo.periodo = @periodo_venc) BEGIN
IF (@p_contratista_1 = @p_contratista) BEGIN
select @sin_ratificar = ISNULL(ratif_empleados,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END ELSE BEGIN
select @sin_ratificar = ISNULL(ratif_empleados,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and contratista = @p_contratista_1
and periodo = @periodo_venc
END
END ELSE BEGIN
SET @sin_ratificar = -1
END*/
/*IF EXISTS (SELECT * FROM led_subcontratista_periodo
WHERE contratista_1 = @p_contratista_1
AND periodo = dbo.PeriodoVencido()) BEGIN
DECLARE @estado_ratificacion INT = 1
DECLARE @subcontratista INT
DECLARE @empleados INT
DECLARE @vehiculos INT
DECLARE QSubc CURSOR FOR
SELECT led_subcontratista_periodo.subcontratista,
ISNULL(led_subcontratista_periodo.ratif_empleados, 0) AS ratif_empleados,
ISNULL(led_subcontratista_periodo.ratif_vehiculos, 0) AS ratif_vehiculos
FROM led_subcontratista_periodo
INNER JOIN led_contratistas ON led_subcontratista_periodo.subcontratista = led_contratistas.contratista
WHERE led_subcontratista_periodo.contratista_1 = @p_contratista_1
AND led_subcontratista_periodo.periodo = dbo.PeriodoVencido()
AND led_contratistas.estado_contratista = 'A'
OPEN QSubc
FETCH NEXT FROM QSubc INTO @subcontratista, @empleados, @vehiculos
WHILE (@@FETCH_STATUS = 0) BEGIN
EXEC Imperium_vista_contratista_Pendientes_Ratificar @p_contratista_1, @subcontratista, 'E', @empleados output
IF (@empleados >= 0) BEGIN
SET @estado_ratificacion = (@estado_ratificacion & @empleados)
END
EXEC Imperium_vista_contratista_Pendientes_Ratificar @p_contratista_1, @subcontratista, 'V', @vehiculos output
IF (@vehiculos >= 0) BEGIN
SET @estado_ratificacion = (@estado_ratificacion & @vehiculos)
END
FETCH NEXT FROM QSubc INTO @subcontratista, @empleados, @vehiculos
END
CLOSE QSubc
DEALLOCATE QSubc
SET @sin_ratificar = @estado_ratificacion
END ELSE BEGIN
SET @sin_ratificar = -1
END*/
/*IF EXISTS (select led_contratista_periodo.contratista,
led_contratista_periodo.periodo
from led_contratista_periodo
inner join led_contratistas subcontratistas on
led_contratista_periodo.contratista = subcontratistas.contratista_1
inner join led_subcontratista_periodo on
(subcontratistas.contratista = led_subcontratista_periodo.subcontratista
and led_contratista_periodo.periodo = led_subcontratista_periodo.periodo)
where led_contratista_periodo.contratista = @p_contratista_1
-- and led_subcontratista_periodo.subcontratista = @p_contratista
and led_contratista_periodo.periodo = @periodo_venc) BEGIN
select @sin_ratificar = ISNULL(ratif_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END ELSE BEGIN
SET @sin_ratificar = -1
END*/
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.Imperium_contratista_Pendientes_Ratificar
-- Add the parameters for the stored procedure here
/*
El SP devuelve:
0: nómina pendiente de ratificar en el período vencido
1: nómina ratificada en el período vencido
-1: el contratista no está ingresado en el período vencido o no tiene empleados en el período vencido
Requiere los dos parametros p_contratista_1 y p_contratista, que pueden ser el mismo para recursos
directos y distintos para nómina de recursos de subcontratista. En caso de ser distintos, si
led_seccion='S' se ignora ya que la nómina de subcontratistas de subcontratistas (>2do nivel) la
ratifica también el contratista de 1er nivel.
06/02/18 : cambio en la lógica. No se chequea la existencia de recursos en el período, sólo devuelve -1
cuando el contratista no está en el período. Esto es porque siempre se tiene que ratificar la nómina,
haya o no recursos afectados.
*/
@p_contratista_1 int,
@p_contratista int,
@p_seccion varchar(1)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @periodo_venc INT = CONVERT(INT, CONVERT(VARCHAR(4),YEAR(DATEADD(MONTH,-1,GETDATE()))) + RIGHT('00' + CONVERT(VARCHAR(2),MONTH(DATEADD(MONTH,-1,GETDATE()))), 2))
DECLARE @sin_ratificar int
-- Insert statements for procedure here
IF(@p_seccion = 'E') BEGIN
IF (@p_contratista_1 = @p_contratista) BEGIN
IF EXISTS (SELECT ISNULL(ratif_empleados,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_empleados,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END
ELSE BEGIN
IF EXISTS (SELECT ISNULL(ratif_empleados,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc)
BEGIN
SELECT @sin_ratificar = ISNULL(ratif_empleados,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc
END
END
END ELSE BEGIN
IF(@p_seccion = 'V') BEGIN
IF (@p_contratista_1 = @p_contratista) BEGIN
IF EXISTS (SELECT ISNULL(ratif_vehiculos,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_vehiculos,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END ELSE BEGIN
IF EXISTS (SELECT ISNULL(ratif_vehiculos,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_vehiculos,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and periodo = @periodo_venc
END
END
END ELSE BEGIN
IF (@p_seccion = 'S') BEGIN
IF EXISTS (SELECT ISNULL(ratif_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END ELSE
IF (@p_seccion = 'R') BEGIN
/* Recursos de subcontratistas */
IF EXISTS (SELECT contratista
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc) BEGIN
SELECT @sin_ratificar = ISNULL(ratif_rec_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END
END
END
END
SELECT @sin_ratificar AS sin_ratificar
/*
SELECT @sin_ratificar AS sin_ratificar
*/
/*IF EXISTS (select led_contratista_periodo.contratista,
led_contratista_periodo.periodo
from led_contratista_periodo inner join led_empleados on
led_contratista_periodo.contratista = led_empleados.contratista_1
inner join led_empleados_periodo on
(led_empleados.empleado = led_empleados_periodo.empleado
and led_contratista_periodo.periodo = led_empleados_periodo.periodo)
where led_contratista_periodo.contratista = @p_contratista_1
and led_empleados.contratista_1 = @p_contratista_1
and led_empleados.contratista = @p_contratista
and led_contratista_periodo.periodo = @periodo_venc) BEGIN
IF (@p_contratista_1 = @p_contratista) BEGIN
select @sin_ratificar = ISNULL(ratif_empleados,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END ELSE BEGIN
select @sin_ratificar = ISNULL(ratif_empleados,0)
from led_subcontratista_periodo
where subcontratista = @p_contratista
and contratista = @p_contratista_1
and periodo = @periodo_venc
END
END ELSE BEGIN
SET @sin_ratificar = -1
END*/
/*IF EXISTS (SELECT * FROM led_subcontratista_periodo
WHERE contratista_1 = @p_contratista_1
AND periodo = dbo.PeriodoVencido()) BEGIN
DECLARE @estado_ratificacion INT = 1
DECLARE @subcontratista INT
DECLARE @empleados INT
DECLARE @vehiculos INT
DECLARE QSubc CURSOR FOR
SELECT led_subcontratista_periodo.subcontratista,
ISNULL(led_subcontratista_periodo.ratif_empleados, 0) AS ratif_empleados,
ISNULL(led_subcontratista_periodo.ratif_vehiculos, 0) AS ratif_vehiculos
FROM led_subcontratista_periodo
INNER JOIN led_contratistas ON led_subcontratista_periodo.subcontratista = led_contratistas.contratista
WHERE led_subcontratista_periodo.contratista_1 = @p_contratista_1
AND led_subcontratista_periodo.periodo = dbo.PeriodoVencido()
AND led_contratistas.estado_contratista = 'A'
OPEN QSubc
FETCH NEXT FROM QSubc INTO @subcontratista, @empleados, @vehiculos
WHILE (@@FETCH_STATUS = 0) BEGIN
EXEC Imperium_vista_contratista_Pendientes_Ratificar @p_contratista_1, @subcontratista, 'E', @empleados output
IF (@empleados >= 0) BEGIN
SET @estado_ratificacion = (@estado_ratificacion & @empleados)
END
EXEC Imperium_vista_contratista_Pendientes_Ratificar @p_contratista_1, @subcontratista, 'V', @vehiculos output
IF (@vehiculos >= 0) BEGIN
SET @estado_ratificacion = (@estado_ratificacion & @vehiculos)
END
FETCH NEXT FROM QSubc INTO @subcontratista, @empleados, @vehiculos
END
CLOSE QSubc
DEALLOCATE QSubc
SET @sin_ratificar = @estado_ratificacion
END ELSE BEGIN
SET @sin_ratificar = -1
END*/
/*IF EXISTS (select led_contratista_periodo.contratista,
led_contratista_periodo.periodo
from led_contratista_periodo
inner join led_contratistas subcontratistas on
led_contratista_periodo.contratista = subcontratistas.contratista_1
inner join led_subcontratista_periodo on
(subcontratistas.contratista = led_subcontratista_periodo.subcontratista
and led_contratista_periodo.periodo = led_subcontratista_periodo.periodo)
where led_contratista_periodo.contratista = @p_contratista_1
-- and led_subcontratista_periodo.subcontratista = @p_contratista
and led_contratista_periodo.periodo = @periodo_venc) BEGIN
select @sin_ratificar = ISNULL(ratif_subcontratistas,0)
from led_contratista_periodo
where contratista = @p_contratista_1
and periodo = @periodo_venc
END ELSE BEGIN
SET @sin_ratificar = -1
END*/
END
GO
Used By
No items found