Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.MisAportes2DeudaExigible
AS
BEGIN
SET NOCOUNT ON;
DELETE deuda_previsional WHERE VISIBLE=1 AND CUIT IN (
SELECT distinct cuit_empleador from mis_aportes where /*aportes_ss not in ('PAGO','-') and */ inserted > '2021-11-30 17:50:05.750'
and cuit_empleador in (select distinct identificacion from ln_contrapartes inner join padrones on ln_contrapartes.id_padron=padrones.id_padron where cliente In (select cliente from clientes where cli_codigo!=0) and activo = 1))
insert into deuda_previsional (cuit,periodo,codigo,fecha_info/*,created*/)
select distinct MISAP1.cuit_empleador as cuit,MISAP1.periodo,301 as codigo,convert(date,getdate()) as fecha_info from mis_aportes MISAP1 inner join (select max(id_aportes) as idAP, cuit_empleador,periodo from mis_aportes where cuit_empleador /*='30525733870'*/ in (select distinct identificacion from ln_contrapartes inner join padrones on ln_contrapartes.id_padron=padrones.id_padron where cliente In (select cliente from clientes where cli_codigo!=0) and activo = 1) group by cuit_empleador,periodo) MISAP2 on MISAP1.id_aportes=MISAP2.idAP
where MISAP1.aportes_ss not in ('PAGO','-','NO PRESENTADO') and inserted > '2021-11-30 17:50:05.750'
union
select distinct MISAP1.cuit_empleador as cuit,MISAP1.periodo,351 as codigo,convert(date,getdate()) as fecha_info from mis_aportes MISAP1 inner join (select max(id_aportes) as idAP, cuit_empleador,periodo from mis_aportes where cuit_empleador /*='30525733870'*/ in (select distinct identificacion from ln_contrapartes inner join padrones on ln_contrapartes.id_padron=padrones.id_padron where cliente In (select cliente from clientes where cli_codigo!=0) and activo = 1) group by cuit_empleador,periodo) MISAP2 on MISAP1.id_aportes=MISAP2.idAP
where MISAP1.contr_patronal not in ('PAGO','-','NO PRESENTADO') and inserted > '2021-11-30 17:50:05.750'
group by cuit, MISAP1.cuit_empleador,MISAP1.periodo,aportes_ss,contr_patronal
insert into fuentes_procesadas (fecha_informacion,fuente,visible,created )
select getdate() as fecha_informacion,'DEUDAAPORTES' as fuente,1 as visible,getdate() as created
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.MisAportes2DeudaExigible
AS
BEGIN
SET NOCOUNT ON;
DELETE deuda_previsional WHERE VISIBLE=1 AND CUIT IN (
SELECT distinct cuit_empleador from mis_aportes where /*aportes_ss not in ('PAGO','-') and */ inserted > '2021-11-30 17:50:05.750'
and cuit_empleador in (select distinct identificacion from ln_contrapartes inner join padrones on ln_contrapartes.id_padron=padrones.id_padron where cliente In (select cliente from clientes where cli_codigo!=0) and activo = 1))
insert into deuda_previsional (cuit,periodo,codigo,fecha_info/*,created*/)
select distinct MISAP1.cuit_empleador as cuit,MISAP1.periodo,301 as codigo,convert(date,getdate()) as fecha_info from mis_aportes MISAP1 inner join (select max(id_aportes) as idAP, cuit_empleador,periodo from mis_aportes where cuit_empleador /*='30525733870'*/ in (select distinct identificacion from ln_contrapartes inner join padrones on ln_contrapartes.id_padron=padrones.id_padron where cliente In (select cliente from clientes where cli_codigo!=0) and activo = 1) group by cuit_empleador,periodo) MISAP2 on MISAP1.id_aportes=MISAP2.idAP
where MISAP1.aportes_ss not in ('PAGO','-','NO PRESENTADO') and inserted > '2021-11-30 17:50:05.750'
union
select distinct MISAP1.cuit_empleador as cuit,MISAP1.periodo,351 as codigo,convert(date,getdate()) as fecha_info from mis_aportes MISAP1 inner join (select max(id_aportes) as idAP, cuit_empleador,periodo from mis_aportes where cuit_empleador /*='30525733870'*/ in (select distinct identificacion from ln_contrapartes inner join padrones on ln_contrapartes.id_padron=padrones.id_padron where cliente In (select cliente from clientes where cli_codigo!=0) and activo = 1) group by cuit_empleador,periodo) MISAP2 on MISAP1.id_aportes=MISAP2.idAP
where MISAP1.contr_patronal not in ('PAGO','-','NO PRESENTADO') and inserted > '2021-11-30 17:50:05.750'
group by cuit, MISAP1.cuit_empleador,MISAP1.periodo,aportes_ss,contr_patronal
insert into fuentes_procesadas (fecha_informacion,fuente,visible,created )
select getdate() as fecha_informacion,'DEUDAAPORTES' as fuente,1 as visible,getdate() as created
END
GO