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_pasivo_contables_TEST '30501677643'
obtener_pasivo_contables null,null,'366137,366138'
*/
CREATE OR ALTER PROCEDURE dbo.obtener_pasivo_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(pc_ctapag,0) as cuentas_por_pagar,
isnull(pc_presta,0) as prestamos, isnull(pc_remune,0) as remuneraciones_y_cargas_sociales,isnull(pc_carfis,0) as cargas_fiscales, isnull(pc_antcli,0) as anticipos_clientes,
isnull(pc_otrpas,0) as otros_pasivos,
(isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0)) as total_pasivo_corriente,
isnull(pnc_cuepag,0) as pnc_cuentas_por_pagar, isnull(pnc_presta,0) as pnc_prestamos,isnull(pnc_deufis,0) as pnc_deudas_fiscales, isnull(pnc_otrpas,0) as pnc_otros_pasivos, isnull(pnc_previ,0) as previsiones,
(isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) as total_pasivo_no_corriente,
(isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) as total_pasivo,
isnull(capsoc,0) as capital_social, isnull(res_noasig,0) as resultados_no_asignados,
(isnull(ac_cajban,0) + isnull(ac_inver,0) + isnull(ac_crevta,0) + isnull(ac_otrcre,0) + isnull(ac_biecam,0) + isnull(ac_otract,0) + isnull(anc_otrcre,0) + isnull(anc_inver,0) + isnull(anc_bieuso,0) + isnull(anc_actint,0) + isnull(anc_otract,0) )- (isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) as patrimonio_neto,
(isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) + ((isnull(ac_cajban,0) + isnull(ac_inver,0) + isnull(ac_crevta,0) + isnull(ac_otrcre,0) + isnull(ac_biecam,0) + isnull(ac_otract,0) + isnull(anc_otrcre,0) + isnull(anc_inver,0) + isnull(anc_bieuso,0) + isnull(anc_actint,0) + isnull(anc_otract,0) )- (isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0))) as total
from balances_fide where cuit = @p_cuit and datediff(YY,fecha_balance,getdate()) < 7 and balances_fide.visible = 1 ORDER BY FECHA_BALANCE DESC
*/
if(ISNULL(@ids,'') != '')
BEGIN
set @ids = '0,'+@ids
/*
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.pc_ctapag,
bc.pc_presta,
bc.pc_remune,
bc.pc_carfis,
bc.pc_antcli,
bc.pc_otrpas,
bc.pc_total,
bc.pnc_cuepag,
bc.pnc_previ,
bc.pnc_presta,
bc.pnc_otrpas,
bc.pnc_deufis,
bc.pnc_total,
bc.pas_total,
bc.capsoc,
bc.res_noasig,
bc.patrimonio,
monedas.nombre_moneda
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.pc_ctapag,
bc.pc_presta,
bc.pc_remune,
bc.pc_carfis,
bc.pc_antcli,
bc.pc_otrpas,
bc.pc_total,
bc.pnc_cuepag,
bc.pnc_previ,
bc.pnc_presta,
bc.pnc_otrpas,
bc.pnc_deufis,
bc.pnc_total,
bc.pas_total,
bc.capsoc,
bc.res_noasig,
bc.patrimonio,
monedas.nombre_moneda
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
GO
GO
/*
obtener_pasivo_contables_TEST '30501677643'
obtener_pasivo_contables null,null,'366137,366138'
*/
CREATE OR ALTER PROCEDURE dbo.obtener_pasivo_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(pc_ctapag,0) as cuentas_por_pagar,
isnull(pc_presta,0) as prestamos, isnull(pc_remune,0) as remuneraciones_y_cargas_sociales,isnull(pc_carfis,0) as cargas_fiscales, isnull(pc_antcli,0) as anticipos_clientes,
isnull(pc_otrpas,0) as otros_pasivos,
(isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0)) as total_pasivo_corriente,
isnull(pnc_cuepag,0) as pnc_cuentas_por_pagar, isnull(pnc_presta,0) as pnc_prestamos,isnull(pnc_deufis,0) as pnc_deudas_fiscales, isnull(pnc_otrpas,0) as pnc_otros_pasivos, isnull(pnc_previ,0) as previsiones,
(isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) as total_pasivo_no_corriente,
(isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) as total_pasivo,
isnull(capsoc,0) as capital_social, isnull(res_noasig,0) as resultados_no_asignados,
(isnull(ac_cajban,0) + isnull(ac_inver,0) + isnull(ac_crevta,0) + isnull(ac_otrcre,0) + isnull(ac_biecam,0) + isnull(ac_otract,0) + isnull(anc_otrcre,0) + isnull(anc_inver,0) + isnull(anc_bieuso,0) + isnull(anc_actint,0) + isnull(anc_otract,0) )- (isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) as patrimonio_neto,
(isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0)) + ((isnull(ac_cajban,0) + isnull(ac_inver,0) + isnull(ac_crevta,0) + isnull(ac_otrcre,0) + isnull(ac_biecam,0) + isnull(ac_otract,0) + isnull(anc_otrcre,0) + isnull(anc_inver,0) + isnull(anc_bieuso,0) + isnull(anc_actint,0) + isnull(anc_otract,0) )- (isnull(pc_ctapag,0) +isnull(pc_presta,0) + isnull(pc_remune,0) +isnull(pc_carfis,0) + isnull(pc_antcli,0) +isnull(pc_otrpas,0) + isnull(pnc_cuepag,0) + isnull(pnc_previ,0) + isnull(pnc_presta,0) + isnull(pnc_otrpas,0) + isnull(pnc_deufis,0))) as total
from balances_fide where cuit = @p_cuit and datediff(YY,fecha_balance,getdate()) < 7 and balances_fide.visible = 1 ORDER BY FECHA_BALANCE DESC
*/
if(ISNULL(@ids,'') != '')
BEGIN
set @ids = '0,'+@ids
/*
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.pc_ctapag,
bc.pc_presta,
bc.pc_remune,
bc.pc_carfis,
bc.pc_antcli,
bc.pc_otrpas,
bc.pc_total,
bc.pnc_cuepag,
bc.pnc_previ,
bc.pnc_presta,
bc.pnc_otrpas,
bc.pnc_deufis,
bc.pnc_total,
bc.pas_total,
bc.capsoc,
bc.res_noasig,
bc.patrimonio,
monedas.nombre_moneda
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.pc_ctapag,
bc.pc_presta,
bc.pc_remune,
bc.pc_carfis,
bc.pc_antcli,
bc.pc_otrpas,
bc.pc_total,
bc.pnc_cuepag,
bc.pnc_previ,
bc.pnc_presta,
bc.pnc_otrpas,
bc.pnc_deufis,
bc.pnc_total,
bc.pas_total,
bc.capsoc,
bc.res_noasig,
bc.patrimonio,
monedas.nombre_moneda
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
GO
Depends On
3Used By
No items found