dbo.ln_balances_cargados

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

9
Name Data Type Length Description
@Userid int 4
@accion varchar 50
@gestion int 4
@doc_id int 4
@desde date 3
@hasta date 3
@contraparte int 4
@fecha_cierre date 3
@periodicidad char 1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDUREdbo.ln_balances_cargados 
@Userid int, 
@accion varchar(50),
@gestion int = null, 
@doc_id int = null, 
@desde date = null, 
@hasta date = null,
@contraparte int = null, 
@fecha_cierre date = null, 
@periodicidad char(1) = null 
AS
BEGIN
 SET NOCOUNT ON;
 declare @cliente int = null 

 if (@accion = 'select')
 begin
  select doc_id, estado_doc, convert(date,inicio_ejercicio) as inicio_ejercicio, convert(date,fin_ejercicio) as fin_ejercicio, 
         id_externo, balances_contables.ruta_archivo, balances_contables.estado
    from ln_docs 
    left join balances_contables on balances_contables.id_balance = ln_docs.id_externo
    where gestion = @gestion and es_balance = 1 and aplica = 1 and estado_doc != 'X'
    select 'ok'
    return
 end

 if (@accion = 'update')
 begin
  select @cliente = cliente from ln_contrapartes where contraparte = @contraparte 

  update ln_docs 
     set inicio_ejercicio = @desde, fin_ejercicio = @hasta, fecha_vigencia = @hasta 
   where doc_id = @doc_id 

  declare @id_externo int = null 
  set @id_externo = (select id_externo from ln_docs where doc_id = @doc_id) 
  if (@id_externo is not null)
  begin
   update balances_contables 
      set fecha_balance = @hasta 
    where id_balance = @id_externo
  end

  EXEC insertar_trazabilidad 'Cambio Fecha Balance en documentos', @cliente, 'CAMBIO_FECHA_BALANCE', 'WWW', @contraparte, @Userid
  
  select 'ok'
  return
 end

 if (@accion = 'update_contrapartes')
 begin
  select @cliente = cliente from ln_contrapartes where contraparte = @contraparte 

  update ln_contrapartes
     set fecha_ultimo_cierre = @fecha_cierre, 
         periodicidad_ejercicio = @periodicidad
   WHERE contraparte = @contraparte
  
  EXEC insertar_trazabilidad 'Cambio Fecha Balance en contraparte', @cliente, 'CAMBIO_FECHA_BALANCE', 'WWW', @contraparte, @Userid

  select 'ok'
  return
 end
END
/*
select * from clientes where cli_codigo = 8907
select * from ln_docs where contraparte in (3994) 
and es_balance = 1

select * from ln_contrapartes where contraparte = 3994
select * from padrones where id_padron = 32356855

select * from balances_contables where cuit = '30710491026' and id_balance in (366553,366545,366546)
*/

/*
exec [ln_balances_cargados] 'update_contrapartes', NULL, NULL, NULL, NULL,'3994','1901-11-30','A'
exec [ln_balances_cargados] 'update',null,'3291','2014-12-01','2015-11-30'
*/

GO

Used By

No items found