Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
4| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_id_balance | int | 4 | |
| @p_Cuit | varchar | 20 | |
| @p_anios | smallint | 2 | |
| @p_visible | bit | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.backend_balances
@p_id_balance int, -- si viene nulo busca los otros tres campos, si viene con valor solo busca por este id.
@p_Cuit varchar(20),
@p_anios smallint,
@p_visible bit
-- Se muestran todos juntos (no separados en Visibles y No visibles)
AS
BEGIN
SET NOCOUNT ON;
declare @dtStart date, @dtEnd date
if (@p_id_balance is not null)
begin
set @p_cuit = null
set @p_anios = null
set @p_visible = null
end
else
begin
set @dtEnd = getdate()
set @dtStart = dateadd(year, (-1)*(@p_anios), @dtEnd)
end
begin
select balances_fide.*,
visible = case balances_fide.visible
when 1 then 'ACTIVO'
when 0 then 'INACTIVO'
end,
bal_man = case balances_fide.bal_manifestacion
when 'M' then 'Manifestación Bienes'
when 'B' then 'Balance'
end,
fecha_dia_mes_anio = convert(varchar(10),fecha_balance,103),
monedas.nombre_moneda,
ac_total = (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)),
anc_total = (isnull(anc_crevta,0)+
isnull(anc_otrcre,0) +
isnull(anc_inver,0) +
isnull(anc_bieuso,0) +
isnull(anc_actint,0) +
isnull(anc_otract,0)),
act_total = (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)),
pc_total = (isnull(pc_ctapag,0) +
isnull(pc_presta,0) +
isnull(pc_remune,0) +
isnull(pc_carfis,0) +
isnull(pc_antcli,0) +
isnull(pc_otrpas,0)),
pnc_total = (isnull(pnc_cuepag,0) +
isnull(pnc_previ,0) +
isnull(pnc_presta,0) +
isnull(pnc_deufis,0) +
isnull(pnc_otrpas,0)),
pas_total = (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_deufis,0) +
isnull(pnc_otrpas,0)),
patrimonio = (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)) -
(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_deufis,0) +
isnull(pnc_otrpas,0)),
total_res = (isnull(res_vtanet,0) + isnull(res_cosmer,0)),
ganancia = (isnull(res_vtanet,0) + isnull(res_cosmer,0)) +
(isnull(res_gascom,0) +
isnull(res_gasadm,0) +
isnull(res_gasfin,0) +
isnull(res_otros,0) +
isnull(res_resinv,0) +
isnull(res_ie,0) +
isnull(res_otrosing,0) +
isnull(res_otrosegr,0) +
isnull(res_resfin,0) +
isnull(res_iva,0))
from balances_fide
inner join monedas
on monedas.moneda = balances_fide.moneda
where (@p_Cuit is not null and
cuit = @p_Cuit
--and visible = @p_visible
and fecha_balance between @dtStart and @dtEnd)
or (@p_id_balance is not null and
id_balance = @p_id_balance)
order by balances_fide.fecha_balance desc
end
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.backend_balances
@p_id_balance int, -- si viene nulo busca los otros tres campos, si viene con valor solo busca por este id.
@p_Cuit varchar(20),
@p_anios smallint,
@p_visible bit
-- Se muestran todos juntos (no separados en Visibles y No visibles)
AS
BEGIN
SET NOCOUNT ON;
declare @dtStart date, @dtEnd date
if (@p_id_balance is not null)
begin
set @p_cuit = null
set @p_anios = null
set @p_visible = null
end
else
begin
set @dtEnd = getdate()
set @dtStart = dateadd(year, (-1)*(@p_anios), @dtEnd)
end
begin
select balances_fide.*,
visible = case balances_fide.visible
when 1 then 'ACTIVO'
when 0 then 'INACTIVO'
end,
bal_man = case balances_fide.bal_manifestacion
when 'M' then 'Manifestación Bienes'
when 'B' then 'Balance'
end,
fecha_dia_mes_anio = convert(varchar(10),fecha_balance,103),
monedas.nombre_moneda,
ac_total = (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)),
anc_total = (isnull(anc_crevta,0)+
isnull(anc_otrcre,0) +
isnull(anc_inver,0) +
isnull(anc_bieuso,0) +
isnull(anc_actint,0) +
isnull(anc_otract,0)),
act_total = (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)),
pc_total = (isnull(pc_ctapag,0) +
isnull(pc_presta,0) +
isnull(pc_remune,0) +
isnull(pc_carfis,0) +
isnull(pc_antcli,0) +
isnull(pc_otrpas,0)),
pnc_total = (isnull(pnc_cuepag,0) +
isnull(pnc_previ,0) +
isnull(pnc_presta,0) +
isnull(pnc_deufis,0) +
isnull(pnc_otrpas,0)),
pas_total = (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_deufis,0) +
isnull(pnc_otrpas,0)),
patrimonio = (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)) -
(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_deufis,0) +
isnull(pnc_otrpas,0)),
total_res = (isnull(res_vtanet,0) + isnull(res_cosmer,0)),
ganancia = (isnull(res_vtanet,0) + isnull(res_cosmer,0)) +
(isnull(res_gascom,0) +
isnull(res_gasadm,0) +
isnull(res_gasfin,0) +
isnull(res_otros,0) +
isnull(res_resinv,0) +
isnull(res_ie,0) +
isnull(res_otrosing,0) +
isnull(res_otrosegr,0) +
isnull(res_resfin,0) +
isnull(res_iva,0))
from balances_fide
inner join monedas
on monedas.moneda = balances_fide.moneda
where (@p_Cuit is not null and
cuit = @p_Cuit
--and visible = @p_visible
and fecha_balance between @dtStart and @dtEnd)
or (@p_id_balance is not null and
id_balance = @p_id_balance)
order by balances_fide.fecha_balance desc
end
END
GO
Depends On
2Used By
No items found