Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @seccion | varchar | 100 | |
| @fecha_char | varchar | 10 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
exec led_amx_a_informix2 'contrapartes_familias','2019-03-27'
exec led_amx_a_informix2 'subcontratistas','1901-01-01'
exec led_amx_a_informix2 'subcontratistas_contratista','1901-01-01'
exec led_amx_a_informix2 'IVA','2019-03-19'
exec led_amx_a_informix2 'documentos','2019-03-28'
exec led_amx_a_informix2 'excepciones','1901-01-01'
select * from ln_contrapartes where cliente = 5546348 and activo = 0
*/
CREATE OR ALTER PROCEDURE dbo.led_amx_a_informix2
@seccion varchar(100),
@fecha_char varchar(10) = null
/* Cuits en LED de AMX (cliente 5546348)
Recorro todos las tablas para registros creados o modificados en las fechas solicitadas */
AS
BEGIN
SET NOCOUNT ON;
declare @fecha date
declare @cliente int
declare @cuit varchar(20)
declare @contraparte int
declare @familia varchar(100)
if (@fecha_char = '' or @fecha_char is null)
begin
set @fecha = convert(date, getdate())
end
else
begin
set @fecha = CONVERT(date, @fecha_char)
end
/* Cuits en led
Busca todas las contrapartes que se modificaron, ellas o alguna de las familias
*/
if (@seccion = 'contrapartes_familias')
begin
select distinct --LN_contrapartes.cliente as cliente,
--ln_contrapartes.modified, ln_contraparte_familias.modified,
clientes.cli_codigo as cli_codigo,
padrones.identificacion as cuit,
LN_contrapartes.country_code as pais,
padrones.nombre_persona as nombre,
--padrones.habilitado as habilitado,
LN_contrapartes.contraparte as contraparte,
IIF (ln_contrapartes.activo=1,'ACTIVO','INACTIVO') as estado_contraparte,
--ln_contraparte_familias.familia as cod_familia,
ln_familias.nombre_familia as familia,
/* case nombre_familia
when 'ESTRATEGICO' then 'PE'
when 'CRITICO EMPRESA' then 'PCE'
when 'CRITICO P. FISICA' then 'PCF'
when 'NO CRITICO EMPRESA' then 'PNCE'
when 'NO CRITICO P. FISICA' then 'PNCF'
when 'OTRO OPERADOR' then 'OTR'
when 'CONTROL INGRESO' then 'CON'
when 'REPUESTOS EMPRESAS' then 'RE'
when 'REPUESTOS P. FISICAS' then 'RF'
when 'EVENTUAL' then 'EVE'
when 'PARAGUAY CRITICO EMPRESA' then 'E2CE'
when 'PARAGUAY CRITICO P. FISICA' then 'E2CF'
when 'PARAGUAY NO CRITICO EMPRESA' then 'E2NCE'
when 'PARAGUAY NO CRITICO P. FISICA' then 'E2NCF'
when 'PARAGUAY CRITICO EMPRESA S/D.E.' then 'E2CE2'
when 'PARAGUAY CRITICO FISICA S/D.E.' then 'E2CF2'
when 'URUGUAY CRITICO EMPRESA' then ' ECE'
when 'URUGUAY CRITICO P. FISICA' then 'ECF'
when 'URUGUAY NO CRITICO EMPRESA' then 'ENCE'
when 'URUGUAY NO CRITICO P. FISICA' then 'ENCF'
when 'URUGUAY CRITICO EMPRESA S/D.E.' then 'ECE2'
when 'URUGUAY CRITICO FISICA S/D.E.' then 'ECF2'
else ''
end as cod_familia,
*/
case ln_familias.familia
when '25' then 'PCE' /* CRIT. EMP. */
when '26' then 'PCF' /* CRIT. P. FIS. */
when '27' then 'PE' /* ESTRATEGICO */
when '28' then 'EVE' /* EVENTUAL */
when '29' then 'PNCE' /* NO CRITICO EMPRESA */
when '30' then 'PNCF' /* NO CRITICO P. FISICA */
when '31' then 'OTR' /* OTRO OPERADOR */
when '32' then 'CON' /* CONTROL INGRESO */
when '33' then 'RE' /* REPUESTOS EMPRESAS */
when '34' then 'RF' /* REPUESTOS P. FISICAS */
when '44' then 'ECE' /* URUGUAY CRITICO EMPRESA */
when '45' then 'ECF' /* URUGUAY CRITICO P. FISICA */
when '46' then 'ENCE' /* URUGUAY NO CRITICO EMPRESA*/
when '47' then 'ENCF' /* URUGUAY NO CRITICO P. FISICA */
when '48' then 'ECE2' /* URUGUAY CRITICO EMPRESA S/D.E. */
when '49' then 'ECF2' /* URUGUAY CRITICO FISICA S/D.E. */
when '50' then 'E2CE' /* PARAGUAY CRITICO EMPRESA */
when '51' then 'E2CF' /* PARAGUAY CRITICO P. FISICA */
when '52' then 'E2NCE' /* PARAGUAY NO CRITICO EMPRESA */
when '53' then 'E2NCF' /* PARAGUAY NO CRITICO P. FISICA */
when '54' then 'E2CE2' /* PARAGUAY CRITICO EMPRESA S/D.E. */
when '55' then 'E2CF2' /* PARAGUAY CRITICO FISICA S/D.E. */
else ''
end as cod_familia,
IIF (ln_contraparte_familias.activo=1,'ACTIVO','INACTIVO') as estado_familia,
familias.cant as cant_familias
from LN_contrapartes
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join clientes on clientes.cliente = LN_contrapartes.cliente
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join ln_familias on ln_familias.familia = ln_contraparte_familias.familia --and ln_familias.cliente = Ln_contrapartes.cliente
inner join (select contraparte, count(*) as cant from LN_contraparte_familias where activo = 1 and familia != 37 group by contraparte) familias
on familias.contraparte = ln_contrapartes.contraparte
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and LN_contrapartes.subcontratista = 0
and ln_contraparte_familias.familia not in (37,31,62) -- No subcontratistas
and
(
(convert(date, ln_contrapartes.created) >= @fecha --or
--convert(date, ln_contrapartes.modified) >= @fecha
)
or (select count(*) from ln_contraparte_familias x where x.contraparte = ln_contrapartes.contraparte and
(convert(date, x.created) >= @fecha or
convert(date, x.modified) >= @fecha)) > 0 -- cambio algo en alguna de las familias
)
end
if (@seccion = 'subcontratistas') --> para cargar en la tabla subcontratistas
begin
select distinct --LN_contrapartes.cliente as cliente,
clientes.cli_codigo as cli_codigo,
padrones2.identificacion as cuit_contratista,
padre.country_code as pais_contratista,
padrones.identificacion as cuit_subcontratista,
LN_contrapartes.country_code as pais_subcontratista,
--padrones.nombre_persona as nombre_subcontratista,
--padrones.habilitado as habilitado,
LN_contrapartes.contraparte as contraparte,
IIF (ln_contrapartes.activo=1,'ACTIVO','INACTIVO') as estado_contraparte,
ln_familias.nombre_familia as Tipo_servicio,
/* case nombre_familia
when 'Subcontratista Servicios' then 'S'
when 'Subcontratista Material' then 'M'
when 'Subcontratista Servicios y Material' then 'A'
else ''
end as tipo,
*/
case ln_familias.familia
when '37' then 'S' /* Subcontratista Servicios */
when '61' then 'M' /* Subcontratista Material */
when '62' then 'A' /* Subcontratista Servicios y Material */
else ''
end as tipo,
IIF (ln_contraparte_familias.activo=1,'ACTIVO','INACTIVO') as estado_familia,
convert(varchar(10),ln_gestiones.desde,103) as vigencia_desde,
convert(varchar(10),ln_gestiones.hasta,103) as vigencia_hasta
from LN_contrapartes
inner join LN_gestiones on ln_gestiones.contraparte = ln_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join ln_contrapartes padre on padre.contraparte = ln_contrapartes.id_padre
inner join padrones as padrones2 on padrones2.id_padron = padre.id_padron and padrones2.habilitado = 1
inner join clientes on clientes.cliente = LN_contrapartes.cliente
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join ln_familias on ln_familias.familia = ln_contraparte_familias.familia --and ln_familias.cliente = Ln_contrapartes.cliente
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and LN_contrapartes.subcontratista = 1
--and ln_contraparte_familias.familia in (37,61,62) -- subcontratistas
and
(convert(date, ln_contraparte_familias.created) >= @fecha or
convert(date, ln_contraparte_familias.modified) >= @fecha)
end
if (@seccion = 'subcontratistas_contratista') --> para cargar en la tabla subcontratistas_mail
begin
select distinct
clientes.cli_codigo as cli_codigo,
padrones.identificacion as cuit_contratista,
LN_contrapartes.country_code as pais_contratista,
--padrones.nombre_persona as nombre_contratista,
ln_contrapartes.nombre_contacto as contacto,
ln_contrapartes.telefono_contacto as telefono,
ln_contrapartes.email_contacto as email,
'A' as tipo
from ln_contrapartes
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join clientes on clientes.cliente = ln_contrapartes.cliente
where contraparte in
(select distinct id_padre
from LN_contrapartes
inner join LN_gestiones on ln_gestiones.contraparte = ln_contrapartes.contraparte
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and LN_contrapartes.subcontratista = 1
--and ln_contraparte_familias.familia in (37,61,62) -- subcontratistas
and (convert(date, ln_contraparte_familias.created) >= @fecha or
convert(date, ln_contraparte_familias.modified) >= @fecha)
)
end
if (@seccion = 'excepciones')
begin
select ln_contrapartes.contraparte, padrones.nombre_persona as nombre,
padrones.identificacion as cuit,
LN_contrapartes.country_code as pais,
iif(a.estado = 0, '3', iif(a.tipo_excepcion = 'V', '1', '2')) as tipo,
/* 1- APROBADO POR EXCEPCION
2- RECHAZADO POR EXCEPCION
3- SIN EXCEPCION */
a.texto_excepcion as texto,
iif(ln_contrapartes.subcontratista = 0, 'CONTRATISTA','SUBCONTRATISTA') as contratista_subcontratista
from LN_Excepciones a
inner join ln_contrapartes on ln_contrapartes.contraparte = a.contraparte
inner join padrones on padrones.id_padron = ln_contrapartes.id_padron and padrones.habilitado = 1
and ln_contrapartes.cliente = 5546348 -- Cliente AMX
and (convert(date, a.created) >= @fecha or
convert(date, a.modified) >= @fecha)
order by a.contraparte, tipo desc
end
if (@seccion = 'IVA')
begin
select distinct ln_contrapartes.contraparte, padrones.nombre_persona as nombre,
padrones.identificacion as cuit,
LN_contrapartes.country_code as pais,
convert(varchar(7),a.valor_fecha,120) as periodo,
b.valor_numerico as iva,a.created,a.modified
from LN_doc_campos_col a
inner join ln_docs on ln_docs.doc_id = a.doc_id
inner join ln_contrapartes on ln_contrapartes.contraparte = ln_docs.contraparte
inner join padrones on padrones.id_padron = ln_contrapartes.id_padron and padrones.habilitado = 1
inner join ln_doc_campos_col b on b.doc_id = a.doc_id and b.seccion = a.seccion and b.campo = a.campo and b.fila = a.fila
where a.campo in (select distinct campo from ln_tipo_doc_campos where campo_id = 'VENTAS-ANUALES')
and ln_docs.estado_doc = 'V'
and ln_docs.aplica = 1
and a.col = 0
and b.col = 2
and b.valor_numerico is not null --> tiene cargado el valor del iva
and ln_contrapartes.cliente = 5546348 -- Cliente AMX
and ln_contrapartes.subcontratista = 0
and (convert(date, a.created) >= @fecha or
convert(date, a.modified) >= @fecha or
convert(date, b.created) >= @fecha or
convert(date, b.modified) >= @fecha or
convert(date, LN_docs.created) >= @fecha or
convert(date, LN_docs.modified) >= @fecha)
end
if (@seccion = 'documentos')
begin
/*
select * from LN_familias where familia in
( '25', '26', '27','28', '29', '30', '31', '32')
select * from LN_familias where set_doc in
( 6,7,8,22,4)
x 6 crit empresa
5 estrategico
x 4 crit persona fisica
15 no crit emp
16 no crit persona fisica
33 repuestos empresa
34 repuestos persona fisica
select * from ln_tipos_doc where tipo_doc = 1079
select * from LN_set_tipo_doc where tipo_doc = 1079
select * from ln_set_tipo_doc where set_doc = 22
ESTO LO USE PARA VER QUE DOCUMENTOS SE PIDE EN CADA FAMILIA:
-- Estrategico
select 'Estrategico' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 5
-- Critico Persona Fisica
union
select 'Critico Persona Fisica' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 4
-- Critico Empresa
union
select 'Critico Empresa' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 6
-- Repuestos Empresa
union
select 'Repuestos Empresa' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 7
-- Repuestos Persona Fisica
union
select 'Repuestos Persona Fisica' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc
from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 8
*/
declare @valor varchar(20)
declare @pais varchar(10)
declare @formulario varchar(2)
declare @respuesta table (tipo varchar(20), cuit varchar(20), pais varchar(10), cod_familia varchar(20), item int, valor varchar(20))
-- Busco Critico Empresa
DECLARE PCE CURSOR FOR
select distinct LN_contrapartes.contraparte as contraparte, padrones.identificacion as cuit, ln_contrapartes.country_code as pais,
ln_familias.nombre_familia as familia,
/*
case nombre_familia
when 'ESTRATEGICO' then 'PE'
when 'CRITICO EMPRESA' then 'PCE'
when 'CRITICO P. FISICA' then 'PCF'
when 'NO CRITICO EMPRESA' then 'PNCE'
when 'NO CRITICO P. FISICA' then 'PNCF'
when 'OTRO OPERADOR' then 'OTR'
when 'CONTROL INGRESO' then 'CON'
when 'REPUESTOS EMPRESAS' then 'RE'
when 'REPUESTOS P. FISICAS' then 'RF'
when 'EVENTUAL' then 'EVE'
when 'PARAGUAY CRITICO EMPRESA' then 'E2CE'
when 'PARAGUAY CRITICO P. FISICA' then 'E2CF'
when 'PARAGUAY NO CRITICO EMPRESA' then 'E2NCE'
when 'PARAGUAY NO CRITICO P. FISICA' then 'E2NCF'
when 'PARAGUAY CRITICO EMPRESA S/D.E.' then 'E2CE2'
when 'PARAGUAY CRITICO FISICA S/D.E.' then 'E2CF2'
when 'URUGUAY CRITICO EMPRESA' then ' ECE'
when 'URUGUAY CRITICO P. FISICA' then 'ECF'
when 'URUGUAY NO CRITICO EMPRESA' then 'ENCE'
when 'URUGUAY NO CRITICO P. FISICA' then 'ENCF'
when 'URUGUAY CRITICO EMPRESA S/D.E.' then 'ECE2'
when 'URUGUAY CRITICO FISICA S/D.E.' then 'ECF2'
else ''
end as cod_familia
*/
case ln_familias.familia
when '25' then 'PCE' /* CRIT. EMP. */
when '26' then 'PCF' /* CRIT. P. FIS. */
when '27' then 'PE' /* ESTRATEGICO */
when '28' then 'EVE' /* EVENTUAL */
when '29' then 'PNCE' /* NO CRITICO EMPRESA */
when '30' then 'PNCF' /* NO CRITICO P. FISICA */
when '31' then 'OTR' /* OTRO OPERADOR */
when '32' then 'CON' /* CONTROL INGRESO */
when '33' then 'RE' /* REPUESTOS EMPRESAS */
when '34' then 'RF' /* REPUESTOS P. FISICAS */
when '44' then 'ECE' /* URUGUAY CRITICO EMPRESA */
when '45' then 'ECF' /* URUGUAY CRITICO P. FISICA */
when '46' then 'ENCE' /* URUGUAY NO CRITICO EMPRESA */
when '47' then 'ENCF' /* URUGUAY NO CRITICO P. FISICA */
when '48' then 'ECE2' /* URUGUAY CRITICO EMPRESA S/D.E. */
when '49' then 'ECF2' /* URUGUAY CRITICO FISICA S/D.E. */
when '50' then 'E2CE' /* PARAGUAY CRITICO EMPRESA */
when '51' then 'E2CF' /* PARAGUAY CRITICO P. FISICA */
when '52' then 'E2NCE' /* PARAGUAY NO CRITICO EMPRESA */
when '53' then 'E2NCF' /* PARAGUAY NO CRITICO P. FISICA */
when '54' then 'E2CE2' /* PARAGUAY CRITICO EMPRESA S/D.E. */
when '55' then 'E2CF2' /* PARAGUAY CRITICO FISICA S/D.E. */
else ''
end as cod_familia
from LN_contrapartes
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join clientes on clientes.cliente = LN_contrapartes.cliente
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join ln_familias on ln_familias.familia = ln_contraparte_familias.familia --and ln_familias.cliente = Ln_contrapartes.cliente
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and ln_contrapartes.activo=1
and ln_contraparte_familias.activo=1
--and ln_familias.nombre_familia = 'CRITICO EMPRESA'
and LN_Contrapartes.subcontratista = 0
OPEN PCE
declare @cod_familia varchar(20)
FETCH NEXT FROM PCE INTO @contraparte,@cuit,@pais,@familia,@cod_familia
WHILE @@fetch_status = 0
BEGIN
-- 1001 - Formulario Completado
-- 1) Se le pidio formulario
if (@cod_familia = 'PCE' /* CRITICO EMPRESA */ or
@cod_familia = 'RE' /* REPUESTOS EMPRESAS */
)
begin
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in ( 1005,
1006,
1007,
1008,
1009,
1010,
1011,
1012,
1013,
1064,
1065,
1084)
) != 0)
begin
-- Todavia no lo termino de completar?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1005,
1006,
1007,
1008,
1009,
1010,
1011,
1012,
1013,
1064,
1065,
1084)
and estado_doc in ('I','N','R')) != 0)
begin
set @formulario = 'NO'
set @valor = '2' -- no
end
else
begin
set @formulario = 'SI'
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais, @cod_familia, '1001', @valor)
end
end
if (@cod_familia = 'PCF' /* CRITICO P. FISICA */ OR
@cod_familia = 'RF' /* REPUESTOS P. FISICAS */
)
begin
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in ( 1005,
1006,
1067,
1068,
1009,
1010,
1011,
1012,
1013,
1064,
1069,
1084)
) != 0)
begin
-- Todavia no lo termino de completar?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1005,
1006,
1067,
1068,
1009,
1010,
1011,
1012,
1013,
1064,
1069,
1084)
and estado_doc in ('I','N','R')) != 0)
begin
set @formulario = 'NO'
set @valor = '2' -- no
end
else
begin
set @formulario = 'SI'
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais, @cod_familia, '1001', @valor)
end
end
if (@cod_familia = 'PE' /* ESTRATEGICO */ )
begin
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in ( 1005,
1070,
1071,
1084)
) != 0)
begin
-- Todavia no lo termino de completar?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1005,
1070,
1071,
1084)
and estado_doc in ('I','N','R')) != 0)
begin
set @formulario = 'NO'
set @valor = '2' -- no
end
else
begin
set @formulario = 'SI'
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais, @cod_familia, '1001', @valor)
end
end
if (@cod_familia = 'PCE' /* CRITICO EMPRESA */ or
@cod_familia = 'PCF' /* CRITICO P. FISICA */ or
@cod_familia = 'PE' /* ESTRATEGICO */
)
begin
-- 1007 - CODIGO PARA EVITAR CORRUPCION Y SOBORNO
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1065,1069,1071)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1065,1069,1071)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1007', @valor)
end
end
-- 1008 - DOS ULT. BALANCES O MANIFESTACION DE BIENES (en empresas - documento 1034, en personas fisicas - documento 1080)
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1034,1080)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1034,1080)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1008', @valor)
end
--- 1003 - SLA (SERVICE LEVEL AGREEMENT)
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1074)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1074)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais,@cod_familia, '1003', @valor)
end
--- 1004 - COPIA DE HABILITACION MUNICIPAL
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1081)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1081)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1004', @valor)
end
-- 1006 - PROTOCOLO DE CONTROL DE CALIDAD
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1082)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1082)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1006', @valor)
end
-- 1009 - ACTA APROBACION ULT. BALANCE
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1023)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1023)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais,@cod_familia, '1009', @valor)
end
-- 1010 - ULTIMOS TRES F.931 Y COMPROBANTE DE PAGO
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (3)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (3)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1010', @valor)
end
-- 1011 - ACTA DE DIRECTORIO ESTATUTO Y MODIFICACIONES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1076)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1076)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1011', @valor)
end
-- 1012 - INSCRIPCION EN AFIP ULTIMAS 12 POS IVA Y GANANCIAS
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1063,
1073,
1027)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1063,
1073,
1027)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1012', @valor)
end
-- 1013 - ORGANIGRAMA DE LA SOCIEDAD
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1015)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1015)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1013', @valor)
end
-- 1014 - DETALLE DE LAS ACTIVIDADES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1028)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1028)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1014', @valor)
end
-- 1015 - DDJJ 1 - PAGO DE APORTES IVA GANANCIAS ETC.
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1072)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1072)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1015', @valor)
end
-- 1016 - D DDJJ 2 - PAGO DE SEGUROS
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1086)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1086)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1016', @valor)
end
-- 1082 - SEGURO DE RESPONSABILIDAD CIVIL
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1083)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1083)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1082', @valor)
end
-- 1081 - TERMINOS Y CONDICIONES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1079,1091)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1079,1091)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1081', @valor)
end
-- 1011 - TERMINOS Y CONDICIONES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1076)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1076)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1011', @valor)
end
-- 1017 - DDJJ 3 - DECLARACION DE CUMPLIMIENTO DE LA LEGISLACION LABORAL VIGENTE
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1087)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1087)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1017', @valor)
end
-- 1018 - DDJJ 4 - CONDUCTA COMERCIAL
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1077,1090)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1077,1090)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais,@cod_familia, '1018', @valor)
end
-- 1019 - INVENTARIO DETALLADO
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1088)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1088)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1019', @valor)
end
-- Respuestas a Preguntas del Formulario
declare @valores table (contraparte int, gestion int, doc_id int, seccion int, campo int, tipo_campo varchar(1), nombre_campo varchar(200), etiqueta varchar(300),fila int, col int, valor_numerico float, valor_texto varchar(max), valor_fecha smalldatetime, valor_fecha_srt varchar(200))
if (@formulario='SI') -- or @formulario='NO')
begin
/*
1022 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (1)
1025 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (2)
1028 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (3)
1031 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (4)
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ESPECIALIZACION_PRODUCTO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia as cod_familia,
case fila
when 1 then 1022
when 2 then 1025
when 3 then 1028
when 4 then 1031
end as item,
case valor_texto
when 'M5' then 1
when 'E25' then 2
when 'N2' then 3
end as valor
from @valores
where col = 3 and isnull(valor_texto,'') != ''
/*
1032 2.2 DATOS DE LOS CENTROS DE TRABAJO
Ya completo el formulario 2? --> Si completo alguno: SI, Si no completo ninguno --> NO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CENTROS_TRABAJO'
if (select count(*) from @valores) > 0 -- Si tiene Centros de Trabajo en su formulario
begin
if ((select count(*)
from @valores
where col = 1
and isnull(valor_texto,'') != '') > 0 )
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1032', @valor)
end
/*
1049 2.3 SUBCONTRATAN HABITUALMENTE ACTIVIDADES PARA LLEVAR A CABO SUS PRODUCTOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'AMX_SUBCONTRATAN'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1049' as item,
case valor_numerico
when 0 then 1 --> no
when 1 then 2 --> si
else 1 --> no
end as valor
from @valores
/*
10501 - TRABAJADORES EN PLANTILLA
*/
/*
declare @valores table (contraparte int, gestion int, doc_id int, seccion int, campo int, tipo_campo varchar(10), nombre_campo varchar(200), etiqueta varchar(200),fila int, col int, valor_numerico float, valor_texto varchar(max), valor_fecha smalldatetime, valor_fecha_srt varchar(200))
declare @contraparte int = 4145
*/
--select * from LN_tipo_doc_campos where campo_id = 'NA_TRABAJADORES'
--select * from ln_campos where etiqueta like 'No tenemos personal'
declare @na char(1) = null, @valor1 int = null, @valor2 int = null, @valor3 int = null
declare @valor1t int = null, @valor2t int = null, @valor3t int = null
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_NO_CALIFICADOS'
set @valor1 = (select isnull(valor_numerico,'0') from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_NO_CALIFICADOS_TEMP'
set @valor1t = (select isnull(valor_numerico,'0') from @valores)
if (@valor1 is not null or @valor1t is not null)
set @valor1 = isnull(@valor1,0) + isnull(@valor1t,0)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_PROFESIONALES'
set @valor2 = (select isnull(valor_numerico,'0') from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_PROFESIONALES_TEMP'
set @valor2t = (select isnull(valor_numerico,'0') from @valores)
if (@valor2 is not null or @valor2t is not null)
set @valor2 = isnull(@valor2,0) + isnull(@valor2t,0)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_ADMINISTRATIVOS'
set @valor3 = (select isnull(valor_numerico,'0') from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_ADMINISTRATIVOS_TEMP'
set @valor3t = (select isnull(valor_numerico,'0') from @valores)
if (@valor3 is not null or @valor3t is not null)
set @valor3 = isnull(@valor3,0) + isnull(@valor3t,0)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'NA_TRABAJADORES'
set @na = (select isnull(valor_texto,'0') from @valores)
if (@na is not null or (@valor1 is not null and @valor2 is not null and @valor3 is not null))
begin
if (@na = 1)
begin
set @valor = 3
end
else
begin
if (@valor1 < (@valor2 + @valor3))
set @valor = 1
else
set @valor = 2
end
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '10501', @valor)
end
/*
1054 2.5 NUMERO DE ALTAS Y BAJAS DEL ULTIMO AÑO
*/
declare @despido int = null
declare @retiro INT = null
declare @otros int = null
declare @bajas int = null
declare @altas int = null
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'BAJA_DESPIDO'
set @despido = (select isnull(valor_numerico,0) from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'BAJA_RETIRO'
set @retiro = (select isnull(valor_numerico,0) from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'BAJA_OTROS_MOTIVOS'
set @otros = (select isnull(valor_numerico,0) from @valores)
set @bajas = @despido + @retiro + @otros
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ALTAS_PERSONAL'
set @altas = (select isnull(valor_numerico,0) from @valores)
set @valor = null
if (isnull(@altas,0) < isnull(@bajas,0)) set @valor = 1
if (isnull(@altas,0) = isnull(@bajas,0))
begin
set @valor = 2
end
else
begin
if (isnull(@altas,0) > isnull(@bajas,0) AND isnull(@altas,0) < isnull(@bajas,0) * 1.5) set @valor = 3
if (isnull(@altas,0) >= isnull(@bajas,0) * 1.5 AND isnull(@altas,0) < isnull(@bajas,0) * 2) set @valor = 4
if (isnull(@altas,0) >= isnull(@bajas,0) * 2) set @valor = 5
end
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'NA_ALTAS_BAJAS'
if (select case isnull(valor_texto,0)
when 1 then 1
else 0
end from @valores) = 1 set @valor = 6
if (@valor is not null) insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1054', @valor)
/*
1059 - 2.6 CUENTAN CON PROGRAMAS ANUALES DE DESARROLLO Y FORMACION DEL PERSONAL
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PROGRAMA_DESARROLLO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1059' as item,
case valor_texto
when '1' then 1 --> si
when '0' then 2 --> no
when '3' then 3 --> n/a
else '3' --> n/a
end as valor
from @valores
/*
1066 - CONFLICTOS LABORALES EN LOS ULTIMOS 2 AÂ¥OS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONFLICTOS_LABORALES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1066' as item,
case valor_texto
when 'S' then 1 --> si, entre 1 y 5
when 'M' then 2 --> si, mas de 5
when 'N' then 3 --> no
else 3 --> n/a
end as valor
from @valores
/*
1068 - DEPARTAMENTO DE INVESTIGACION Y DESARROLLO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'DPTO_INVESTIGACION_DESARROLLO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1068' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1069 - PATENTADOS DESAROLLOS TECNICOS O TECNOLOGICOS PROPIOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PATENTADOS_DESAROLLOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1069' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1071 3.3 COMUNICACION / VENTA: E-MAIL
1072 3.3 COMUNICACION / VENTA: CATALOGO DE PRODUCTOS
1073 3.3 COMUNICACION / VENTA: VENTA TELEFONICA
1074 3.3 COMUNICACION / VENTA: WEB INFORMATIVA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TECNOLOGIA_COMUNICACION'
if (select count(*) from @valores) > 0
begin
-- e-mail
if (select count(*) from @valores where valor_texto like '%E%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1071', @valor)
-- catalogo
if (select count(*) from @valores where valor_texto like '%C%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1072', @valor)
-- venta telefonica
if (select count(*) from @valores where valor_texto like '%T%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1073', @valor)
-- web
if (select count(*) from @valores where valor_texto like '%W%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1074', @valor)
end
/*
1076 - COMUNICACION CON AMX: TELEFONO
1077 - COMUNICACION CON AMX: E-MAIL
1078 - COMUNICACION CON AMX: INTERNET
1079 - COMUNICACION CON AMX: SUBASTA ELECTRONICA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'COMUNICACION_AMX'
if (select count(*) from @valores) > 0
begin
-- telefono
if (select count(*) from @valores where valor_texto like '%T%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1076', @valor)
-- e-mail
if (select count(*) from @valores where valor_texto like '%E%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1077', @valor)
-- internet
if (select count(*) from @valores where valor_texto like '%I%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1078', @valor)
-- subasta electronica
if (select count(*) from @valores where valor_texto like '%S%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1079', @valor)
end
/*
1083 - PROCESO HOMOLOGACION DE PROVEEDORES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'HOMOLOGACION_PROVEEDORES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1083' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1085 - PORCENTAJE DE COMPRAS A PROVEEDORES HOMOLOGADOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PROCENTAJE_PROVEEDORES_HOMOLOGADOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1085' as item,
case
when valor_numerico > 75 then 4
when valor_numerico >= 50 and valor_numerico < 75 then 3
when valor_numerico >= 25 and valor_numerico < 50 then 2
else 1
end as valor
from @valores
/*
1086 - EVALUAN SERVICIO DE PROVEEDORES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EVALUAN_PROVEEDORES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1086' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1089 - TIENEN ASEGURADOS SUMINISTROS DE PRODUCTOS CRITICOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ASEGURADOS_SUMINISTROS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1089' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1091 - AMBITO GEOGRAFICO DE SUMINISTRO: CAPITAL FEDERAL
1092 - AMBITO GEOGRAFICO DE SUMINISTRO: GRAN BUENOS AIRES
1093 - AMBITO GEOGRAFICO DE SUMINISTRO: INTERIOR DEL PAIS
1094 - AMBITO GEOGRAFICO DE SUMINISTRO: EXTERIOR
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'AMBITO_GEOGRAFICO'
if (select count(*) from @valores) > 0
begin
-- capital
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item = '0')> 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1091', @valor)
-- Buenos Aires
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item = '1')> 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1092', @valor)
-- Interior del Pais (tiene cargado algo que no es Capital, ni Buenos Aires, ni exterior)
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item not in ('0','1','25')) > 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1093', @valor)
-- Exterio
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item = '25')> 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1092', @valor)
end
/*
1095 - SISTEMA INFORMATIZADO DE CONTROL DE INVENTARIO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTROL_INVENTARIO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1095' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1096 - CONTROL INTERNO PERIODICO SOBRE LOS NIVELES DE INVENTARIO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTROL_NIVEL_INVENTARIO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1096' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1097 - CONTROL EXTERNO DE INVENTARIO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTROL_EXTERNO_INVENTARIO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1097' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1098 - CERTIFICADO ISO-9000
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ISO_9000'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1098' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1101 - OTRO CERTIFICADO DE CALIDAD
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'OTRO_CERTIFICADO_CALIDAD'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1101' as item,
case valor_texto
when 'N' then 1 --> NO
when 'O' then 2 --> 1
when 'M' then 3 --> mas de 1
else 1 --> no
end as valor
from @valores
/*
1111 - ANTIGUEDAD EQUIPO PRODUCTIVO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ANTIGUEDAD_EQUIPO_PRODUCTIVO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1111' as item,
case valor_texto
when 'M5' then 1 --> menos de 5
when 'M10' then 2 --> entre 5 y 10
when 'M20' then 3 --> entre 10 y 20
when 'Y20' then 4 --> mas de 20
when 'N' then 5 --> no aplica
else 5 --> no aplica
end as valor
from @valores
/*
1112 - PROGRAMA DE MANTENIMIENTO PREVENTIVO DE EQUIPO PRODUCTIVO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MANTENIMIENTO_PREVENTIVO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1112' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
PORCENTAJE_INVERSION
/*
1113 - PORCENTAJE DE INVERSION EN EQUIPOS PRODUCTIVOS
0-10|E10-30|E30-50|M50|N
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ANTIGUEDAD_EQUIPO_PRODUCTIVO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1113' as item,
case valor_texto
when '0-10' then 1 --> menos de 10
when 'E10-30' then 2 --> entre 10 y 30
when 'E30-50' then 3 --> entre 30 y 50
when 'M50' then 4 --> mas de 50
when 'N' then 5 --> no aplica
else 5 --> no aplica
end as valor
from @valores
/*
1119 - INFORMA PRINCIPALES CLIENTES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PRINCIPALES_CLIENTES'
if (select count(*) from @valores) > 0
begin
if ((select count(*)
from @valores
where col = 1
and isnull(valor_texto,'') != '') > 0 )
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1119', @valor)
end
/*
1124 - INFORMA PRINCIPALES PROVEEDORES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PRINCIPALES_PROVEEDORES'
if (select count(*) from @valores) > 0
begin
if ((select count(*)
from @valores
where col = 1
and isnull(valor_texto,'') != '') > 0 )
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1124', @valor)
end
/*
11142 - PORCENTAJE DE CLIENTES EN EL SECTOR TELECOMUNICACIONES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'SECTORES_CLIENTES'
if (select count(*) from @valores) > 0
begin
if ((select isnull(valor_numerico,'0')
from @valores
where col = 1) >
(select sum(isnull(valor_numerico,'0'))
from @valores
where col > 1 ))
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '11142', @valor)
end
/*
1129 - SERVICIO DE POST-VENTA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'SERVICIO_POSTVENTA'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1129' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1131 - AREA DE ATENCION AL CLIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ATENCION_CLIENTE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1131' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1133 - PROCESO DE MEDICION DE SATISFACCION
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'SATISFACCION_CLIENTES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1133' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1135 - NORMAS SOBRE CONSERVACION MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MEDIO_AMBIENTE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1135' as item,
case valor_texto
when 'S' then 1 --> si
when 'E' then 2 --> en proceso
when 'N' then 3 --> no
when 'X' then 4 --> no aplica
else 3 --> no
end as valor
from @valores
/*
1138 9.2 EXPEDIENTE DISCIPLINARIO POR INCUNPLIMIENTO NORMAS DE MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EXPEDIENTE_DISCIPLINARIO'
if (select count(*) from @valores) > 0
begin
set @valor = null
set @valor = (select case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores)
if (@valor is not null)
begin
if (@valor = 2)
begin
insert into @respuesta values ('pregunta',@cuit,@pais,@cod_familia, '1138',1)
end
else
begin
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EXPEDIENTE_DISCIPLINARIO_CORRECCION'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1138' as item,
case valor_numerico
when 1 then 2 --> si, y han tomado medidas
when 0 then 3 --> si, y no han tomado medidas
else 3 --> si, y no han tomado medidas
end as valor
from @valores
end
end
end
/*
1140 - CERTIFICADO ISO 14001 SOBRE MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ISO_14001'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1140' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1141 - MEDIDAS INTERNAS QUE CONTRIBUYEN A LA PRESERVACION DEL MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MEDIDAS_PRESERVACION_MEDIO_AMBIENTE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1141' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1143 - MEDIDAS SALUD E HIGIENE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MEDIDAS_SALUD_HIGIENE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1143' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1145 - CONTRATACION PERSONAS SECTORES DESFAVORECIDOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTRATAN_SECTORES_DESFAVORECIDOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1145' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1146 - PARTICIPAN INSTITUCIONES RELACIONADAS CON EL FOMENTO DE LA CULTURA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'FOMENTO_CULTURA'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1146' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1157 - PLAN DE CONTINGENCIA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PLAN_CONTINGENCIA'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1157' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1159 - DE CUANTOS PROVEEDORES DEPENDE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'DE_CUANTOS_PROVEEDORES_DEPENDE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1159' as item,
case valor_texto
when '3' then 1 --> hasta 3
when '4' then 2 --> de 4
when '5' then 3 --> mas de 5
else 1
end as valor
from @valores
/*
1160 - HAN TENIDO ALGUNA EXPERIENCIA DONDE HAYAN PODIDO COMPROBAR SU CAPACIDAD ANTE CRISIS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EXPERIENCIA_CRISIS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1160' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1168 - CODIGO DE CONDUCTA PARA EVITAR VULNERACIONES DE LOS DERECHOS HUMANOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CODIGO_CONDUCTA_DERECHOS_HUMANOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1168' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1169 - CODIGO DE CONDUCTA O POLITICA PARA EVITAR LA CORRUPCION Y SOBORNO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CODIGO_CONDUCTA_CORRUPCION'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1169' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1170 - EN CUESTIONARIOS DE HOMOLOGACION A SUS PROVEEDORES INCLUYEN CRITERIOS AMBIENTALES Y SOCIALES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CRITERIOS_AMBIENTALES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1170' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
end
FETCH NEXT FROM PCE INTO @contraparte,@cuit,@pais,@familia,@cod_familia
END
CLOSE PCE
DEALLOCATE PCE
if (@formulario='SI')
begin
select convert(char(7), getdate(),120) as periodo, * from @respuesta where tipo = 'documento'
union
select convert(char(7), getdate(),120) as periodo, * from @respuesta where tipo = 'pregunta'
order by 3,4,5
end
else
begin
-- Si todavia no completo el formulario, solo manda los documentos ya verificados
select convert(char(7), getdate(),120) as periodo, * from @respuesta where tipo = 'documento' and valor = 1
order by 3,4,5
end
END
END
GO
GO
/*
exec led_amx_a_informix2 'contrapartes_familias','2019-03-27'
exec led_amx_a_informix2 'subcontratistas','1901-01-01'
exec led_amx_a_informix2 'subcontratistas_contratista','1901-01-01'
exec led_amx_a_informix2 'IVA','2019-03-19'
exec led_amx_a_informix2 'documentos','2019-03-28'
exec led_amx_a_informix2 'excepciones','1901-01-01'
select * from ln_contrapartes where cliente = 5546348 and activo = 0
*/
CREATE OR ALTER PROCEDURE dbo.led_amx_a_informix2
@seccion varchar(100),
@fecha_char varchar(10) = null
/* Cuits en LED de AMX (cliente 5546348)
Recorro todos las tablas para registros creados o modificados en las fechas solicitadas */
AS
BEGIN
SET NOCOUNT ON;
declare @fecha date
declare @cliente int
declare @cuit varchar(20)
declare @contraparte int
declare @familia varchar(100)
if (@fecha_char = '' or @fecha_char is null)
begin
set @fecha = convert(date, getdate())
end
else
begin
set @fecha = CONVERT(date, @fecha_char)
end
/* Cuits en led
Busca todas las contrapartes que se modificaron, ellas o alguna de las familias
*/
if (@seccion = 'contrapartes_familias')
begin
select distinct --LN_contrapartes.cliente as cliente,
--ln_contrapartes.modified, ln_contraparte_familias.modified,
clientes.cli_codigo as cli_codigo,
padrones.identificacion as cuit,
LN_contrapartes.country_code as pais,
padrones.nombre_persona as nombre,
--padrones.habilitado as habilitado,
LN_contrapartes.contraparte as contraparte,
IIF (ln_contrapartes.activo=1,'ACTIVO','INACTIVO') as estado_contraparte,
--ln_contraparte_familias.familia as cod_familia,
ln_familias.nombre_familia as familia,
/* case nombre_familia
when 'ESTRATEGICO' then 'PE'
when 'CRITICO EMPRESA' then 'PCE'
when 'CRITICO P. FISICA' then 'PCF'
when 'NO CRITICO EMPRESA' then 'PNCE'
when 'NO CRITICO P. FISICA' then 'PNCF'
when 'OTRO OPERADOR' then 'OTR'
when 'CONTROL INGRESO' then 'CON'
when 'REPUESTOS EMPRESAS' then 'RE'
when 'REPUESTOS P. FISICAS' then 'RF'
when 'EVENTUAL' then 'EVE'
when 'PARAGUAY CRITICO EMPRESA' then 'E2CE'
when 'PARAGUAY CRITICO P. FISICA' then 'E2CF'
when 'PARAGUAY NO CRITICO EMPRESA' then 'E2NCE'
when 'PARAGUAY NO CRITICO P. FISICA' then 'E2NCF'
when 'PARAGUAY CRITICO EMPRESA S/D.E.' then 'E2CE2'
when 'PARAGUAY CRITICO FISICA S/D.E.' then 'E2CF2'
when 'URUGUAY CRITICO EMPRESA' then ' ECE'
when 'URUGUAY CRITICO P. FISICA' then 'ECF'
when 'URUGUAY NO CRITICO EMPRESA' then 'ENCE'
when 'URUGUAY NO CRITICO P. FISICA' then 'ENCF'
when 'URUGUAY CRITICO EMPRESA S/D.E.' then 'ECE2'
when 'URUGUAY CRITICO FISICA S/D.E.' then 'ECF2'
else ''
end as cod_familia,
*/
case ln_familias.familia
when '25' then 'PCE' /* CRIT. EMP. */
when '26' then 'PCF' /* CRIT. P. FIS. */
when '27' then 'PE' /* ESTRATEGICO */
when '28' then 'EVE' /* EVENTUAL */
when '29' then 'PNCE' /* NO CRITICO EMPRESA */
when '30' then 'PNCF' /* NO CRITICO P. FISICA */
when '31' then 'OTR' /* OTRO OPERADOR */
when '32' then 'CON' /* CONTROL INGRESO */
when '33' then 'RE' /* REPUESTOS EMPRESAS */
when '34' then 'RF' /* REPUESTOS P. FISICAS */
when '44' then 'ECE' /* URUGUAY CRITICO EMPRESA */
when '45' then 'ECF' /* URUGUAY CRITICO P. FISICA */
when '46' then 'ENCE' /* URUGUAY NO CRITICO EMPRESA*/
when '47' then 'ENCF' /* URUGUAY NO CRITICO P. FISICA */
when '48' then 'ECE2' /* URUGUAY CRITICO EMPRESA S/D.E. */
when '49' then 'ECF2' /* URUGUAY CRITICO FISICA S/D.E. */
when '50' then 'E2CE' /* PARAGUAY CRITICO EMPRESA */
when '51' then 'E2CF' /* PARAGUAY CRITICO P. FISICA */
when '52' then 'E2NCE' /* PARAGUAY NO CRITICO EMPRESA */
when '53' then 'E2NCF' /* PARAGUAY NO CRITICO P. FISICA */
when '54' then 'E2CE2' /* PARAGUAY CRITICO EMPRESA S/D.E. */
when '55' then 'E2CF2' /* PARAGUAY CRITICO FISICA S/D.E. */
else ''
end as cod_familia,
IIF (ln_contraparte_familias.activo=1,'ACTIVO','INACTIVO') as estado_familia,
familias.cant as cant_familias
from LN_contrapartes
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join clientes on clientes.cliente = LN_contrapartes.cliente
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join ln_familias on ln_familias.familia = ln_contraparte_familias.familia --and ln_familias.cliente = Ln_contrapartes.cliente
inner join (select contraparte, count(*) as cant from LN_contraparte_familias where activo = 1 and familia != 37 group by contraparte) familias
on familias.contraparte = ln_contrapartes.contraparte
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and LN_contrapartes.subcontratista = 0
and ln_contraparte_familias.familia not in (37,31,62) -- No subcontratistas
and
(
(convert(date, ln_contrapartes.created) >= @fecha --or
--convert(date, ln_contrapartes.modified) >= @fecha
)
or (select count(*) from ln_contraparte_familias x where x.contraparte = ln_contrapartes.contraparte and
(convert(date, x.created) >= @fecha or
convert(date, x.modified) >= @fecha)) > 0 -- cambio algo en alguna de las familias
)
end
if (@seccion = 'subcontratistas') --> para cargar en la tabla subcontratistas
begin
select distinct --LN_contrapartes.cliente as cliente,
clientes.cli_codigo as cli_codigo,
padrones2.identificacion as cuit_contratista,
padre.country_code as pais_contratista,
padrones.identificacion as cuit_subcontratista,
LN_contrapartes.country_code as pais_subcontratista,
--padrones.nombre_persona as nombre_subcontratista,
--padrones.habilitado as habilitado,
LN_contrapartes.contraparte as contraparte,
IIF (ln_contrapartes.activo=1,'ACTIVO','INACTIVO') as estado_contraparte,
ln_familias.nombre_familia as Tipo_servicio,
/* case nombre_familia
when 'Subcontratista Servicios' then 'S'
when 'Subcontratista Material' then 'M'
when 'Subcontratista Servicios y Material' then 'A'
else ''
end as tipo,
*/
case ln_familias.familia
when '37' then 'S' /* Subcontratista Servicios */
when '61' then 'M' /* Subcontratista Material */
when '62' then 'A' /* Subcontratista Servicios y Material */
else ''
end as tipo,
IIF (ln_contraparte_familias.activo=1,'ACTIVO','INACTIVO') as estado_familia,
convert(varchar(10),ln_gestiones.desde,103) as vigencia_desde,
convert(varchar(10),ln_gestiones.hasta,103) as vigencia_hasta
from LN_contrapartes
inner join LN_gestiones on ln_gestiones.contraparte = ln_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join ln_contrapartes padre on padre.contraparte = ln_contrapartes.id_padre
inner join padrones as padrones2 on padrones2.id_padron = padre.id_padron and padrones2.habilitado = 1
inner join clientes on clientes.cliente = LN_contrapartes.cliente
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join ln_familias on ln_familias.familia = ln_contraparte_familias.familia --and ln_familias.cliente = Ln_contrapartes.cliente
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and LN_contrapartes.subcontratista = 1
--and ln_contraparte_familias.familia in (37,61,62) -- subcontratistas
and
(convert(date, ln_contraparte_familias.created) >= @fecha or
convert(date, ln_contraparte_familias.modified) >= @fecha)
end
if (@seccion = 'subcontratistas_contratista') --> para cargar en la tabla subcontratistas_mail
begin
select distinct
clientes.cli_codigo as cli_codigo,
padrones.identificacion as cuit_contratista,
LN_contrapartes.country_code as pais_contratista,
--padrones.nombre_persona as nombre_contratista,
ln_contrapartes.nombre_contacto as contacto,
ln_contrapartes.telefono_contacto as telefono,
ln_contrapartes.email_contacto as email,
'A' as tipo
from ln_contrapartes
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join clientes on clientes.cliente = ln_contrapartes.cliente
where contraparte in
(select distinct id_padre
from LN_contrapartes
inner join LN_gestiones on ln_gestiones.contraparte = ln_contrapartes.contraparte
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and LN_contrapartes.subcontratista = 1
--and ln_contraparte_familias.familia in (37,61,62) -- subcontratistas
and (convert(date, ln_contraparte_familias.created) >= @fecha or
convert(date, ln_contraparte_familias.modified) >= @fecha)
)
end
if (@seccion = 'excepciones')
begin
select ln_contrapartes.contraparte, padrones.nombre_persona as nombre,
padrones.identificacion as cuit,
LN_contrapartes.country_code as pais,
iif(a.estado = 0, '3', iif(a.tipo_excepcion = 'V', '1', '2')) as tipo,
/* 1- APROBADO POR EXCEPCION
2- RECHAZADO POR EXCEPCION
3- SIN EXCEPCION */
a.texto_excepcion as texto,
iif(ln_contrapartes.subcontratista = 0, 'CONTRATISTA','SUBCONTRATISTA') as contratista_subcontratista
from LN_Excepciones a
inner join ln_contrapartes on ln_contrapartes.contraparte = a.contraparte
inner join padrones on padrones.id_padron = ln_contrapartes.id_padron and padrones.habilitado = 1
and ln_contrapartes.cliente = 5546348 -- Cliente AMX
and (convert(date, a.created) >= @fecha or
convert(date, a.modified) >= @fecha)
order by a.contraparte, tipo desc
end
if (@seccion = 'IVA')
begin
select distinct ln_contrapartes.contraparte, padrones.nombre_persona as nombre,
padrones.identificacion as cuit,
LN_contrapartes.country_code as pais,
convert(varchar(7),a.valor_fecha,120) as periodo,
b.valor_numerico as iva,a.created,a.modified
from LN_doc_campos_col a
inner join ln_docs on ln_docs.doc_id = a.doc_id
inner join ln_contrapartes on ln_contrapartes.contraparte = ln_docs.contraparte
inner join padrones on padrones.id_padron = ln_contrapartes.id_padron and padrones.habilitado = 1
inner join ln_doc_campos_col b on b.doc_id = a.doc_id and b.seccion = a.seccion and b.campo = a.campo and b.fila = a.fila
where a.campo in (select distinct campo from ln_tipo_doc_campos where campo_id = 'VENTAS-ANUALES')
and ln_docs.estado_doc = 'V'
and ln_docs.aplica = 1
and a.col = 0
and b.col = 2
and b.valor_numerico is not null --> tiene cargado el valor del iva
and ln_contrapartes.cliente = 5546348 -- Cliente AMX
and ln_contrapartes.subcontratista = 0
and (convert(date, a.created) >= @fecha or
convert(date, a.modified) >= @fecha or
convert(date, b.created) >= @fecha or
convert(date, b.modified) >= @fecha or
convert(date, LN_docs.created) >= @fecha or
convert(date, LN_docs.modified) >= @fecha)
end
if (@seccion = 'documentos')
begin
/*
select * from LN_familias where familia in
( '25', '26', '27','28', '29', '30', '31', '32')
select * from LN_familias where set_doc in
( 6,7,8,22,4)
x 6 crit empresa
5 estrategico
x 4 crit persona fisica
15 no crit emp
16 no crit persona fisica
33 repuestos empresa
34 repuestos persona fisica
select * from ln_tipos_doc where tipo_doc = 1079
select * from LN_set_tipo_doc where tipo_doc = 1079
select * from ln_set_tipo_doc where set_doc = 22
ESTO LO USE PARA VER QUE DOCUMENTOS SE PIDE EN CADA FAMILIA:
-- Estrategico
select 'Estrategico' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 5
-- Critico Persona Fisica
union
select 'Critico Persona Fisica' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 4
-- Critico Empresa
union
select 'Critico Empresa' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 6
-- Repuestos Empresa
union
select 'Repuestos Empresa' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 7
-- Repuestos Persona Fisica
union
select 'Repuestos Persona Fisica' as familia, ln_tipos_doc.tipo_doc, nombre_tipo_doc
from LN_set_tipo_doc
inner join ln_tipos_doc on ln_tipos_doc.tipo_doc = LN_set_tipo_doc.tipo_doc
where set_doc = 8
*/
declare @valor varchar(20)
declare @pais varchar(10)
declare @formulario varchar(2)
declare @respuesta table (tipo varchar(20), cuit varchar(20), pais varchar(10), cod_familia varchar(20), item int, valor varchar(20))
-- Busco Critico Empresa
DECLARE PCE CURSOR FOR
select distinct LN_contrapartes.contraparte as contraparte, padrones.identificacion as cuit, ln_contrapartes.country_code as pais,
ln_familias.nombre_familia as familia,
/*
case nombre_familia
when 'ESTRATEGICO' then 'PE'
when 'CRITICO EMPRESA' then 'PCE'
when 'CRITICO P. FISICA' then 'PCF'
when 'NO CRITICO EMPRESA' then 'PNCE'
when 'NO CRITICO P. FISICA' then 'PNCF'
when 'OTRO OPERADOR' then 'OTR'
when 'CONTROL INGRESO' then 'CON'
when 'REPUESTOS EMPRESAS' then 'RE'
when 'REPUESTOS P. FISICAS' then 'RF'
when 'EVENTUAL' then 'EVE'
when 'PARAGUAY CRITICO EMPRESA' then 'E2CE'
when 'PARAGUAY CRITICO P. FISICA' then 'E2CF'
when 'PARAGUAY NO CRITICO EMPRESA' then 'E2NCE'
when 'PARAGUAY NO CRITICO P. FISICA' then 'E2NCF'
when 'PARAGUAY CRITICO EMPRESA S/D.E.' then 'E2CE2'
when 'PARAGUAY CRITICO FISICA S/D.E.' then 'E2CF2'
when 'URUGUAY CRITICO EMPRESA' then ' ECE'
when 'URUGUAY CRITICO P. FISICA' then 'ECF'
when 'URUGUAY NO CRITICO EMPRESA' then 'ENCE'
when 'URUGUAY NO CRITICO P. FISICA' then 'ENCF'
when 'URUGUAY CRITICO EMPRESA S/D.E.' then 'ECE2'
when 'URUGUAY CRITICO FISICA S/D.E.' then 'ECF2'
else ''
end as cod_familia
*/
case ln_familias.familia
when '25' then 'PCE' /* CRIT. EMP. */
when '26' then 'PCF' /* CRIT. P. FIS. */
when '27' then 'PE' /* ESTRATEGICO */
when '28' then 'EVE' /* EVENTUAL */
when '29' then 'PNCE' /* NO CRITICO EMPRESA */
when '30' then 'PNCF' /* NO CRITICO P. FISICA */
when '31' then 'OTR' /* OTRO OPERADOR */
when '32' then 'CON' /* CONTROL INGRESO */
when '33' then 'RE' /* REPUESTOS EMPRESAS */
when '34' then 'RF' /* REPUESTOS P. FISICAS */
when '44' then 'ECE' /* URUGUAY CRITICO EMPRESA */
when '45' then 'ECF' /* URUGUAY CRITICO P. FISICA */
when '46' then 'ENCE' /* URUGUAY NO CRITICO EMPRESA */
when '47' then 'ENCF' /* URUGUAY NO CRITICO P. FISICA */
when '48' then 'ECE2' /* URUGUAY CRITICO EMPRESA S/D.E. */
when '49' then 'ECF2' /* URUGUAY CRITICO FISICA S/D.E. */
when '50' then 'E2CE' /* PARAGUAY CRITICO EMPRESA */
when '51' then 'E2CF' /* PARAGUAY CRITICO P. FISICA */
when '52' then 'E2NCE' /* PARAGUAY NO CRITICO EMPRESA */
when '53' then 'E2NCF' /* PARAGUAY NO CRITICO P. FISICA */
when '54' then 'E2CE2' /* PARAGUAY CRITICO EMPRESA S/D.E. */
when '55' then 'E2CF2' /* PARAGUAY CRITICO FISICA S/D.E. */
else ''
end as cod_familia
from LN_contrapartes
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron and habilitado = 1
inner join clientes on clientes.cliente = LN_contrapartes.cliente
inner join ln_contraparte_familias on ln_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join ln_familias on ln_familias.familia = ln_contraparte_familias.familia --and ln_familias.cliente = Ln_contrapartes.cliente
where Ln_contrapartes.cliente = 5546348 -- Cliente AMX
and ln_contrapartes.activo=1
and ln_contraparte_familias.activo=1
--and ln_familias.nombre_familia = 'CRITICO EMPRESA'
and LN_Contrapartes.subcontratista = 0
OPEN PCE
declare @cod_familia varchar(20)
FETCH NEXT FROM PCE INTO @contraparte,@cuit,@pais,@familia,@cod_familia
WHILE @@fetch_status = 0
BEGIN
-- 1001 - Formulario Completado
-- 1) Se le pidio formulario
if (@cod_familia = 'PCE' /* CRITICO EMPRESA */ or
@cod_familia = 'RE' /* REPUESTOS EMPRESAS */
)
begin
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in ( 1005,
1006,
1007,
1008,
1009,
1010,
1011,
1012,
1013,
1064,
1065,
1084)
) != 0)
begin
-- Todavia no lo termino de completar?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1005,
1006,
1007,
1008,
1009,
1010,
1011,
1012,
1013,
1064,
1065,
1084)
and estado_doc in ('I','N','R')) != 0)
begin
set @formulario = 'NO'
set @valor = '2' -- no
end
else
begin
set @formulario = 'SI'
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais, @cod_familia, '1001', @valor)
end
end
if (@cod_familia = 'PCF' /* CRITICO P. FISICA */ OR
@cod_familia = 'RF' /* REPUESTOS P. FISICAS */
)
begin
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in ( 1005,
1006,
1067,
1068,
1009,
1010,
1011,
1012,
1013,
1064,
1069,
1084)
) != 0)
begin
-- Todavia no lo termino de completar?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1005,
1006,
1067,
1068,
1009,
1010,
1011,
1012,
1013,
1064,
1069,
1084)
and estado_doc in ('I','N','R')) != 0)
begin
set @formulario = 'NO'
set @valor = '2' -- no
end
else
begin
set @formulario = 'SI'
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais, @cod_familia, '1001', @valor)
end
end
if (@cod_familia = 'PE' /* ESTRATEGICO */ )
begin
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in ( 1005,
1070,
1071,
1084)
) != 0)
begin
-- Todavia no lo termino de completar?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1005,
1070,
1071,
1084)
and estado_doc in ('I','N','R')) != 0)
begin
set @formulario = 'NO'
set @valor = '2' -- no
end
else
begin
set @formulario = 'SI'
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais, @cod_familia, '1001', @valor)
end
end
if (@cod_familia = 'PCE' /* CRITICO EMPRESA */ or
@cod_familia = 'PCF' /* CRITICO P. FISICA */ or
@cod_familia = 'PE' /* ESTRATEGICO */
)
begin
-- 1007 - CODIGO PARA EVITAR CORRUPCION Y SOBORNO
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1065,1069,1071)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1065,1069,1071)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1007', @valor)
end
end
-- 1008 - DOS ULT. BALANCES O MANIFESTACION DE BIENES (en empresas - documento 1034, en personas fisicas - documento 1080)
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1034,1080)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1034,1080)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1008', @valor)
end
--- 1003 - SLA (SERVICE LEVEL AGREEMENT)
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1074)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1074)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais,@cod_familia, '1003', @valor)
end
--- 1004 - COPIA DE HABILITACION MUNICIPAL
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1081)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1081)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1004', @valor)
end
-- 1006 - PROTOCOLO DE CONTROL DE CALIDAD
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1082)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1082)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1006', @valor)
end
-- 1009 - ACTA APROBACION ULT. BALANCE
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1023)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1023)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais,@cod_familia, '1009', @valor)
end
-- 1010 - ULTIMOS TRES F.931 Y COMPROBANTE DE PAGO
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (3)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (3)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1010', @valor)
end
-- 1011 - ACTA DE DIRECTORIO ESTATUTO Y MODIFICACIONES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1076)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1076)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1011', @valor)
end
-- 1012 - INSCRIPCION EN AFIP ULTIMAS 12 POS IVA Y GANANCIAS
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1063,
1073,
1027)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1063,
1073,
1027)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1012', @valor)
end
-- 1013 - ORGANIGRAMA DE LA SOCIEDAD
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1015)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1015)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1013', @valor)
end
-- 1014 - DETALLE DE LAS ACTIVIDADES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1028)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1028)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1014', @valor)
end
-- 1015 - DDJJ 1 - PAGO DE APORTES IVA GANANCIAS ETC.
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1072)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1072)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1015', @valor)
end
-- 1016 - D DDJJ 2 - PAGO DE SEGUROS
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1086)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1086)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1016', @valor)
end
-- 1082 - SEGURO DE RESPONSABILIDAD CIVIL
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1083)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1083)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1082', @valor)
end
-- 1081 - TERMINOS Y CONDICIONES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1079,1091)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1079,1091)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1081', @valor)
end
-- 1011 - TERMINOS Y CONDICIONES
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1076)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1076)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1011', @valor)
end
-- 1017 - DDJJ 3 - DECLARACION DE CUMPLIMIENTO DE LA LEGISLACION LABORAL VIGENTE
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1087)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1087)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1017', @valor)
end
-- 1018 - DDJJ 4 - CONDUCTA COMERCIAL
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1077,1090)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1077,1090)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento', @cuit, @pais,@cod_familia, '1018', @valor)
end
-- 1019 - INVENTARIO DETALLADO
-- 1) Se le pidio
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and estado_doc not in ('X')
and tipo_doc in (1088)
) != 0)
begin
-- Todavia no lo entrego?
if ((select count(*)
from ln_docs
where contraparte = @contraparte and aplica = 1
and tipo_doc in (1088)
and estado_doc in ('I','N','R')) != 0)
begin
set @valor = '2' -- no
end
else
begin
set @valor = '1' -- si
end
insert into @respuesta values ('documento',@cuit, @pais, @cod_familia, '1019', @valor)
end
-- Respuestas a Preguntas del Formulario
declare @valores table (contraparte int, gestion int, doc_id int, seccion int, campo int, tipo_campo varchar(1), nombre_campo varchar(200), etiqueta varchar(300),fila int, col int, valor_numerico float, valor_texto varchar(max), valor_fecha smalldatetime, valor_fecha_srt varchar(200))
if (@formulario='SI') -- or @formulario='NO')
begin
/*
1022 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (1)
1025 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (2)
1028 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (3)
1031 2.1 ESPECIALIZACION PRODUCTO / ACTIVIDAD (4)
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ESPECIALIZACION_PRODUCTO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia as cod_familia,
case fila
when 1 then 1022
when 2 then 1025
when 3 then 1028
when 4 then 1031
end as item,
case valor_texto
when 'M5' then 1
when 'E25' then 2
when 'N2' then 3
end as valor
from @valores
where col = 3 and isnull(valor_texto,'') != ''
/*
1032 2.2 DATOS DE LOS CENTROS DE TRABAJO
Ya completo el formulario 2? --> Si completo alguno: SI, Si no completo ninguno --> NO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CENTROS_TRABAJO'
if (select count(*) from @valores) > 0 -- Si tiene Centros de Trabajo en su formulario
begin
if ((select count(*)
from @valores
where col = 1
and isnull(valor_texto,'') != '') > 0 )
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1032', @valor)
end
/*
1049 2.3 SUBCONTRATAN HABITUALMENTE ACTIVIDADES PARA LLEVAR A CABO SUS PRODUCTOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'AMX_SUBCONTRATAN'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1049' as item,
case valor_numerico
when 0 then 1 --> no
when 1 then 2 --> si
else 1 --> no
end as valor
from @valores
/*
10501 - TRABAJADORES EN PLANTILLA
*/
/*
declare @valores table (contraparte int, gestion int, doc_id int, seccion int, campo int, tipo_campo varchar(10), nombre_campo varchar(200), etiqueta varchar(200),fila int, col int, valor_numerico float, valor_texto varchar(max), valor_fecha smalldatetime, valor_fecha_srt varchar(200))
declare @contraparte int = 4145
*/
--select * from LN_tipo_doc_campos where campo_id = 'NA_TRABAJADORES'
--select * from ln_campos where etiqueta like 'No tenemos personal'
declare @na char(1) = null, @valor1 int = null, @valor2 int = null, @valor3 int = null
declare @valor1t int = null, @valor2t int = null, @valor3t int = null
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_NO_CALIFICADOS'
set @valor1 = (select isnull(valor_numerico,'0') from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_NO_CALIFICADOS_TEMP'
set @valor1t = (select isnull(valor_numerico,'0') from @valores)
if (@valor1 is not null or @valor1t is not null)
set @valor1 = isnull(@valor1,0) + isnull(@valor1t,0)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_PROFESIONALES'
set @valor2 = (select isnull(valor_numerico,'0') from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_PROFESIONALES_TEMP'
set @valor2t = (select isnull(valor_numerico,'0') from @valores)
if (@valor2 is not null or @valor2t is not null)
set @valor2 = isnull(@valor2,0) + isnull(@valor2t,0)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_ADMINISTRATIVOS'
set @valor3 = (select isnull(valor_numerico,'0') from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TRABAJADORES_ADMINISTRATIVOS_TEMP'
set @valor3t = (select isnull(valor_numerico,'0') from @valores)
if (@valor3 is not null or @valor3t is not null)
set @valor3 = isnull(@valor3,0) + isnull(@valor3t,0)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'NA_TRABAJADORES'
set @na = (select isnull(valor_texto,'0') from @valores)
if (@na is not null or (@valor1 is not null and @valor2 is not null and @valor3 is not null))
begin
if (@na = 1)
begin
set @valor = 3
end
else
begin
if (@valor1 < (@valor2 + @valor3))
set @valor = 1
else
set @valor = 2
end
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '10501', @valor)
end
/*
1054 2.5 NUMERO DE ALTAS Y BAJAS DEL ULTIMO AÑO
*/
declare @despido int = null
declare @retiro INT = null
declare @otros int = null
declare @bajas int = null
declare @altas int = null
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'BAJA_DESPIDO'
set @despido = (select isnull(valor_numerico,0) from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'BAJA_RETIRO'
set @retiro = (select isnull(valor_numerico,0) from @valores)
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'BAJA_OTROS_MOTIVOS'
set @otros = (select isnull(valor_numerico,0) from @valores)
set @bajas = @despido + @retiro + @otros
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ALTAS_PERSONAL'
set @altas = (select isnull(valor_numerico,0) from @valores)
set @valor = null
if (isnull(@altas,0) < isnull(@bajas,0)) set @valor = 1
if (isnull(@altas,0) = isnull(@bajas,0))
begin
set @valor = 2
end
else
begin
if (isnull(@altas,0) > isnull(@bajas,0) AND isnull(@altas,0) < isnull(@bajas,0) * 1.5) set @valor = 3
if (isnull(@altas,0) >= isnull(@bajas,0) * 1.5 AND isnull(@altas,0) < isnull(@bajas,0) * 2) set @valor = 4
if (isnull(@altas,0) >= isnull(@bajas,0) * 2) set @valor = 5
end
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'NA_ALTAS_BAJAS'
if (select case isnull(valor_texto,0)
when 1 then 1
else 0
end from @valores) = 1 set @valor = 6
if (@valor is not null) insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1054', @valor)
/*
1059 - 2.6 CUENTAN CON PROGRAMAS ANUALES DE DESARROLLO Y FORMACION DEL PERSONAL
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PROGRAMA_DESARROLLO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1059' as item,
case valor_texto
when '1' then 1 --> si
when '0' then 2 --> no
when '3' then 3 --> n/a
else '3' --> n/a
end as valor
from @valores
/*
1066 - CONFLICTOS LABORALES EN LOS ULTIMOS 2 AÂ¥OS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONFLICTOS_LABORALES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1066' as item,
case valor_texto
when 'S' then 1 --> si, entre 1 y 5
when 'M' then 2 --> si, mas de 5
when 'N' then 3 --> no
else 3 --> n/a
end as valor
from @valores
/*
1068 - DEPARTAMENTO DE INVESTIGACION Y DESARROLLO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'DPTO_INVESTIGACION_DESARROLLO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1068' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1069 - PATENTADOS DESAROLLOS TECNICOS O TECNOLOGICOS PROPIOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PATENTADOS_DESAROLLOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1069' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1071 3.3 COMUNICACION / VENTA: E-MAIL
1072 3.3 COMUNICACION / VENTA: CATALOGO DE PRODUCTOS
1073 3.3 COMUNICACION / VENTA: VENTA TELEFONICA
1074 3.3 COMUNICACION / VENTA: WEB INFORMATIVA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'TECNOLOGIA_COMUNICACION'
if (select count(*) from @valores) > 0
begin
if (select count(*) from @valores where valor_texto like '%E%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1071', @valor)
-- catalogo
if (select count(*) from @valores where valor_texto like '%C%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1072', @valor)
-- venta telefonica
if (select count(*) from @valores where valor_texto like '%T%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1073', @valor)
-- web
if (select count(*) from @valores where valor_texto like '%W%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1074', @valor)
end
/*
1076 - COMUNICACION CON AMX: TELEFONO
1077 - COMUNICACION CON AMX: E-MAIL
1078 - COMUNICACION CON AMX: INTERNET
1079 - COMUNICACION CON AMX: SUBASTA ELECTRONICA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'COMUNICACION_AMX'
if (select count(*) from @valores) > 0
begin
-- telefono
if (select count(*) from @valores where valor_texto like '%T%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1076', @valor)
if (select count(*) from @valores where valor_texto like '%E%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1077', @valor)
-- internet
if (select count(*) from @valores where valor_texto like '%I%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1078', @valor)
-- subasta electronica
if (select count(*) from @valores where valor_texto like '%S%') > 0 set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1079', @valor)
end
/*
1083 - PROCESO HOMOLOGACION DE PROVEEDORES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'HOMOLOGACION_PROVEEDORES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1083' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1085 - PORCENTAJE DE COMPRAS A PROVEEDORES HOMOLOGADOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PROCENTAJE_PROVEEDORES_HOMOLOGADOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1085' as item,
case
when valor_numerico > 75 then 4
when valor_numerico >= 50 and valor_numerico < 75 then 3
when valor_numerico >= 25 and valor_numerico < 50 then 2
else 1
end as valor
from @valores
/*
1086 - EVALUAN SERVICIO DE PROVEEDORES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EVALUAN_PROVEEDORES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1086' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1089 - TIENEN ASEGURADOS SUMINISTROS DE PRODUCTOS CRITICOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ASEGURADOS_SUMINISTROS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1089' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1091 - AMBITO GEOGRAFICO DE SUMINISTRO: CAPITAL FEDERAL
1092 - AMBITO GEOGRAFICO DE SUMINISTRO: GRAN BUENOS AIRES
1093 - AMBITO GEOGRAFICO DE SUMINISTRO: INTERIOR DEL PAIS
1094 - AMBITO GEOGRAFICO DE SUMINISTRO: EXTERIOR
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'AMBITO_GEOGRAFICO'
if (select count(*) from @valores) > 0
begin
-- capital
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item = '0')> 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1091', @valor)
-- Buenos Aires
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item = '1')> 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1092', @valor)
-- Interior del Pais (tiene cargado algo que no es Capital, ni Buenos Aires, ni exterior)
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item not in ('0','1','25')) > 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1093', @valor)
-- Exterio
if ((select count(*) from DelimitedSplit8K ((select valor_texto from @valores),',') where item = '25')> 0) set @valor = 1 else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1092', @valor)
end
/*
1095 - SISTEMA INFORMATIZADO DE CONTROL DE INVENTARIO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTROL_INVENTARIO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1095' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1096 - CONTROL INTERNO PERIODICO SOBRE LOS NIVELES DE INVENTARIO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTROL_NIVEL_INVENTARIO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1096' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1097 - CONTROL EXTERNO DE INVENTARIO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTROL_EXTERNO_INVENTARIO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1097' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1098 - CERTIFICADO ISO-9000
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ISO_9000'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1098' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1101 - OTRO CERTIFICADO DE CALIDAD
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'OTRO_CERTIFICADO_CALIDAD'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1101' as item,
case valor_texto
when 'N' then 1 --> NO
when 'O' then 2 --> 1
when 'M' then 3 --> mas de 1
else 1 --> no
end as valor
from @valores
/*
1111 - ANTIGUEDAD EQUIPO PRODUCTIVO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ANTIGUEDAD_EQUIPO_PRODUCTIVO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1111' as item,
case valor_texto
when 'M5' then 1 --> menos de 5
when 'M10' then 2 --> entre 5 y 10
when 'M20' then 3 --> entre 10 y 20
when 'Y20' then 4 --> mas de 20
when 'N' then 5 --> no aplica
else 5 --> no aplica
end as valor
from @valores
/*
1112 - PROGRAMA DE MANTENIMIENTO PREVENTIVO DE EQUIPO PRODUCTIVO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MANTENIMIENTO_PREVENTIVO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1112' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
PORCENTAJE_INVERSION
/*
1113 - PORCENTAJE DE INVERSION EN EQUIPOS PRODUCTIVOS
0-10|E10-30|E30-50|M50|N
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ANTIGUEDAD_EQUIPO_PRODUCTIVO'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1113' as item,
case valor_texto
when '0-10' then 1 --> menos de 10
when 'E10-30' then 2 --> entre 10 y 30
when 'E30-50' then 3 --> entre 30 y 50
when 'M50' then 4 --> mas de 50
when 'N' then 5 --> no aplica
else 5 --> no aplica
end as valor
from @valores
/*
1119 - INFORMA PRINCIPALES CLIENTES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PRINCIPALES_CLIENTES'
if (select count(*) from @valores) > 0
begin
if ((select count(*)
from @valores
where col = 1
and isnull(valor_texto,'') != '') > 0 )
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '1119', @valor)
end
/*
1124 - INFORMA PRINCIPALES PROVEEDORES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PRINCIPALES_PROVEEDORES'
if (select count(*) from @valores) > 0
begin
if ((select count(*)
from @valores
where col = 1
and isnull(valor_texto,'') != '') > 0 )
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais,@cod_familia, '1124', @valor)
end
/*
11142 - PORCENTAJE DE CLIENTES EN EL SECTOR TELECOMUNICACIONES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'SECTORES_CLIENTES'
if (select count(*) from @valores) > 0
begin
if ((select isnull(valor_numerico,'0')
from @valores
where col = 1) >
(select sum(isnull(valor_numerico,'0'))
from @valores
where col > 1 ))
set @valor = 1
else set @valor = 2
insert into @respuesta values ('pregunta', @cuit, @pais, @cod_familia, '11142', @valor)
end
/*
1129 - SERVICIO DE POST-VENTA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'SERVICIO_POSTVENTA'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1129' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1131 - AREA DE ATENCION AL CLIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ATENCION_CLIENTE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1131' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1133 - PROCESO DE MEDICION DE SATISFACCION
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'SATISFACCION_CLIENTES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1133' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1135 - NORMAS SOBRE CONSERVACION MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MEDIO_AMBIENTE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1135' as item,
case valor_texto
when 'S' then 1 --> si
when 'E' then 2 --> en proceso
when 'N' then 3 --> no
when 'X' then 4 --> no aplica
else 3 --> no
end as valor
from @valores
/*
1138 9.2 EXPEDIENTE DISCIPLINARIO POR INCUNPLIMIENTO NORMAS DE MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EXPEDIENTE_DISCIPLINARIO'
if (select count(*) from @valores) > 0
begin
set @valor = null
set @valor = (select case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores)
if (@valor is not null)
begin
if (@valor = 2)
begin
insert into @respuesta values ('pregunta',@cuit,@pais,@cod_familia, '1138',1)
end
else
begin
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EXPEDIENTE_DISCIPLINARIO_CORRECCION'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1138' as item,
case valor_numerico
when 1 then 2 --> si, y han tomado medidas
when 0 then 3 --> si, y no han tomado medidas
else 3 --> si, y no han tomado medidas
end as valor
from @valores
end
end
end
/*
1140 - CERTIFICADO ISO 14001 SOBRE MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'ISO_14001'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1140' as item,
case valor_texto
when 'S' then 1 --> si
when 'N' then 2 --> no
when 'X' then 3 --> no aplica
else 2 --> no
end as valor
from @valores
/*
1141 - MEDIDAS INTERNAS QUE CONTRIBUYEN A LA PRESERVACION DEL MEDIO AMBIENTE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MEDIDAS_PRESERVACION_MEDIO_AMBIENTE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1141' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1143 - MEDIDAS SALUD E HIGIENE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'MEDIDAS_SALUD_HIGIENE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1143' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1145 - CONTRATACION PERSONAS SECTORES DESFAVORECIDOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CONTRATAN_SECTORES_DESFAVORECIDOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1145' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1146 - PARTICIPAN INSTITUCIONES RELACIONADAS CON EL FOMENTO DE LA CULTURA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'FOMENTO_CULTURA'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1146' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1157 - PLAN DE CONTINGENCIA
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'PLAN_CONTINGENCIA'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1157' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1159 - DE CUANTOS PROVEEDORES DEPENDE
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'DE_CUANTOS_PROVEEDORES_DEPENDE'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1159' as item,
case valor_texto
when '3' then 1 --> hasta 3
when '4' then 2 --> de 4
when '5' then 3 --> mas de 5
else 1
end as valor
from @valores
/*
1160 - HAN TENIDO ALGUNA EXPERIENCIA DONDE HAYAN PODIDO COMPROBAR SU CAPACIDAD ANTE CRISIS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'EXPERIENCIA_CRISIS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1160' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1168 - CODIGO DE CONDUCTA PARA EVITAR VULNERACIONES DE LOS DERECHOS HUMANOS
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CODIGO_CONDUCTA_DERECHOS_HUMANOS'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1168' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1169 - CODIGO DE CONDUCTA O POLITICA PARA EVITAR LA CORRUPCION Y SOBORNO
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CODIGO_CONDUCTA_CORRUPCION'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1169' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
/*
1170 - EN CUESTIONARIOS DE HOMOLOGACION A SUS PROVEEDORES INCLUYEN CRITERIOS AMBIENTALES Y SOCIALES
*/
delete from @valores
insert into @valores exec ln_docs_valores @contraparte, 'CRITERIOS_AMBIENTALES'
insert into @respuesta
select 'pregunta' as tipo,
@cuit as cuit,
@pais as pais,
@cod_familia,
'1170' as item,
case valor_numerico
when 1 then 1 --> si
when 0 then 2 --> no
else 2 --> no
end as valor
from @valores
end
FETCH NEXT FROM PCE INTO @contraparte,@cuit,@pais,@familia,@cod_familia
END
CLOSE PCE
DEALLOCATE PCE
if (@formulario='SI')
begin
select convert(char(7), getdate(),120) as periodo, * from @respuesta where tipo = 'documento'
union
select convert(char(7), getdate(),120) as periodo, * from @respuesta where tipo = 'pregunta'
order by 3,4,5
end
else
begin
-- Si todavia no completo el formulario, solo manda los documentos ya verificados
select convert(char(7), getdate(),120) as periodo, * from @respuesta where tipo = 'documento' and valor = 1
order by 3,4,5
end
END
END
GO
Depends On
13Used By
No items found