dbo.obtener_nivel_socioeconomico_2021_MIS

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

4
Name Data Type Length Description
@identificacion varchar 20
@tipo_persona char 1
@es_macro bit 1
@p_cliente int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*

exec [obtener_nivel_socioeconomico_2021]  '20146830502','f'
exec [obtener_nivel_socioeconomico_2021]  '30703370515 ','j'
exec [obtener_nivel_socioeconomico_2021]  '30702145895 ','j'
exec obtener_nivel_socioeconomico_2021 '30500711732','j'
exec obtener_nivel_socioeconomico_2021_MIS '30626022576','j'

exec obtener_nivel_socioeconomico_2021_MIS '30555414222','j'

select * from niveles_socioeconomicos where monto_maximo = 5000000000

 */

 
/* 
select cli_codigo,cliente,nombre_cliente,estado_cliente from clientes where nombre_cliente like '%claves%'

select * from niveles_socioeconomicos where id_cliente = 340354200 --claves=340354200

select DISTINCT CUIT from consultar_afip where proceso='PROCESOS_MASIVOS' AND FECHA='2021-12-23'
select * from datos_personas WHERE c01_cuit IN (select DISTINCT CUIT from consultar_afip where proceso='PROCESOS_MASIVOS' AND FECHA='2021-12-23') AND fecha_defuncion IS NULL
*/


-- select * from niveles_socioeconomicos ORDER BY monto_maximo ASC where monto_minimo=2340000

CREATE OR ALTER PROCEDURE dbo.obtener_nivel_socioeconomico_2021_MIS
@identificacion varchar(20),
@tipo_persona char(1),
@es_macro bit = 1, 
@p_cliente int = null



AS
BEGIN
 SET NOCOUNT ON;
  declare @sueldo bigint = 0
  declare @monotributo int = 0
  declare @iva int = 0
  declare @autonomo int = 0
  declare @monto_autonomo int = 0
  declare @monto_socio int = 0
  declare @sueldo_empleados int = 0
  declare @id_padron int
  declare @ultimo_mes_empleados date
  declare @mes_empleados date
  declare @periodo_empleados_desde int 
  declare @periodo_empleados_hasta int 
  declare @rango_min bigint
  declare @rango_max bigint
  declare @total  decimal(18,4) = 0
  declare @max bigint = 0
  declare @max_general bigint = 0
  declare @nombre varchar(100)
  declare @periodo_viejo int = 0
  declare @cod_ramo int
  declare @porcentaje_afectacion float = null
  declare @valor_nomina  decimal(18,4)
  declare @valor_nomina_inicial  decimal(18,4)
  declare @valor_nomina_vieja  decimal(18,4)
  declare @porcentaje_ipc  float
  declare @ventas decimal(18,4)
  declare @ventas_totales decimal(18,4)
  declare @fecha_balance int = 0
  declare @cantidad_nomina int
  declare @provincia varchar(100)
  declare @cliente smallint = 0
  declare @fecha_importaciones date
  declare @fecha_exportaciones date
  declare @comex_importaciones decimal(18,4)
  declare @comex_exportaciones decimal(18,4)
  declare @fecha_nomina_mas_reciente int
  declare @factor decimal(18,4)
  declare @argenta bit
  declare @riesgo_fiscal bit
  declare @es_empleador int
  declare @es_empleado int
  declare @cuit varchar(20)
  
  declare @fec_periodo_minimo varchar(11),
             @periodo_minimo varchar(7)


