Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_user_id | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: STORE PARA CONSULTAR DESDE BACKEND LOS DOCUMENTOS que Valoración y análisis de balances
/*
select * from balances_contables where id_balance in (366137,366139,366140)
where cuit = '30618705672' ORDER by fecha_balance desc
*/
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_documentos_valoraciones
@p_user_id int = NULL
AS
BEGIN
SET NOCOUNT ON;
select c.contraparte,
g.gestion,
p.producto, p.balance_analisis, p.balance_valoracion,
clientes.nombre_cliente,
padrones.identificador,
padrones.identificacion,
padrones.nombre_persona,
identificadores.abreviatura,
identificadores.country_code,
country.country_name,
bal.balances
from LN_contrapartes c
inner join LN_gestiones g on c.contraparte = g.contraparte
inner join padrones on c.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 clientes on c.cliente = clientes.cliente
inner join LN_contraparte_familias cf on c.contraparte = cf.contraparte
inner join LN_familia_productos fp on cf.familia = fp.familia
inner join LN_productos p on fp.producto = p.producto
/*inner join
(select c.contraparte, g.gestion, count(*) as balances
from LN_contrapartes c
inner join LN_gestiones g on c.contraparte = g.contraparte
inner join LN_docs d on (c.contraparte = d.contraparte and g.gestion = d.gestion)
inner join LN_tipos_doc td on d.tipo_doc = td.tipo_doc
inner join balances_contables bc on d.id_externo = bc.id_balance
where g.desde <= GETDATE()
and g.hasta >= GETDATE()
and g.vigente = 1
and td.es_balance = 1
and d.estado_doc IN ('I','V')
and bc.estado = 'PUBLICADO'
group by c.contraparte, g.gestion) BAL on (c.contraparte = BAL.contraparte and g.gestion = BAL.gestion)
*/
inner join
(select c.contraparte,g.gestion, count(*) as balances
from LN_contrapartes c
inner join LN_gestiones g on c.contraparte = g.contraparte
inner join padrones on padrones.id_padron = c.id_padron
inner join balances_contables bc on padrones.identificacion = bc.cuit
where bc.visible = 1
/*and
bc.estado = 'PUBLICADO' */
group by c.contraparte,g.gestion) BAL on (c.contraparte = BAL.contraparte and g.gestion = BAL.gestion)
where p.balance = 1
and g.desde <= GETDATE()
and g.hasta >= GETDATE()
and g.vigente = 1
and BAL.balances >= 1
and (p.balance_analisis > 0 OR p.balance_valoracion > 0)
and not exists (select * from tareas_usuarios_documentos tud where tud.contraparte = c.contraparte and tipo like '%de balance')
order by padrones.nombre_persona, c.contraparte, g.gestion
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: STORE PARA CONSULTAR DESDE BACKEND LOS DOCUMENTOS que Valoración y análisis de balances
/*
select * from balances_contables where id_balance in (366137,366139,366140)
where cuit = '30618705672' ORDER by fecha_balance desc
*/
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_documentos_valoraciones
@p_user_id int = NULL
AS
BEGIN
SET NOCOUNT ON;
select c.contraparte,
g.gestion,
p.producto, p.balance_analisis, p.balance_valoracion,
clientes.nombre_cliente,
padrones.identificador,
padrones.identificacion,
padrones.nombre_persona,
identificadores.abreviatura,
identificadores.country_code,
country.country_name,
bal.balances
from LN_contrapartes c
inner join LN_gestiones g on c.contraparte = g.contraparte
inner join padrones on c.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 clientes on c.cliente = clientes.cliente
inner join LN_contraparte_familias cf on c.contraparte = cf.contraparte
inner join LN_familia_productos fp on cf.familia = fp.familia
inner join LN_productos p on fp.producto = p.producto
/*inner join
(select c.contraparte, g.gestion, count(*) as balances
from LN_contrapartes c
inner join LN_gestiones g on c.contraparte = g.contraparte
inner join LN_docs d on (c.contraparte = d.contraparte and g.gestion = d.gestion)
inner join LN_tipos_doc td on d.tipo_doc = td.tipo_doc
inner join balances_contables bc on d.id_externo = bc.id_balance
where g.desde <= GETDATE()
and g.hasta >= GETDATE()
and g.vigente = 1
and td.es_balance = 1
and d.estado_doc IN ('I','V')
and bc.estado = 'PUBLICADO'
group by c.contraparte, g.gestion) BAL on (c.contraparte = BAL.contraparte and g.gestion = BAL.gestion)
*/
inner join
(select c.contraparte,g.gestion, count(*) as balances
from LN_contrapartes c
inner join LN_gestiones g on c.contraparte = g.contraparte
inner join padrones on padrones.id_padron = c.id_padron
inner join balances_contables bc on padrones.identificacion = bc.cuit
where bc.visible = 1
/*and
bc.estado = 'PUBLICADO' */
group by c.contraparte,g.gestion) BAL on (c.contraparte = BAL.contraparte and g.gestion = BAL.gestion)
where p.balance = 1
and g.desde <= GETDATE()
and g.hasta >= GETDATE()
and g.vigente = 1
and BAL.balances >= 1
and (p.balance_analisis > 0 OR p.balance_valoracion > 0)
and not exists (select * from tareas_usuarios_documentos tud where tud.contraparte = c.contraparte and tipo like '%de balance')
order by padrones.nombre_persona, c.contraparte, g.gestion
END
GO
Depends On
11Used By
No items found