dbo.obtener_activo_contables

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

3
Name Data Type Length Description
@p_Cuit varchar 20
@p_todos varchar 1
@ids varchar 100

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
obtener_activo_contables null,null,'0,366137,366139,366140,366138'
[obtener_activo_contables] '30692845605', 'S'
*/


CREATE OR ALTER PROCEDURE dbo.obtener_activo_contables 
@p_Cuit varchar(20), 
@p_todos varchar(1) = 'N',
@ids varchar(100) = NULL 
AS

BEGIN
       SET NOCOUNT ON;
      SET ANSI_PADDING ON
      SET ANSI_WARNINGS ON
      SET CONCAT_NULL_YIELDS_NULL ON 
    /*
        SELECT top 5 convert(varchar(10),balances_fide.fecha_balance,103) as fecha_balance, isnull(ac_cajban,0) as caja_y_bancos, isnull(ac_inver,0) as inversiones_corrientes , isnull(ac_crevta,0) as anc_creditos_por_ventas, isnull(ac_otrcre,0) as otros_creditos, isnull(ac_biecam,0) as bienes_de_cambio, isnull(ac_bietan,0) as bienes_intangibles, isnull(ac_otract,0) as otros_activos_corrientes,
        (isnull(ac_cajban,0) +  isnull(ac_inver,0)  +  isnull(ac_crevta,0) +  isnull(ac_otrcre,0) +  isnull(ac_biecam,0) + isnull(ac_bietan,0) + isnull(ac_otract,0) ) as total_activo_corriente,
        datepart(YEAR,fecha_balance) as anio,
     isnull(anc_crevta,0) as creditos_por_ventas,isnull(anc_otrcre,0) as otros_creditos_no_corrientes, isnull(anc_inver,0) as otras_inversiones_no_corrientes, isnull(anc_bieusovo,0) as bienes_de_uso_valor_de_origen,isnull(anc_depacu,0) as depreciacion_acumulada,isnull(anc_bieuso,0) as bienes_de_uso, isnull(anc_actint,0) as activo_intangibles,isnull(anc_otract,0) as otros_activos_no_corrientes,
     (isnull(anc_crevta,0) + isnull(anc_otrcre,0) +  isnull(anc_inver,0) +  isnull(anc_bieuso,0) +  isnull(anc_actint,0) + isnull(anc_otract,0) ) as total_activo_no_corriente,
    
     (isnull(ac_cajban,0) +  isnull(ac_inver,0)  +  isnull(ac_crevta,0) +  isnull(ac_otrcre,0) +  isnull(ac_biecam,0) + isnull(ac_bietan,0) + isnull(ac_otract,0) ) + (isnull(anc_crevta,0) + isnull(anc_otrcre,0) +  isnull(anc_inver,0) +  isnull(anc_bieuso,0) +  isnull(anc_actint,0) + isnull(anc_otract,0) ) as total_activo
    
     from balances_fide where cuit = @p_cuit and datediff(YY,fecha_balance,getdate()) < 7 and visible = 1  ORDER BY FECHA_BALANCE DESC
    */


  if(ISNULL(@ids,'') != '')
  BEGIN
    set @ids  = '0,'+@ids 
  /*
      declare @data xml
      declare @temp table(id int)
      select @data = '<t>' + replace(@ids, ',', '</t><t>') + '</t>'
      insert into @temp
             select t.c.value('.', 'int') as id
             from @data.nodes('t') as t(c)
    */

    SELECT convert(varchar(10),bc.fecha_balance,103) as fecha_balance,fecha_balance as fecha_order,
   bc.ac_cajban,
   bc.ac_inver, 
   bc.ac_crevta, 
   bc.ac_otrcre, 
   bc.ac_biecam, 
   bc.ac_bietan, 
   bc.ac_otract,
   bc.anc_crevta, 
   bc.anc_otrcre, 
   bc.anc_inver, 
   bc.anc_bieusovo, 
   bc.anc_depacu, 
   bc.anc_bieuso, 
   bc.anc_actint, 
   bc.anc_otract, 
   bc.ac_total, 
   bc.anc_total,
   bc.act_total,
   monedas.nombre_moneda,
   bc.ruta_archivo

    from balances_contables as bc inner join monedas on bc.moneda = monedas.moneda 
    inner join dbo.DelimitedSplit8K(@ids, ',') lista on bc.id_balance= lista.Item
      where --id_balance in (SELECT id FROM @temp) AND 
      isnull(bc.visible,0) = 1
      AND isnull(estado,'') = 'PUBLICADO'
      order by fecha_order 
  END 
  ELSE
  BEGIN
      declare @p_top int = 5 
      if (@p_todos = 'S') begin set @p_top = 6 end 
      SELECT top (@p_top)  
      bc.estado as estado, 
    convert(varchar(10),bc.fecha_balance,103) as fecha_balance,fecha_balance as fecha_order,
   bc.ac_cajban,
   bc.ac_inver, 
   bc.ac_crevta, 
   bc.ac_otrcre, 
   bc.ac_biecam, 
   bc.ac_bietan, 
   bc.ac_otract,
   bc.anc_crevta, 
   bc.anc_otrcre, 
   bc.anc_inver, 
   bc.anc_bieusovo, 
   bc.anc_depacu, 
   bc.anc_bieuso, 
   bc.anc_actint, 
   bc.anc_otract, 
   bc.ac_total, 
   bc.anc_total,
   bc.act_total,
   monedas.nombre_moneda,
   bc.ruta_archivo

    from balances_contables as bc inner join monedas on bc.moneda = monedas.moneda 
    where bc.cuit = @p_cuit and bc.fecha_balance >= convert(date,dateadd(yy, -6, getdate()))
    AND (@p_todos = 'S' or isnull(bc.visible,0) = 1)
    AND isnull(estado,'') != 'ELIMINADO'
    order by fecha_order DESC, id_balance desc
  END 

END

--'30501677643'

GO

Used By

No items found