dbo.LN_actualiza_fidecheck

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

6
Name Data Type Length Description
@contraparte int 4
@cuit varchar 20
@seccion varchar 1
@fidecheck char 1
@detalle varchar -1
@idr int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
select * from clientes where cli_codigo = 2000
select * from LN_demo_fidecheck where contraparte = 32103 and seccion = 'P'

update LN_demo_fidecheck set fidecheck = '' where contraparte = 32103 and seccion = 'P'
select * from LN_contrapartes where cliente = 2046807993 order by contraparte desc
[ln_completa_fidecheck] 32103
*/

CREATE OR ALTER PROCEDURE dbo.LN_actualiza_fidecheck  
@contraparte int, 
@cuit        varchar(20), 
@seccion     varchar(1), 
@fidecheck   char(1),
@detalle     varchar(max),
@idr      int = null 
AS
BEGIN
  SET NOCOUNT ON;

  declare @gestion int = 0 
  set @gestion = (select gestion 
    from LN_gestiones 
    where contraparte = @contraparte 
    AND LN_gestiones.desde <= GETDATE()
    AND LN_gestiones.hasta >= GETDATE()
    and ln_gestiones.vigente = 1 )


  update LN_demo_fidecheck 
     set fidecheck = @fidecheck,
      detalle   = @detalle, 
      modified = GETDATE(), 
      id_resultado = @idr
   where contraparte = @contraparte 
     and tax_id      = @cuit
     and seccion     = @seccion 
     and gestion = @gestion 


/* select * from ln_contrapartes where id_padron=1963852 and activo=1
select * from LN_demo_fidecheck where contraparte in (select contraparte from ln_contrapartes where id_padron=1963852 and activo=1) and tax_id='20303340883'
select * from LN_demo_fidecheck where contraparte in (select contraparte from ln_contrapartes where id_padron=1963852 and activo=1) and tax_id='20303340883'
-- insert into ln_contrapartes_queue (contraparte) values(145706)
select * from ln_contrapartes_queue where contraparte=145706 order by created desc


*/

/*
select LN_demo_fidecheck.id_fidecheck,LN_demo_fidecheck.*
from ln_contrapartes inner join LN_gestiones on ln_contrapartes.contraparte = ln_gestiones.contraparte 
inner join LN_demo_fidecheck on ln_gestiones.gestion=LN_demo_fidecheck.gestion
where id_padron in (select id_padron from ln_contrapartes where contraparte = 107682) and ln_contrapartes.activo=1 and ln_gestiones.vigente=1
and LN_demo_fidecheck.tax_id='20303340883'
and LN_demo_fidecheck.seccion='D'
*/

/* BUSCO OTRAS CONTRAPARTES QUE SEAN EL MISMO CUIT Y ACTUALIZO EL FIDECHECK A TODOS LOS REGISTROS QUE HAYA NO IMPORTA PARA QUE CLIENTE SE HAYA HECHO */
  
  update LN_demo_fidecheck 
     set fidecheck = @fidecheck,
      detalle   = @detalle, 
      modified = GETDATE(), 
      id_resultado = @idr
   where id_fidecheck in (select LN_demo_fidecheck.id_fidecheck
  from ln_contrapartes 
  inner join LN_gestiones on ln_contrapartes.contraparte = ln_gestiones.contraparte 
  inner join LN_demo_fidecheck on ln_gestiones.gestion=LN_demo_fidecheck.gestion
  -- 25/06/2024: si el cliente esta activo
  inner join clientes CL on (CL.cliente = ln_contrapartes.cliente and CL.estado_cliente='A')
  -- 
  where ln_contrapartes.id_padron in (select id_padron from ln_contrapartes where contraparte = @contraparte) 
  and ln_contrapartes.activo=1 and ln_gestiones.vigente=1
  and LN_demo_fidecheck.tax_id=@cuit
  and LN_demo_fidecheck.seccion=@seccion 
  )

/* MANDO AL QUEUE TODA CONTRAPARTE QUE SE ESTE ACTUZALIZANDO PARA QUE SE REFLEJE EL CAMBIO EN EL PANEL DE CONTROL  */


  INSERT INTO LN_contrapartes_queue (CONTRAPARTE,id_taken)
  select distinct LN_demo_fidecheck.contraparte, 1.0 + floor(10 * RAND(convert(varbinary, newid()))) as id_taken
  from ln_contrapartes 
  inner join LN_gestiones on ln_contrapartes.contraparte = ln_gestiones.contraparte
  inner join LN_demo_fidecheck on ln_gestiones.gestion=LN_demo_fidecheck.gestion
  -- 25/06/2024: si el cliente esta activo, y tienen que ir al queue
  inner join clientes CL on   (CL.cliente = ln_contrapartes.cliente and CL.estado_cliente='A')
  inner join clientes_productos CP on (CP.cliente = ln_contrapartes.cliente and CP.id_producto = 47 and CP.activo = 1 and CP.no_queue != 1) 
  -- 
  where ln_contrapartes.id_padron in (select id_padron from ln_contrapartes where contraparte = @contraparte) 
  and ln_contrapartes.activo=1 and ln_gestiones.vigente=1
  and LN_demo_fidecheck.tax_id=@cuit
  and LN_demo_fidecheck.seccion=@seccion 
  and not exists (select * from LN_contrapartes_queue where contraparte = LN_demo_fidecheck.contraparte and processed = 0)


END 

GO

Used By

No items found