dbo.LN_reporte_subcontratistas_amx_mensual

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.LN_reporte_subcontratistas_amx_mensual
AS

BEGIN
    SET NOCOUNT ON;

SELECT 
/*
p2.nombre_persona  as contratista,
p2.identificacion as cuit_contratista,
padrones.numero, 
*/

padrones.nombre_persona as sub_contratista,
padrones.identificacion as cuit_sub_contratista,
LN_familias.nombre_familia as familia
FROM LN_contrapartes
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
INNER JOIN country ON LN_contrapartes.country_code = country.country_code
INNER JOIN LN_gestiones ON LN_contrapartes.contraparte = LN_gestiones.contraparte
INNER JOIN users users1 ON LN_contrapartes.created_by = users1.user_id
LEFT OUTER JOIN users users2 ON LN_contrapartes.modified_by = users2.user_id

LEFT OUTER JOIN LN_contrapartes PADRE on LN_contrapartes.id_padre = PADRE.contraparte
LEFT OUTER JOIN padrones p2 on PADRE.id_padron = p2.id_padron

LEFT OUTER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
LEFT OUTER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia

WHERE LN_contrapartes.subcontratista = 1
and (ln_contrapartes.created > '2020-12-01 00:00:00')

union 

SELECT 
/*
p2.nombre_persona  as contratista,
p2.identificacion as cuit_contratista,
padrones.numero, 
*/

padrones.nombre_persona as sub_contratista,
padrones.identificacion as cuit_sub_contratista,
LN_familias.nombre_familia as familia
FROM LN_contrapartes
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
INNER JOIN country ON LN_contrapartes.country_code = country.country_code
INNER JOIN LN_gestiones ON LN_contrapartes.contraparte = LN_gestiones.contraparte
INNER JOIN users users1 ON LN_contrapartes.created_by = users1.user_id
LEFT OUTER JOIN users users2 ON LN_contrapartes.modified_by = users2.user_id

LEFT OUTER JOIN LN_contrapartes PADRE on LN_contrapartes.id_padre = PADRE.contraparte
LEFT OUTER JOIN padrones p2 on PADRE.id_padron = p2.id_padron

LEFT OUTER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
LEFT OUTER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia

WHERE LN_contrapartes.subcontratista = 1 and LN_contrapartes.id_padron in (select distinct id_padron from padrones where identificacion in (select DISTINCT CUIT from consultar_afip where proceso = 'SUBCAMX' AND FECHA = '2020-12-01'))


union 

SELECT 
/*
p2.nombre_persona  as contratista,
p2.identificacion as cuit_contratista,
padrones.numero, 
*/

padrones.nombre_persona as sub_contratista,
padrones.identificacion as cuit_sub_contratista,
LN_familias.nombre_familia as familia
FROM LN_contrapartes
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
INNER JOIN country ON LN_contrapartes.country_code = country.country_code
INNER JOIN LN_gestiones ON LN_contrapartes.contraparte = LN_gestiones.contraparte
INNER JOIN users users1 ON LN_contrapartes.created_by = users1.user_id
LEFT OUTER JOIN users users2 ON LN_contrapartes.modified_by = users2.user_id

LEFT OUTER JOIN LN_contrapartes PADRE on LN_contrapartes.id_padre = PADRE.contraparte
LEFT OUTER JOIN padrones p2 on PADRE.id_padron = p2.id_padron

LEFT OUTER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
LEFT OUTER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia

WHERE LN_contrapartes.subcontratista = 1 and LN_contrapartes.id_padron in (select distinct id_padron from padrones where identificacion in (
'30573652084',
'30578494185',
'30584715932',
'30610753139',
'30622143867',
'30639453975',
'30658733717',
'30688408888',
'30690855387',
'30696173008',
'30698332812',
'30703335922',
'30707508996',
'30707559779',
'30707923896',
'30707953523',
'30708118652',
'30708126124',
'30708311150',
'30708906693',
'30709038601',
'30709054615',
'30709134406',
'30709139696',
'30709238341',
'30709586315',
'30709592943',
'30709607622',
'30709637084',
'30709690643',
'30709875880',
'30709991244',
'30709994251',
'30710082819',
'30710235801',
'30710235925',
'30710330405',
'30710422733',
'30710539673',
'30710580266',
'30710720661',
'30711019886',
'30711138532',
'30711155917',
'30711220867',
'30711374481',
'30711388539',
'30711489017',
'30711615136',
'30711629854',
'30711872333',
'30712024514',
'30712321179',
'30712467793',
'30712512268',
'30714069736',
'30714271535',
'30714319244',
'30714348457',
'30714385697',
'30714410470',
'30714549223',
'30714588768',
'30714708151',
'30714724416',
'30714739863',
'30714763861',
'30714814113',
'30714922978',
'30714941298',
'30715046403',
'30715121499',
'30715154079',
'30715165968',
'30715259385',
'30715301381',
'30715530828',
'30715573039',
'30715757369',
'30715814001',
'30715832050',
'30715870459',
'30715877739',
'30715916335',
'30715982869',
'30715998323',
'30716105365',
'30716154536',
'30716194279',
'30716260166',
'30716532727',
'30716548585',
'30716584530',
'30716586126',
'30716597802',
'30716694336',
'30716729202',
'30716780313',
'33504261579',
'33661814999',
'33688256149',
'33709309159',
'33711789079',
'33711870879',
'33712088139',
'33714327599',
'33715041699',
'33715182039',
'33715859659',
'33716646799',
'34525505539'))

ORDER BY [sub_contratista]
-- p2.nombre_persona,padrones.nombre_persona




END 

GO

Used By

No items found