set @p_cliente=340354200



  set @fec_periodo_minimo = dateadd(MM, -23,getdate())
  set @periodo_minimo = convert(varchar(4),DATEPART(yyyy,@fec_periodo_minimo))+right('0'+convert(varchar(2),DATEPART(mm,@fec_periodo_minimo)),2)
  if(@es_macro = 1)
  begin
   set @cliente = (select count(*) from cendeu_temp where convert(int,codigo_ent) in (285) and iden = @identificacion and vigente = 1 and fec_inf >= @periodo_minimo)
   if(@cliente = 0)
   begin
    set @cliente = (select count(*) from cendeu where convert(int,codigo_ent) in (285) and iden = @identificacion and vigente = 1 and fec_inf >= @periodo_minimo)
   end
  end
  
  SET @nombre = (select nombre_persona from padrones where identificacion = @identificacion and habilitado = 1 and identificador in (select identificador from identificadores where country_code='AR'))
    
  set @ultimo_mes_empleados = (select max(fuentes_procesadas.fecha_informacion) from fuentes_procesadas where fuente = 'empleados')
  set @periodo_empleados_hasta = convert(int,substring(convert(char,@ultimo_mes_empleados),3,2)+substring(convert(char,@ultimo_mes_empleados),6,2))

  set @mes_empleados = DATEADD(M,-7,@ultimo_mes_empleados)
  set @periodo_empleados_desde = convert(int,substring(convert(char,@mes_empleados),3,2)+substring(convert(char,@mes_empleados),6,2))
  
  set @id_padron = (select id_padron from padrones where identificacion = @identificacion and habilitado = 1 and identificador in (select identificador from identificadores where country_code='AR'))

 if(@tipo_persona = 'f')
  begin
  
  set @es_empleador =  (select   count(id_empleado) from empleados
     where cuit = @identificacion
       and visible = '1'
       and periodo = (select max(periodo) from empleados b
                    where b.cuit = @identificacion 
          and b.visible = 1 
                      and b.periodo between @periodo_empleados_desde and @periodo_empleados_hasta))
     set @es_empleado =  (select   iif(count(id_empleado)>0,1,0) from empleados
     where cuil = @identificacion
       and visible = '1'
       and periodo = (select max(periodo) from empleados b
                    where b.cuil = @identificacion 
          and b.visible = 1 
                      and b.periodo between @periodo_empleados_desde and @periodo_empleados_hasta and b.remimp > 0))

  set @riesgo_fiscal = (select count(cuit) from sircreb  where cuit = @identificacion and fecha_publicacion between (getdate()-360) and getdate()) 
 
  set @argenta = (select count(argenta.cuit) from argenta where cuit = @identificacion)

  /* 1. Sueldo
   Si la persona es un empleado: 
   Por cada empresa donde trabaja, tomar los últimos 3 valores de nómina y elegir el mayor. 
   Sumar de todos los empleos 
   */

  set @sueldo = 0 
  if (@es_empleado > 0)
  begin
  set @sueldo = (select sum(sueldos.sueldo) from  
      (select cuit, max(isnull(empleados.remimp,0))  as sueldo from empleados
           where cuil = @identificacion
          and visible = 1 
                      /*and periodo between @periodo_empleados_desde and @periodo_empleados_hasta*/
       and periodo in (select top 3 periodo from empleados b 
                        where b.cuil = @identificacion 
              and b.remimp > 0 and b.visible = 1 
               and SUBSTRING((convert(varchar,b.periodo)),3,2) not in ('06','12') order by b.periodo desc) 
       and remimp > 0
       group by cuit) sueldos )
  end 
  /* 2. Categoría Fiscal
   2.1  Si la persona está inscripta en Monotributo, tomar el valor de la categoría, 
   dividirlo por 12 y multiplicarlo por 1.4 (se le carga al valor del año fiscal anterior una “actualización del 40%"). 
   2.2 Si la persona es responsable al IVA (Código 30 activo), tomar el valor de la categoría del Monotributo “F”, 
   dividirlo por 12, y multiplicarlo por 2 (se asume que factura el doble que un monotributista medio).
   Si es sólo Autónomo (cod 308) y no tiene el código 30 (IVA) activo, debe considerarse como Monotributo F / 12 * 1.5
   Suma 2.1 y de 2.2 
  
   */

  set @monotributo = (select max(monto) 
                        from persona_categoria_afip
        inner join monotributo on monotributo.categoria =  SUBSTRING(descripcion_categoria, 1, 1)
                       where id_padron = @id_padron and isnull(estado,'ACTIVO') = 'ACTIVO' and id_impuesto = 20)   
  set @monotributo = isnull(@monotributo,0) / 12 * 1.4

  declare @tiene_iva int = (select COUNT(*) from padron_impuestos
                            where id_padron = @id_padron and isnull(estado,'ACTIVO') = 'ACTIVO' and codigo_impuesto = 30) 
  declare @tiene_automo int = (select COUNT(*) from padron_impuestos
                               where id_padron = @id_padron and isnull(estado,'ACTIVO') = 'ACTIVO' and codigo_impuesto = 308) 
  set @iva = (select max(monto)
        from monotributo where monotributo.categoria =  'F') 
  if (@tiene_iva > 0) 
  begin
   set @iva = isnull(@iva,0) / 12 * 2
  end 
  else
  begin  
   if (@tiene_automo > 0)
   begin
   set @iva = isnull(@iva,0) / 12 * 1.5 
   end
  end  


  /*
   set @autonomo = (select COUNT(*) from padron_impuestos
    where id_padron = @id_padron and isnull(estado,'ACTIVO') = 'ACTIVO' and codigo_impuesto =308) 
    --Caso de ser autonomo
    if( @autonomo > 0)
    begin
   set @monto_autonomo = (select COUNT(DISTINCT(c01_cuit)) from socios where c04_ultimo = 'S' and c01_cuit_soc = @identificacion and c01_cuit != '')
  
   if(@monto_autonomo = 0)
   begin
   set @monto_autonomo = 25001
   end
   else
   begin
   set @monto_autonomo = @monto_autonomo * 20000
   end
   if((select COUNT(*) from empleados where cuit = @identificacion  and periodo = (select max(periodo) from empleados b
                     where b.cuit = @identificacion 
       and b.visible = 1 
                       and b.periodo between @periodo_empleados_desde and @periodo_empleados_hasta)) > 0)
   begin
   set @sueldo_empleados = 0
   end
    end
    else
    begin
   set @monto_socio = (select  COUNT(*) from socios where c04_ultimo = 'S' and c01_cuit_soc = @identificacion and visible = 1)
   set @monto_socio = @monto_socio * 20000
    end
   set @total = ISNULL(@sueldo,0)+ISNULL(@monotributo/12,0) + isnull(@monto_autonomo,0) + ISNULL(@monto_socio,0) + ISNULL(@sueldo_empleados,0) 
   */


  /* 3. Nómina de Empleados
   Si es empleador: 
   Se suman las últimas dos nóminas con valores, se las dividen por dos (para tomar un promedio) 
   se las multiplica por 1.5 (para calcular costo total) 
   y se las multiplica por 2.5 (porque se asumirá que por cada empleado, el empleador gana dos veces y media el sueldo pagado). 
   */

  set @sueldo_empleados = 0 
  if (@es_empleador > 0) 
  begin 
   declare @cant_periodo int = (select count(*) from 
           (select distinct top 2 periodo from empleados b 
                        where b.cuit = @identificacion 
              and b.remimp > 0 and b.visible = 1 
              and SUBSTRING((convert(varchar,b.periodo)),3,2) not in ('06','12') order by b.periodo desc) periodos)
   if (@cant_periodo > 0)
   begin
    set @sueldo_empleados = 
      (select sum(isnull(empleados.remimp,0)) / @cant_periodo as sueldo from empleados
           where cuit = @identificacion
          and visible = 1 
                      and periodo in (select top 2 periodo from empleados b 
                        where b.cuit = @identificacion 
              and b.remimp > 0 and b.visible = 1 
               and SUBSTRING((convert(varchar,b.periodo)),3,2) not in ('06','12') order by b.periodo desc)
      ) 
    set @sueldo_empleados = @sueldo_empleados * 1.5
    set @sueldo_empleados = @sueldo_empleados * 2.5
   end 

  end 

  /* 4. Directorios que integra último directorio
   por cada sociedad donde la persona figure como Socio, se sumarán $60.000.
   */

  set @monto_socio = 0
  set @monto_socio = (select COUNT(distinct c01_cuit) 
                        from socios 
         inner join cargos on cargos.car_codigo = socios.car_codigo
         where c04_ultimo = 'S' and c01_cuit_soc = @identificacion and visible = 1 
         and (cargos.car_nombre like 'SOCI[AO]%' OR cargos.car_nombre like 'GERENTE%'))
  declare @sumar_socio money = (select socio from nivel_socioeconomico_cifras) 
  set @monto_socio = @monto_socio * isnull(@sumar_socio,100000) /*100000*/

  /* 5. Sociedades que tiene 
   por cada directorio que la persona integre (no en carácter de ex) 
   y no haya sido previamente tomado como Socio (para no sumar los valores) se sumarán $40.000. 
   */


  declare @monto_dir int = 0
  set @monto_dir = (select COUNT(distinct c01_cuit) 
                        from socios 
         inner join cargos on cargos.car_codigo = socios.car_codigo
         where c04_ultimo = 'S' and c01_cuit_soc = @identificacion and visible = 1 
         and (cargos.car_nombre NOT like 'SOCI[AO]%' AND cargos.car_nombre NOT like 'GERENTE%'))
  declare @sumar_dir money = (select directivo from nivel_socioeconomico_cifras) 
  set @monto_dir = @monto_dir * isnull(@sumar_dir, 150000) /*150000*/

  set @total = ISNULL(@sueldo,0) +
               ISNULL(@monotributo,0) + isnull(@iva,0) + 
      ISNULL(@sueldo_empleados,0)  + 
      ISNULL(@monto_socio,0) + 
      ISNULL(@monto_dir,0) 

  set @max = null 
  set @rango_min = null 
  set @rango_max = null 
  if (@p_cliente is not null) 
  begin
   set @max = (select max(monto_maximo) from niveles_socioeconomicos where tipo_persona = @tipo_persona and id_cliente = @p_cliente)
  end 
  if (@max is null) 
   set @max  = (select max(monto_maximo) from niveles_socioeconomicos where tipo_persona = @tipo_persona and id_cliente =@p_cliente) /*AGB 0)*/
  
  if(@total > @max)
  begin
   set @rango_max = @max
   set @rango_min = null 
   if (@p_cliente is not null) 
    set @rango_min = (select monto_minimo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and monto_maximo = @rango_max and id_cliente = @p_cliente)
   if (@rango_min is null) 
    set @rango_min = (select monto_minimo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and monto_maximo = @rango_max and id_cliente = @p_cliente) /* AGB  = 0) */
   set @max = 1
  end
  else
  begin
   set @rango_min = null
   set @rango_max = null
   if (@p_cliente is not null) begin
      set @rango_min = (select monto_minimo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and @total between monto_minimo and monto_maximo and id_cliente =  @p_cliente)
   set @rango_max = (select monto_maximo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and @total between monto_minimo and monto_maximo and id_cliente =  @p_cliente)
   end 
   if (@rango_min is null) 
    set @rango_min = (select monto_minimo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and @total between monto_minimo and monto_maximo and id_cliente =  @p_cliente) /* AGB 0) */
   if (@rango_max is null) 
    set @rango_max = (select monto_maximo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and @total between monto_minimo and monto_maximo and id_cliente =  @p_cliente) /*AG 0)*/
   set @max = 0
  end
  select @identificacion as cuit, 
      @nombre as persona, 
   ISNULL(@sueldo,0) as sueldo, 
   ISNULL(@monotributo,0 ) as monotributo,
   ISNULL(@iva,0) as iva, 
   --isnull(@monto_autonomo,0) as autonomo, 
   ISNULL(@monto_socio,0) as socio, 
   ISNULL(@monto_dir,0) as directivo, 
   ISNULL(@sueldo_empleados,0) as empleador,
   @total as total,
   @rango_min as rango_minimo,
   @rango_max as rango_maximo,
   @argenta as argenta,
   @cliente as cliente,
   @riesgo_fiscal as riesgo_fiscal,
   @es_empleador as es_empleador,
   @es_empleado as es_empleado

  end
 else if(@tipo_persona = 'j')
 begin
  
  declare @max_periodo date, @min_periodo date
  declare @detalle_calculo varchar(500)
  declare @porcentaje_de_inflacion_total decimal(10,2)
  declare @max_periodo_uno date,  @max_periodo_comex date, @min_periodo_comex date
  set @max_periodo  = (select max(fecha_informacion) as fecha_informacion from fuentes_procesadas where fuente='comercio_exterior' and visible = 1)
  set @max_periodo_uno = convert(date,SUBSTRING(convert(char,@max_periodo),0,8)+'-01')
  set @max_periodo_comex = DATEADD(day, -1, (DATEADD(month, +1, @max_periodo_uno)))
  set @min_periodo  = (select DATEADD(month, -6, max(fecha_informacion)) as fecha_informacion from fuentes_procesadas where fuente='comercio_exterior' and visible =1)
  set @min_periodo_comex = convert(date,SUBSTRING(convert(char,@min_periodo),0,8)+'-01')
  
  set @cod_ramo = (select distinct(cod_ramo) from ramos where ramos.cod_subramo = (select distinct(cod_clae) from  clae where cuit = @identificacion and principal = 1 and visible = 1))
  
  set @ventas  = (SELECT res_vtanet FROM balances_contables where fecha_balance = (select MAX(fecha_balance) from balances_contables where cuit = @identificacion AND visible = 1 AND estado = 'PUBLICADO' )
  and cuit = @identificacion AND visible = 1 AND estado = 'PUBLICADO')


  set @fecha_balance  = (SELECT YEAR(fecha_balance) FROM balances_contables where  fecha_balance = (select MAX(fecha_balance) from balances_contables where cuit = @identificacion AND visible = 1 AND estado = 'PUBLICADO' )
  and cuit = @identificacion AND visible = 1 AND estado = 'PUBLICADO')
  
  set @fecha_nomina_mas_reciente = (select max(periodo) from empleados b
         where b.cuit = @identificacion 
        and b.visible = 1 
        and b.periodo between @periodo_empleados_desde and @periodo_empleados_hasta
        and b.remimp > 0
        )
  
   set @valor_nomina_inicial = 0
   set @valor_nomina_inicial = ( SELECT SUM(remimp)  FROM empleados WHERE cuit = @identificacion  and visible = '1'
     and periodo = @fecha_nomina_mas_reciente)
   set @valor_nomina = ((@valor_nomina_inicial* 2) * @porcentaje_afectacion) *13
  declare @calcular_balance bit = 0 
  if(@fecha_balance > YEAR(getdate())-11 )
  BEGIN
   set @calcular_balance = 1
  END
   
  --end
  --set @ventas_act = ((@sueldos_nuevos*13) / (@sueldos_viejos *13 / @ventas))

  if(@fecha_balance > 0)
  begin
   set @periodo_viejo =  (select max(periodo) from empleados_historico where /*visible = 1 and*/ cuit = @identificacion and periodo like (RIGHT(CONVERT(VARCHAR(4), @fecha_balance, 1),2))+'%' )
   if(@periodo_viejo > 0 )
   begin
    if(@valor_nomina_vieja > 0 and @ventas > 0)
    begin
     set @factor = (@valor_nomina_vieja *13) / @ventas
     if(@factor > 0)
     begin
      set @total  = (@valor_nomina_inicial *13)  / @factor
      set @detalle_calculo = 'tiene todo, se calcula por balance '
     end
    end
   end
   
  end

  if(@valor_nomina_inicial > 0 and @valor_nomina_vieja is null and (@total = 0 or @total is null))
    begin
      set @porcentaje_afectacion = (select porcentaje from porcentajes_por_ramo where cod_ramo = @cod_ramo)
      /* exec obtener_nivel_socioeconomico_dev '30710593597','j' */
      set @valor_nomina = ((@valor_nomina_inicial * 13) / isnull(@porcentaje_afectacion,1))
      set @detalle_calculo = '--'
      set @total = isnull(@valor_nomina,0)
    end
    else
     if(@ventas> 0 and (@total = 0 or @total is null) and @calcular_balance = 1)
     begin
      set @detalle_calculo = 'se calcula con las ventas y la inflación'
      set @total = @ventas
      DECLARE c_inflacion CURSOR FOR
        select porcentaje 
          from inflacion_anual
          where anio >= @fecha_balance
          order by anio
      OPEN C_inflacion
      FETCH NEXT FROM C_inflacion INTO @porcentaje_ipc 
      WHILE @@fetch_status = 0
      BEGIN
      --select @anio, @porcentaje
       set @total = @total + (@total * @porcentaje_ipc / 100)
       FETCH NEXT FROM C_inflacion INTO @porcentaje_ipc
      END 
      CLOSE C_inflacion
      DEALLOCATE C_inflacion
       set @porcentaje_de_inflacion_total = (@total/@ventas*100)
     end
   
   select @detalle_calculo

  set @max = (select max(monto_maximo) from niveles_socioeconomicos where tipo_persona = @tipo_persona  and id_cliente = @p_cliente) --'263625984'

  select @total as total
  select @max as max
  if(@total > @max )
  begin
  select 'total es mayor que max'
   set @rango_max =  @max
   set @max = 1
  end
  else
  begin
   set @max = 0
   set @rango_min = (select monto_minimo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and @total between monto_minimo and monto_maximo  and id_cliente = @p_cliente )
   set @rango_max = (select monto_maximo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and @total between monto_minimo and monto_maximo  and id_cliente = @p_cliente)
  end

  select @rango_min as rango_min
  select @rango_max as rango_max 

  set @provincia = (select top 1 domicilios_todos.prv_nombre from domicilios_todos where cuit = @identificacion and tipo_domicilio = 'D' and visible = 1 and prv_nombre is not null)
  if (@provincia = '')
  begin
   set @provincia = (select top 1 domicilios_todos.prv_nombre from domicilios_todos where cuit = @identificacion and tipo_domicilio = 'F' and visible = 1 and prv_nombre is not null)
  end

  set @cantidad_nomina = ( SELECT count(distinct(cuil))  FROM empleados WHERE cuit = @identificacion  and visible = '1'
     and periodo = (select max(periodo) from empleados b
         where b.cuit = @identificacion 
        and b.visible = 1 
        and b.periodo between @periodo_empleados_desde and @periodo_empleados_hasta
        and b.remimp > 0))
  
  set @comex_exportaciones = (select convert(decimal(28,2),sum(convert(real,fobusd))) from comex_exportaciones where cuit = @identificacion and fecha between @min_periodo_comex and @max_periodo_comex)
  set @comex_importaciones = (select  convert(decimal(28,2),sum(convert(real,fobusd))) from comex_importaciones where cuit = @identificacion and fecha between @min_periodo_comex and @max_periodo_comex)
  set @rango_min  = @rango_min * 1.3
  set @rango_max  = @rango_max * 1.3

  
  select @rango_min as 'rango_min x 1.3'
  select @rango_max as 'rango_max x 1.3' 
  declare @length_nomina int = len(convert(decimal(18,0),@valor_nomina_inicial)) -2
  
  -- [obtener_nivel_socioeconomico_2021AGB] '30504018845','j'

