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_a_sacar | varchar | 1 | |
| @p_cantidad | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
--[obtener_cheques_vinculaciones_todas] '30504151464'
CREATE OR ALTER PROCEDURE dbo.obtener_cheques_vinculaciones_todas
@p_Cuit varchar(20),
@p_a_sacar varchar(1) = null,
@p_cantidad int = 2147483647
AS
BEGIN
DECLARE @p_5anios smalldatetime = getdate() - 1825
DECLARE @p_2anios smalldatetime = getdate() - 730
DECLARE @p_1anio smalldatetime = getdate() - 365
DECLARE @total_cheques int = 0
DECLARE @tipo varchar(2)
set @total_cheques = (select count(nro_cheque) from ChequesBCRA
where (cuit_firmante = @p_Cuit)
AND id_cheque = (select max(id_cheque) from chequesBCRA b
where b.cuit_firmante = chequesBCRA.cuit_firmante
and b.nro_cheque = chequesBCRA.nro_cheque
and b.visible = 1)
AND visible = 1
AND
(
(
(
(
(fecha_levantamiento IS NULL)
AND
(fecha_rechazo >= @p_5anios)
)
OR
(
(
(fecha_levantamiento >= @p_5anios)
AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 15 )
)
AND
(
((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= (GETDATE() - 2)))
OR
(((fecha_pago IS NULL) AND (fecha_levantamiento >= (GETDATE() - 2))) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
((fecha_levantamiento >= @p_5anios)
AND (((datediff(day,fecha_rechazo,fecha_levantamiento)) >= 16 ) AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 90))
)
AND
(((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= @p_1anio))
OR (((fecha_pago IS NULL) AND (fecha_levantamiento >= @p_1anio)) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
(((fecha_levantamiento >= @p_5anios) AND
((datediff(day,fecha_rechazo,fecha_levantamiento)) > 90)) AND (fecha_levantamiento >= @p_2anios)
)
AND (fecha_rechazo >= @p_5anios)
)
)
)
SELECT @tipo = IIF(CharIndex('3',@p_Cuit)=1,'j',NULL)
IF @tipo = 'j'
BEGIN
SELECT top (@p_cantidad)
pf.nombre_persona AS 'nombre_persona_firmante',
cuit_firmante AS 'cuit_firmante',
pr.nombre_persona AS 'nombre_persona_relacionado',
Cuit_relacionado AS 'Cuit_relacionado',
pf.id_padron as idp,
pr.id_padron as idppr,
'0' as nro_cheque,
'0' AS fecha_rechazo,
'0' AS fecha_levantamiento,
'0' AS fecha_pago,
'0' AS importe,
count(nro_cheque) as cantidad,
'0' AS causa,
'vinculaciones' AS tipo,
@total_cheques as total_cheques
FROM
ChequesBCRA
LEFT JOIN padrones AS pf ON (pf.identificacion = cuit_firmante and pf.habilitado = 1) --info firmante
LEFT JOIN padrones AS pr ON (pr.identificacion = Cuit_relacionado and pr.habilitado = 1) --info relacionado
INNER JOIN Cheques_causales ON (ChequesBCRA.id_causa = Cheques_causales.id_causa)
WHERE
(Cuit_relacionado = @p_Cuit)
AND id_cheque = (select max(id_cheque) from chequesBCRA b
where b.cuit_firmante = chequesBCRA.cuit_firmante
and b.nro_cheque = chequesBCRA.nro_cheque
and b.visible = 1)
AND visible = 1
/*
AND
(
(
(
(
(fecha_levantamiento IS NULL)
AND
(fecha_rechazo >= @p_5anios)
)
OR
(
(
(fecha_levantamiento >= @p_5anios)
AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 15 )
)
AND
(
((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= (GETDATE() - 2)))
OR
(((fecha_pago IS NULL) AND (fecha_levantamiento >= @p_2anios)) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
((fecha_levantamiento >= @p_5anios)
AND (((datediff(day,fecha_rechazo,fecha_levantamiento)) >= 16 ) AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 90))
)
AND
(((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= @p_1anio))
OR (((fecha_pago IS NULL) AND (fecha_levantamiento >= @p_2anios)) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
(((fecha_levantamiento >= @p_5anios) AND
((datediff(day,fecha_rechazo,fecha_levantamiento)) > 90)) AND (fecha_levantamiento >= @p_2anios)
)
AND (fecha_rechazo >= @p_5anios)
)
)
*/
group by pf.nombre_persona,ChequesBCRA.cuit_firmante,pr.nombre_persona,Cuit_relacionado,pf.id_padron,pr.id_padron
--ORDER BY fecha_rechazo, nro_cheque DESC
union
SELECT distinct
pf.nombre_persona AS 'nombre_persona_firmante',
cuita AS 'cuit_firmante',
pr.nombre_persona AS 'nombre_persona_relacionado',
Cuitb AS 'Cuit_relacionado',
pf.id_padron as idp,
pr.id_padron as idppr,
'0' as nro_cheque,
'0' AS fecha_rechazo,
'0' AS fecha_levantamiento,
'0' AS fecha_pago,
'0' AS importe,
'0' as cantidad,
'0' AS causa,
'vinculaciones' AS tipo,
@total_cheques as total_cheques
FROM
Relaciones
LEFT JOIN padrones AS pf ON (pf.identificacion = cuita and pf.habilitado = 1)
LEFT JOIN padrones AS pr ON (pr.identificacion = Cuitb and pr.habilitado = 1)
WHERE Cuitb = @p_Cuit
AND origen_del_dato = 'Cheques-BCRA'
and not exists (select * from ChequesBCRA where cuit_firmante = cuita and Cuit_relacionado = cuitb)
ORDER BY fecha_rechazo, nro_cheque DESC
END
END
GO
GO
--[obtener_cheques_vinculaciones_todas] '30504151464'
CREATE OR ALTER PROCEDURE dbo.obtener_cheques_vinculaciones_todas
@p_Cuit varchar(20),
@p_a_sacar varchar(1) = null,
@p_cantidad int = 2147483647
AS
BEGIN
DECLARE @p_5anios smalldatetime = getdate() - 1825
DECLARE @p_2anios smalldatetime = getdate() - 730
DECLARE @p_1anio smalldatetime = getdate() - 365
DECLARE @total_cheques int = 0
DECLARE @tipo varchar(2)
set @total_cheques = (select count(nro_cheque) from ChequesBCRA
where (cuit_firmante = @p_Cuit)
AND id_cheque = (select max(id_cheque) from chequesBCRA b
where b.cuit_firmante = chequesBCRA.cuit_firmante
and b.nro_cheque = chequesBCRA.nro_cheque
and b.visible = 1)
AND visible = 1
AND
(
(
(
(
(fecha_levantamiento IS NULL)
AND
(fecha_rechazo >= @p_5anios)
)
OR
(
(
(fecha_levantamiento >= @p_5anios)
AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 15 )
)
AND
(
((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= (GETDATE() - 2)))
OR
(((fecha_pago IS NULL) AND (fecha_levantamiento >= (GETDATE() - 2))) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
((fecha_levantamiento >= @p_5anios)
AND (((datediff(day,fecha_rechazo,fecha_levantamiento)) >= 16 ) AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 90))
)
AND
(((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= @p_1anio))
OR (((fecha_pago IS NULL) AND (fecha_levantamiento >= @p_1anio)) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
(((fecha_levantamiento >= @p_5anios) AND
((datediff(day,fecha_rechazo,fecha_levantamiento)) > 90)) AND (fecha_levantamiento >= @p_2anios)
)
AND (fecha_rechazo >= @p_5anios)
)
)
)
SELECT @tipo = IIF(CharIndex('3',@p_Cuit)=1,'j',NULL)
IF @tipo = 'j'
BEGIN
SELECT top (@p_cantidad)
pf.nombre_persona AS 'nombre_persona_firmante',
cuit_firmante AS 'cuit_firmante',
pr.nombre_persona AS 'nombre_persona_relacionado',
Cuit_relacionado AS 'Cuit_relacionado',
pf.id_padron as idp,
pr.id_padron as idppr,
'0' as nro_cheque,
'0' AS fecha_rechazo,
'0' AS fecha_levantamiento,
'0' AS fecha_pago,
'0' AS importe,
count(nro_cheque) as cantidad,
'0' AS causa,
'vinculaciones' AS tipo,
@total_cheques as total_cheques
FROM
ChequesBCRA
LEFT JOIN padrones AS pf ON (pf.identificacion = cuit_firmante and pf.habilitado = 1) --info firmante
LEFT JOIN padrones AS pr ON (pr.identificacion = Cuit_relacionado and pr.habilitado = 1) --info relacionado
INNER JOIN Cheques_causales ON (ChequesBCRA.id_causa = Cheques_causales.id_causa)
WHERE
(Cuit_relacionado = @p_Cuit)
AND id_cheque = (select max(id_cheque) from chequesBCRA b
where b.cuit_firmante = chequesBCRA.cuit_firmante
and b.nro_cheque = chequesBCRA.nro_cheque
and b.visible = 1)
AND visible = 1
/*
AND
(
(
(
(
(fecha_levantamiento IS NULL)
AND
(fecha_rechazo >= @p_5anios)
)
OR
(
(
(fecha_levantamiento >= @p_5anios)
AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 15 )
)
AND
(
((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= (GETDATE() - 2)))
OR
(((fecha_pago IS NULL) AND (fecha_levantamiento >= @p_2anios)) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
((fecha_levantamiento >= @p_5anios)
AND (((datediff(day,fecha_rechazo,fecha_levantamiento)) >= 16 ) AND ((datediff(day,fecha_rechazo,fecha_levantamiento)) <= 90))
)
AND
(((fecha_pago IS NOT NULL) AND (fecha_levantamiento >= @p_1anio))
OR (((fecha_pago IS NULL) AND (fecha_levantamiento >= @p_2anios)) AND (fecha_rechazo >= @p_5anios))
)
)
)
OR
(
(((fecha_levantamiento >= @p_5anios) AND
((datediff(day,fecha_rechazo,fecha_levantamiento)) > 90)) AND (fecha_levantamiento >= @p_2anios)
)
AND (fecha_rechazo >= @p_5anios)
)
)
*/
group by pf.nombre_persona,ChequesBCRA.cuit_firmante,pr.nombre_persona,Cuit_relacionado,pf.id_padron,pr.id_padron
--ORDER BY fecha_rechazo, nro_cheque DESC
union
SELECT distinct
pf.nombre_persona AS 'nombre_persona_firmante',
cuita AS 'cuit_firmante',
pr.nombre_persona AS 'nombre_persona_relacionado',
Cuitb AS 'Cuit_relacionado',
pf.id_padron as idp,
pr.id_padron as idppr,
'0' as nro_cheque,
'0' AS fecha_rechazo,
'0' AS fecha_levantamiento,
'0' AS fecha_pago,
'0' AS importe,
'0' as cantidad,
'0' AS causa,
'vinculaciones' AS tipo,
@total_cheques as total_cheques
FROM
Relaciones
LEFT JOIN padrones AS pf ON (pf.identificacion = cuita and pf.habilitado = 1)
LEFT JOIN padrones AS pr ON (pr.identificacion = Cuitb and pr.habilitado = 1)
WHERE Cuitb = @p_Cuit
AND origen_del_dato = 'Cheques-BCRA'
and not exists (select * from ChequesBCRA where cuit_firmante = cuita and Cuit_relacionado = cuitb)
ORDER BY fecha_rechazo, nro_cheque DESC
END
END
GO
Depends On
4Used By
No items found