dbo.grafico_card_cheques_rechazados

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_cuit varchar 13

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE  dbo.grafico_card_cheques_rechazados
    @p_cuit varchar(13)
AS
BEGIN
    DECLARE @tipo varchar(1)
    DECLARE @p_5anios smalldatetime = getdate() - 1825
    DECLARE @p_2anios smalldatetime = getdate() - 730
    DECLARE @p_1anio  smalldatetime = getdate() - 365
    DECLARE @hoy date = convert(date,getdate())
    DECLARE @respuesta table (anio varchar, mes int, tipo char(10), cantidad int) 

 SET NOCOUNT ON;
 --select * from ChequesBCRA where cuit_firmante = '30501677643' and fecha_rechazo between getdate()-365 and  getdate() and visible = 1
 --insert into @respuesta 
 
    SELECT  convert(varchar(13),cast(datepart(YYYY,fecha_rechazo) as varchar(4))+'-'+right('00' + cast(DATEPART(MM,fecha_rechazo) as varchar(4)),2)) as fecha, tipo = iif(cuit_relacionado is null or ltrim(rtrim(cuit_relacionado)) = '', 'propio','empresa'),iif(ChequesBCRA.fecha_levantamiento is null,0,1) as abonado, id_causa
     FROM chequesBCRA WHERE
            (Cuit_firmante = @p_Cuit)
         AND not exists(select * from chequesBCRA b 
                 where b.cuit_firmante = chequesBCRA.cuit_firmante 
               and b.nro_cheque = chequesBCRA.nro_cheque 
               and b.visible = 1 
               and b.id_cheque > chequesBCRA.id_cheque)
            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) 
    )
   )
END

GO

Depends On

1

Used By

No items found