-- SELECT @fecha_balance AS fecha_balance
-- exec obtener_nivel_socioeconomico_2021AGB '30502332615','j'
  /* BUSCAR LOS DIRECTORES QUE TIENE LA SOCIEDAD */
  
  declare @monto_directores int
  set @monto_directores = 0
  set @monto_directores = (select count (distinct c01_cuit_soc)  from socios where c04_ultimo = 'S' and c01_cuit = @identificacion and visible = 1)
  --select *  from socios where c04_ultimo = 'S' and c01_cuit = '30502332615' and visible = 1
  declare @sumar_directores money = (select directivo from nivel_socioeconomico_cifras) 
  set @monto_directores = @monto_directores * isnull(@sumar_directores,100000) /*100000*/

  /* 5. Sociedades que tiene 
   por cada directorio que la persona integre (no en carácter de ex) 
   y no haya sido previamente tomado como Socio (para no sumar los valores) se sumarán $40.000. 
   */

  /* BUSCAR LOS SOCIOS QUE TIENE LA SOCIEDAD */

  if (@rango_min is null and @rango_max is null)
  begin
   set @rango_min = (select TOP 1 monto_minimo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and id_cliente = @p_cliente ORDER BY monto_MINIMO ASC)
   set @rango_max = (select TOP 1 monto_maximo from  niveles_socioeconomicos where tipo_persona = @tipo_persona and id_cliente = @p_cliente  ORDER BY monto_MINIMO ASC)
   set @detalle_calculo = 'MINIMO'
   SET @total=@rango_min
  end

  select @identificacion as cuit, 
  @detalle_calculo as formula_utilizada,@fecha_balance as balance_mas_nuevo,@ventas as ventas_del_balance,
  @periodo_viejo as periodo_nomina_vieja,
  @valor_nomina_vieja as valor_nomina_vieja,
  @fecha_nomina_mas_reciente as periodo_nomina_mas_reciente,
  @valor_nomina_inicial as valor_nomina_mas_reciente,
  @factor as factor,
  @ventas_totales as ventas_totales,
  @porcentaje_afectacion as porcentaje_afectacion_por_rubro,
  @porcentaje_de_inflacion_total as porcentaje_inflacion_anual,
  @rango_min as rango_minimo,@rango_max as rango_maximo,
  @total as total, round(@valor_nomina_inicial, -@length_nomina) as valor_nomina,
  @cantidad_nomina cantidad_empleados,
  @valor_nomina_vieja as nomina_anterior,@fecha_nomina_mas_reciente fecha_nomina_mas_reciente,@max as alcanzo_rango_maximo,@cliente cliente,@provincia provincia,
  @comex_exportaciones comex_exportaciones,@comex_importaciones comex_importaciones,@nombre as nombre
  end
END

/*
select ID_INGRESO AS id,upper(tipo_persona) as tipo_persona,monto_minimo,monto_maximo from niveles_socioeconomicos where id_cliente = 263625984 order by tipo_persona
select * from clientes where cliente = 263625984
*/

GO

Used By

No items found