Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
6| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_Cuit | varchar | 20 | |
| @p_cliente | int | 4 | |
| @causal | int | 4 | |
| @levantados | char | 1 | |
| @cantidad | decimal | 13 | |
| @monto | decimal | 13 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
DECLARE @monto decimal(20,2), @cantidad int
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '2', 'N', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '2', 'S', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '1', 'S', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '1', 'N', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
*/
CREATE OR ALTER PROCEDURE dbo.LN_alertas_cheques_cliente_montos
@p_Cuit varchar(20),
@p_cliente int,
@causal int = 2,
@levantados char(1) = 'N',
@cantidad decimal(20,2) = NULL OUTPUT,
@monto decimal(20,2) = NULL OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @p_5anios smalldatetime = getdate() - 1825
DECLARE @p_2anios smalldatetime = getdate() - 730
DECLARE @p_1anio smalldatetime = getdate() - 365
DECLARE @dias int
declare @monto_rechazados decimal(20,2)
declare @total_rechazados int = 0
select @dias = max(dias)
from ln_dias_alertas
where tabla = 'cheques' and cliente = @p_Cliente
if (@dias is null)
begin
set @dias = 720 -- default 2 aƱos
end
select @monto_rechazados = SUM(ChequesBCRA.importe) ,
@total_rechazados = count(*)
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 ChequesBCRA.id_causa = @causal
AND ((@levantados = 'N' AND ChequesBCRA.fecha_levantamiento IS NULL)
or
(@levantados = 'S' AND ChequesBCRA.fecha_levantamiento IS NOT NULL)
or
(@levantados is null))
AND (visible = 1)
AND ChequesBCRA.fecha_rechazo >= (GETDATE()-@dias)
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)
)
)
SET @monto = @monto_rechazados
SET @cantidad = @total_rechazados
END
GO
GO
/*
DECLARE @monto decimal(20,2), @cantidad int
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '2', 'N', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '2', 'S', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '1', 'S', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
EXEC [LN_alertas_cheques_cliente_montos] '20293314102', '5546348', '1', 'N', @cantidad output, @monto output
select @cantidad as cantidad, @monto as monto
*/
CREATE OR ALTER PROCEDURE dbo.LN_alertas_cheques_cliente_montos
@p_Cuit varchar(20),
@p_cliente int,
@causal int = 2,
@levantados char(1) = 'N',
@cantidad decimal(20,2) = NULL OUTPUT,
@monto decimal(20,2) = NULL OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @p_5anios smalldatetime = getdate() - 1825
DECLARE @p_2anios smalldatetime = getdate() - 730
DECLARE @p_1anio smalldatetime = getdate() - 365
DECLARE @dias int
declare @monto_rechazados decimal(20,2)
declare @total_rechazados int = 0
select @dias = max(dias)
from ln_dias_alertas
where tabla = 'cheques' and cliente = @p_Cliente
if (@dias is null)
begin
set @dias = 720 -- default 2 aƱos
end
select @monto_rechazados = SUM(ChequesBCRA.importe) ,
@total_rechazados = count(*)
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 ChequesBCRA.id_causa = @causal
AND ((@levantados = 'N' AND ChequesBCRA.fecha_levantamiento IS NULL)
or
(@levantados = 'S' AND ChequesBCRA.fecha_levantamiento IS NOT NULL)
or
(@levantados is null))
AND (visible = 1)
AND ChequesBCRA.fecha_rechazo >= (GETDATE()-@dias)
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)
)
)
SET @monto = @monto_rechazados
SET @cantidad = @total_rechazados
END
GO