dbo.LN_control_ingreso

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@accion varchar 30
@p_cliente int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_control_ingreso 
 -- Add the parameters for the stored procedure here
 @accion        varchar(30),
 @p_cliente       int = null
 
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here
 if (@accion = 'productos_panel') begin

  select LN_productos.producto, LN_productos.nombre_producto, LN_productos.producto_id,
    LN_productos.class_icon, LN_productos.etiqueta
  from LN_productos 
  inner join LN_cliente_productos ON LN_productos.producto = LN_cliente_productos.producto
  where LN_cliente_productos.cliente = @p_cliente
  and LN_cliente_productos.activo = 1
  and LN_productos.control_ingreso = 1
  order by LN_cliente_productos.orden_producto

 end


 if (@accion = 'productos_indicadores') begin

  SELECT LN_productos.producto, LN_productos.nombre_producto, LN_cliente_productos.activo,
   LN_cliente_productos.visibilidad_default, LN_productos.visible,
   country.country_code, country.country_name,
   LN_productos.etiqueta, LN_productos.class_icon,
   LN_productos.producto_id, LN_indicadores.indicador, LN_indicadores.nombre_indicador,
   LN_indicadores.etiqueta as etiqueta_indicador, LN_indicadores.tipo_dato,
   LN_indicadores.rango_inferior, LN_indicadores.rango_superior, LN_indicadores.opciones,
   LN_indicadores.clave_indicador,
   LN_cliente_productos.orden_producto, LN_indicadores.orden

  FROM LN_productos 
  INNER JOIN LN_cliente_productos ON LN_productos.producto = LN_cliente_productos.producto
  INNER JOIN LN_familia_productos ON LN_cliente_productos.producto = LN_familia_productos.producto
  INNER JOIN LN_familias ON (LN_familia_productos.familia = LN_familias.familia
         AND LN_cliente_productos.cliente = LN_familias.cliente)

  INNER join LN_indicadores ON LN_productos.producto = LN_indicadores.producto
  LEFT OUTER JOIN country ON LN_productos.country_code = country.country_code


  WHERE LN_cliente_productos.cliente = @p_cliente
  AND LN_productos.visible = 1
  AND LN_productos.control_ingreso = 1
  AND LN_cliente_productos.activo = 1
  AND LN_familia_productos.activo = 1
  AND LN_familias.visible = 1
  AND LN_indicadores.visible = 1

  GROUP BY LN_productos.producto, LN_productos.nombre_producto, LN_cliente_productos.activo,
   LN_cliente_productos.visibilidad_default, LN_productos.visible,
   country.country_code, country.country_name,
   LN_productos.etiqueta, LN_productos.class_icon,
   LN_productos.producto_id, LN_indicadores.indicador, LN_indicadores.nombre_indicador,
   LN_indicadores.etiqueta, LN_indicadores.tipo_dato,
   LN_indicadores.rango_inferior, LN_indicadores.rango_superior, LN_indicadores.opciones,
   LN_indicadores.clave_indicador,
   LN_cliente_productos.orden_producto, LN_indicadores.orden

  ORDER BY LN_cliente_productos.orden_producto, LN_indicadores.orden
   

 end


 if (@accion = 'valores_grilla') begin

  SELECT LN_contrapartes.contraparte, LN_contraparte_indicadores.indicador,
    LN_indicadores.clave_indicador, LN_productos.producto_id,

  case        
   when LN_indicadores.tipo_dato = 'S' then LN_contraparte_indicadores.valor_texto
   when LN_indicadores.tipo_dato = 'M' then LN_contraparte_indicadores.valor_memo
   when LN_indicadores.tipo_dato = 'I' then iif(LN_contraparte_indicadores.valor_numerico is not null, 
              REPLACE(replace(convert(varchar,convert(Money, ROUND(LN_contraparte_indicadores.valor_numerico,0)),1),'.00',''), ',', '.'), 
              null)
   when LN_indicadores.tipo_dato = 'F' then iif(LN_contraparte_indicadores.valor_numerico is not null, 
              REPLACE(replace(convert(varchar,convert(Money, ROUND(LN_contraparte_indicadores.valor_numerico,0)),1),'.00',''), ',', '.'), 
              null)
   when LN_indicadores.tipo_dato = 'D' then convert(varchar, LN_contraparte_indicadores.valor_fecha, 103)
   when LN_indicadores.tipo_dato = 'B' then iif(LN_contraparte_indicadores.valor_numerico > 0, 'SI', 'NO')
   else null
  end as valor,


  /** COLOR **/
  CASE
   WHEN LN_indicadores.clave_indicador = 'DEP_ECON' THEN
    case
     when LN_contraparte_indicadores.valor_numerico >= 81 then 'A72B2A'
     when LN_contraparte_indicadores.valor_numerico >= 61 then 'd37123'
     when LN_contraparte_indicadores.valor_numerico >= 41 then 'FFB81C'
     when LN_contraparte_indicadores.valor_numerico >= 21 then 'cbc367'
     when LN_contraparte_indicadores.valor_numerico >= 0 then '63b68c'
     else NULL
    end

   WHEN LN_indicadores.clave_indicador = 'NIVEL_RIESGO' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'AR' then 'A72B2A'
     when LN_contraparte_indicadores.valor_texto = 'MR' then 'FFB81C'
     when LN_contraparte_indicadores.valor_texto = 'BR' then '63b68c'
     else NULL
    end

   WHEN LN_indicadores.clave_indicador = 'FIDECHECK' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then 'A72B2A'
     when LN_contraparte_indicadores.valor_texto = 'R' then 'FFB81C'
     when LN_contraparte_indicadores.valor_texto = 'N' then '63b68c'
     else NULL
    end

   WHEN (LN_indicadores.clave_indicador = 'CTRL_CALIDAD' OR LN_indicadores.clave_indicador = 'CTRL_ETICO' OR LN_indicadores.clave_indicador = 'CTRL_COMERCIAL' OR LN_indicadores.clave_indicador = 'HOMOLOG') THEN
    case 
     when (LN_contraparte_indicadores.valor_numerico = 1) then '63b68c'
     when (LN_contraparte_indicadores.valor_numerico = 0) then 'A72B2A'
     else null
    end

   WHEN (LN_indicadores.clave_indicador = 'VALORACION_BAL') THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then '63b68c'
     when LN_contraparte_indicadores.valor_texto = 'U' then 'cbc367'
     when LN_contraparte_indicadores.valor_texto = 'E' then 'FFB81C'
     when LN_contraparte_indicadores.valor_texto = 'D' then 'd37123'
     when LN_contraparte_indicadores.valor_texto = 'N' then 'A72B2A'
     else null
    end

   ELSE
    case
     when LN_contraparte_indicadores.valor_numerico >= 81 then '63b68c'
     when LN_contraparte_indicadores.valor_numerico >= 61 then 'cbc367'
     when LN_contraparte_indicadores.valor_numerico >= 41 then 'FFB81C'
     when LN_contraparte_indicadores.valor_numerico >= 21 then 'd37123'
     when LN_contraparte_indicadores.valor_numerico >= 0 then 'A72B2A'
     else NULL 
    end
        
  END AS color,


  /** COLOR TEXTO **/
  CASE
   WHEN LN_indicadores.clave_indicador = 'DEP_ECON' THEN
    case
     when LN_contraparte_indicadores.valor_numerico >= 81 then 'FFFFFF'
     else '000000'
    end

   WHEN LN_indicadores.clave_indicador = 'NIVEL_RIESGO' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'AR' then 'FFFFFF'
     when LN_contraparte_indicadores.valor_texto = 'MR' then '000000'
     when LN_contraparte_indicadores.valor_texto = 'BR' then '000000'
     else NULL
    end       

   WHEN LN_indicadores.clave_indicador = 'FIDECHECK' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then 'FFFFFF'
     when LN_contraparte_indicadores.valor_texto = 'R' then 'FFFFFF'
     when LN_contraparte_indicadores.valor_texto = 'N' then 'FFFFFF'
     else NULL
    end       

   WHEN (LN_indicadores.clave_indicador = 'CTRL_CALIDAD' OR LN_indicadores.clave_indicador = 'CTRL_ETICO' OR LN_indicadores.clave_indicador = 'CTRL_COMERCIAL' OR LN_indicadores.clave_indicador = 'HOMOLOG') THEN
    case 
     when (LN_contraparte_indicadores.valor_numerico = 0) then 'FFFFFF'
     else '000000'
    end

   ELSE
    case
     when LN_contraparte_indicadores.valor_numerico <= 20 then 'FFFFFF'
     else '000000' 
    end        
  END AS textcolor,


  /** SVG **/
  CASE
   WHEN (LN_indicadores.clave_indicador = 'EXCEPCION') THEN
    case
     when LN_contraparte_indicadores.valor_numerico > 0 then '<svg x="0px" y="0px" viewBox="0 0 473.931 473.931" style="enable-background:new 0 0 473.931 473.931;" xml:space="preserve" width="15px" height="15px" class=""><g><circle style="fill:#FFB81C" cx="236.966" cy="236.966" r="236.966" data-original="#E79E2D" class="active-path" data-old_color="#E79E2D"/><path style="fill:#FFFFFF" d="M214.399,252.389l-6.698-100.159c-1.257-19.517-1.871-33.526-1.871-42.027  c0-11.57,3.035-20.602,9.085-27.072c6.065-6.499,14.054-9.74,23.94-9.74c11.996,0,20.022,4.15,24.056,12.445  c4.034,8.303,6.065,20.258,6.065,35.857c0,9.205-0.494,18.559-1.459,28.022l-8.995,103.089c-0.973,12.277-3.061,21.68-6.279,28.239  c-3.207,6.544-8.509,9.815-15.888,9.815c-7.536,0-12.756-3.158-15.682-9.512C217.744,275.016,215.645,265.351,214.399,252.389z   M237.609,389.974c-8.501,0-15.936-2.739-22.267-8.251c-6.346-5.497-9.512-13.197-9.512-23.102c0-8.647,3.035-16.004,9.085-22.069  c6.065-6.065,13.493-9.092,22.275-9.092c8.786,0,16.269,3.027,22.477,9.092c6.204,6.065,9.31,13.425,9.31,22.069  c0,9.751-3.136,17.414-9.418,22.997C253.291,387.19,245.976,389.974,237.609,389.974z" data-original="#CA7B29" class="" data-old_color="#ffffff"/></g> </svg>'
     else null
    end

   WHEN (LN_indicadores.clave_indicador = 'CTRL_ETICO' OR LN_indicadores.clave_indicador = 'CTRL_CALIDAD' OR LN_indicadores.clave_indicador = 'CTRL_COMERCIAL' OR LN_indicadores.clave_indicador = 'HOMOLOG') THEN
    case
     when LN_contraparte_indicadores.valor_numerico > 0 then '<svg width="15" height="15"><rect width="15" height="15" style="fill:#63b68c;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico = 0 then '<svg width="15" height="15"><rect width="15" height="15" style="fill:#A72B2A;" /></svg>'
     else null
    end

   WHEN (LN_indicadores.clave_indicador = 'NIVEL_RIESGO') THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'AR' then '<svg width="15" height="15"><rect width="15" height="15" style="fill:#A72B2A;" /></svg>'
     when LN_contraparte_indicadores.valor_texto = 'MR' then '<svg width="15" height="15"><rect width="15" height="15" style="fill:#FFB81C;" /></svg>'
     when LN_contraparte_indicadores.valor_texto = 'BR' then '<svg width="15" height="15"><rect width="15" height="15" style="fill:#63b68c;" /></svg>'
     else NULL
    end

   WHEN (LN_indicadores.clave_indicador = 'FIDECHECK') THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then '<svg height="15" width="15"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
     when LN_contraparte_indicadores.valor_texto = 'R' then '<svg height="15" width="15"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
     when LN_contraparte_indicadores.valor_texto = 'N' then '<svg height="15" width="15"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#63b68c" /></svg>'
     else NULL
    end

   WHEN (LN_indicadores.clave_indicador = 'SCORE_IC' OR LN_indicadores.clave_indicador = 'SCORE_BAL' OR LN_indicadores.clave_indicador = 'SCORE_DOC' OR LN_indicadores.clave_indicador = 'CUMPL_DOC' OR LN_indicadores.clave_indicador = 'SCORE_FINAL' OR LN_indicadores.clave_indicador = 'SCORE_DOSSIER') THEN
    case
     when LN_contraparte_indicadores.valor_numerico >= 81 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#63b68c;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 61 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#cbc367;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 41 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#FFB81C;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 21 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#d37123;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 0 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#A72B2A;" /></svg>'
     else NULL
    end

   WHEN (LN_indicadores.clave_indicador = 'DEP_ECON') THEN
    case
     when LN_contraparte_indicadores.valor_numerico >= 81 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#A72B2A;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 61 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#d37123;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 41 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#FFB81C;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 21 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#cbc367;" /></svg>'
     when LN_contraparte_indicadores.valor_numerico >= 0 then '<svg width="7" height="15"><rect width="7" height="15" style="fill:#63b68c;" /></svg>'
     else NULL
    end

   WHEN (LN_indicadores.clave_indicador = 'VALORACION_BAL') THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="" x="0px" y="0px" viewBox="0 0 543.906 543.906" style="enable-background:new 0 0 543.906 543.906;" xml:space="preserve" width="15px" height="15px">
     <g>
      <path d="M0,271.953c0,150.194,121.759,271.953,271.953,271.953s271.953-121.759,271.953-271.953 S422.148,0,271.953,0S0,121.759,0,271.953z M124.076,340.453l0.169-97.735L272.122,95.184l147.703,147.535v97.566L307.476,227.929 v220.793h-71.556V228.778L124.076,340.453z" fill="#63b68c"/>
     </g>
     </svg>'

          when LN_contraparte_indicadores.valor_texto = 'U' then '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="" x="0px" y="0px" viewBox="0 0 543.902 543.902" style="enable-background:new 0 0 543.902 543.902;" xml:space="preserve" width="15px" height="15px">
          <g>
           <path d="M79.652,79.652c-106.203,106.203-106.203,278.398,0,384.602   c106.203,106.198,278.398,106.198,384.602,0c106.198-106.203,106.198-278.398,0-384.602   C358.045-26.551,185.856-26.551,79.652,79.652z M118.955,215.825l69.228-68.989l208.887,0.239l0.12,208.768l-68.989,68.984V265.94   L172.073,422.069l-50.6-50.6l155.519-155.525L118.955,215.825L118.955,215.825z" fill="#cbc367"/>
          </g>
          </svg>'
 
          when LN_contraparte_indicadores.valor_texto = 'E' then '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="" x="0px" y="0px" viewBox="0 0 543.906 543.906" style="enable-background:new 0 0 543.906 543.906;" xml:space="preserve" width="15px" height="15px">
          <g>
           <path d="M271.953,0C121.759,0,0,121.759,0,271.953s121.759,271.953,271.953,271.953   s271.953-121.759,271.953-271.953S422.148,0,271.953,0z M203.454,124.076l97.735,0.169l147.535,147.877L301.188,419.831h-97.56   l112.349-112.349H95.184v-71.562h219.945L203.454,124.076z" fill="#FFB81C"/>
          </g>
          </svg>'

          when LN_contraparte_indicadores.valor_texto = 'D' then '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve" width="15px" height="15px">
          <g>
           <path d="M85.355,14.645c-19.526-19.526-51.185-19.526-70.711,0s-19.526,51.185,0,70.711   c19.526,19.525,51.185,19.525,70.711,0C104.881,65.829,104.881,34.171,85.355,14.645z M60.319,21.871l12.684,12.728l-0.044,38.405   l-38.383,0.022L21.893,60.342h29.213L22.401,31.637l9.303-9.303l28.593,28.593L60.319,21.871z" fill="#d37123"/>
          </g>
          </svg>'

          when LN_contraparte_indicadores.valor_texto = 'N' then '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="" x="0px" y="0px" viewBox="0 0 543.906 543.906" style="enable-background:new 0 0 543.906 543.906;" xml:space="preserve" width="15px" height="15px">
          <g>
           <path d="M543.906,271.953C543.906,121.759,422.148,0,271.953,0S0,121.759,0,271.953 s121.759,271.953,271.953,271.953S543.906,422.148,543.906,271.953z M419.831,203.454l-0.169,97.735L271.785,448.723 L124.076,301.188v-97.56l112.349,112.349V95.184h71.556v219.945L419.831,203.454z" fill="#A72B2A"/>
          </g>
          </svg>'

     else NULL
    end

   ELSE NULL
  END AS svg_data,


  /** TEXT CAPTION **/
  CASE
   WHEN LN_indicadores.clave_indicador = 'VALORACION_BAL' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then 'Positivo'
     when LN_contraparte_indicadores.valor_texto = 'U' then 'Ascendente'
     when LN_contraparte_indicadores.valor_texto = 'E' then 'Neutro' 
     when LN_contraparte_indicadores.valor_texto = 'D' then 'Descendente' 
     when LN_contraparte_indicadores.valor_texto = 'N' then 'Negativo'
     else NULL
    end

   WHEN LN_indicadores.clave_indicador = 'NIVEL_RIESGO' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'AR' then 'Riesgo alto'
     when LN_contraparte_indicadores.valor_texto = 'MR' then 'Riesgo medio'
     when LN_contraparte_indicadores.valor_texto = 'BR' then 'Riesgo bajo'
     else null
    end

   WHEN LN_indicadores.clave_indicador = 'FIDECHECK' THEN
    case
     when LN_contraparte_indicadores.valor_texto = 'P' then 'Positive'
     when LN_contraparte_indicadores.valor_texto = 'R' then 'Related'
     when LN_contraparte_indicadores.valor_texto = 'N' then 'Negative'
     else null
    end

   WHEN LN_indicadores.clave_indicador = 'EXCEPCION' THEN
    iif (excepciones.tipo_excepcion = 'V', 'Excepción para PERMITIR ingreso', iif(excepciones.tipo_excepcion = 'R', 'Excepción para RECHAZAR ingreso', NULL))

   ELSE NULL
  END AS textcaption,


  /** PUNTO **/
  CASE      
   WHEN LN_indicadores.clave_indicador LIKE '%CUMPL%' THEN iif(PENDIENTES_VERIFICAR.ingresados > 0, 1, 0)
   WHEN LN_indicadores.clave_indicador = 'ULTIMA_NOVEDAD' THEN iif(LN_contraparte_indicadores.valor_fecha IS NOT NULL, iif(DATEDIFF(DAY, CONVERT(DATE,LN_contraparte_indicadores.valor_fecha) , CONVERT(DATE,GETDATE())) <= 7, 1, 0), 0)
   WHEN LN_indicadores.clave_indicador = 'SCORE_BAL' THEN ISNULL(LN_contraparte_indicadores.balance_preexiste, 0)
   ELSE 0 
  END AS punto


  FROM LN_contrapartes 
  INNER JOIN LN_contraparte_indicadores ON LN_contrapartes.contraparte = LN_contraparte_indicadores.contraparte
  INNER JOIN LN_indicadores ON LN_contraparte_indicadores.indicador = LN_indicadores.indicador

  INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
  INNER JOIN LN_familia_productos ON (LN_contraparte_familias.familia = LN_familia_productos.familia
           AND LN_indicadores.producto = LN_familia_productos.producto)
  INNER JOIN LN_productos ON LN_indicadores.producto = LN_productos.producto

  INNER JOIN LN_gestiones ON LN_contrapartes.contraparte = LN_gestiones.contraparte

  LEFT OUTER JOIN
   (SELECT LN_docs.contraparte, COUNT(*) AS ingresados
   FROM LN_docs 
   INNER JOIN LN_gestiones ON LN_docs.gestion = LN_gestiones.gestion

   INNER JOIN
    (select LN_docs.contraparte, LN_docs.tipo_doc, max(doc_version) as ultima
    from LN_docs
    inner join LN_gestiones on (LN_docs.gestion = LN_gestiones.gestion 
           AND LN_docs.contraparte = LN_gestiones.contraparte)
    where LN_gestiones.desde <= GETDATE() AND LN_gestiones.hasta >= GETDATE()
    group by LN_docs.contraparte, LN_docs.tipo_doc) ultimas_versiones 

   ON (LN_docs.tipo_doc = ultimas_versiones.tipo_doc 
    AND ln_docs.contraparte = ultimas_versiones.contraparte 
    AND LN_docs.doc_version = ultimas_versiones.ultima)


   WHERE LN_gestiones.desde <= GETDATE() AND LN_gestiones.hasta >= GETDATE()
   AND LN_docs.estado_doc = 'I'
   GROUP BY LN_docs.contraparte) PENDIENTES_VERIFICAR ON LN_contrapartes.contraparte = PENDIENTES_VERIFICAR.contraparte

  LEFT OUTER JOIN
   (select LN_excepciones.contraparte, LN_excepciones.tipo_excepcion
   from LN_contrapartes inner join LN_excepciones
   on LN_contrapartes.contraparte = LN_excepciones.contraparte
   where LN_contrapartes.cliente = @p_cliente
   and LN_excepciones.estado = 1
   and LN_excepciones.vigencia >= GETDATE()) excepciones ON LN_contrapartes.contraparte = excepciones.contraparte


  WHERE LN_contrapartes.cliente = @p_cliente
  AND LN_gestiones.desde <= GETDATE() AND LN_gestiones.hasta >= GETDATE()
  AND LN_indicadores.visible = 1
  AND LN_contrapartes.activo = 1
  AND LN_contraparte_familias.activo = 1
  AND LN_familia_productos.activo = 1
  AND LN_productos.control_ingreso = 1




 end


 if (@accion = 'contrapartes') begin

  select LN_contrapartes.contraparte, identificadores.abreviatura, padrones.identificador, 
    LN_contrapartes.subcontratista, LN_contrapartes.id_padre, padrones.numero,
    padrones.identificacion, padrones.nombre_persona, identificadores.country_code,
    country.country_name, padrones.id_padron, LN_gestiones.desde, LN_gestiones.hasta,
    LN_familias.nombre_familia, ISNULL(LN_familias.subfamilia, 0) AS subfamilia,

    padrones2.nombre_persona as nombre_persona_padre, 
    identificadores2.abreviatura as abreviatura_padre,
    identificadores2.country_code as country_code_padre,
    padrones2.numero as numero_padre,
    padrones2.identificacion as identificacion_padre,
    country2.country_name as country_name_padre

  from LN_contrapartes
  inner join LN_gestiones on LN_contrapartes.contraparte = LN_gestiones.contraparte
  inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
  inner join identificadores on padrones.identificador = identificadores.identificador
  inner join country on identificadores.country_code = country.country_code
  inner join LN_contraparte_familias on LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
  inner join LN_familias on LN_contraparte_familias.familia = LN_familias.familia
  inner join LN_familia_productos on LN_familias.familia = LN_familia_productos.familia
  inner join LN_productos on LN_familia_productos.producto = LN_productos.producto
  inner join LN_cliente_productos on (LN_contrapartes.cliente = LN_cliente_productos.cliente
           and LN_familia_productos.producto = LN_cliente_productos.producto)

  left outer join LN_contrapartes AS padre on LN_contrapartes.id_padre = padre.contraparte
  left outer join padrones AS padrones2 on padre.id_padron = padrones2.id_padron
  left outer join identificadores AS identificadores2 on padrones2.identificador = identificadores2.identificador
  left outer join country AS country2 on identificadores2.country_code = country2.country_code

  where LN_contrapartes.cliente = @p_cliente
  and LN_gestiones.desde <= getdate() and LN_gestiones.hasta >= getdate()
  and LN_productos.control_ingreso = 1
  and LN_familia_productos.activo = 1
  and LN_familias.visible = 1
  and LN_cliente_productos.activo = 1
  and LN_contrapartes.activo = 1

  order by padrones.nombre_persona

 end

END
GO

Used By

No items found