IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'dbo.CP_Stat') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE dbo.CP_Stat
END
GO


CREATE PROCEDURE CP_Stat @Fecha DATE
AS
DECLARE @param VARCHAR(5000)


EXEC CP_Clientes_Estadisticas_Hist @Fecha


SET @param = '{"Id_Usuario":"-1"
							,"Equate":"90"
							,"FechaDesde":"'+ CONVERT(CHAR(8),@Fecha,112)+'"
							,"FechaHasta":"'+ CONVERT(CHAR(8),@Fecha,112)+'"
							,"Flag_Liquidacion":"0"
							,"Flag_FPago":"0"
							,"Tipo_Cob":""
							,"Formato":"T"
							,"Flag_Filtrar_Prod":"0"
							,"Flag_Filtrar_Fam":"0"
							,"Flag_Filtrar_Caja":"0"
							,"Id_Familia":""
							,"Id_Producto":""
							,"Id_Cliente":""
							,"Regenerar_Archivo":"S"
							,"Flag_Inc_Fact_Periodo":"0"}' 
EXEC CPJ_Productos_Cobros  @param  

RETURN

