dbo.backend_contratos_consumos

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@p_cliente int 4
@p_item_contrato int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

/*

exec backend_contratos_consumos 1068109769,419
exec backend_contratos_consumos 1068109769,409


select * from clientes where cliente = 1068109769


exec LN_informes 'tipos_informe_cliente', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1068109769



*/



CREATE OR ALTER PROCEDURE dbo.backend_contratos_consumos 
 @p_cliente int,
 @p_item_contrato int

AS
BEGIN
 SET NOCOUNT ON;
 
 declare @vItem int
 declare @vCliente int
 declare @vConsumo int
 declare @vContratado int
 declare @vDisponible int

 set @vItem = @p_item_contrato
 set @vCliente = @p_cliente

 select @vConsumo = ISNULL(SUM(consumo_contratos.cantidad_consumida),0) 
 from consumo_contratos
 inner join informes on consumo_contratos.informe = informes.informe
 where consumo_contratos.item_contrato = @vItem
 and informes.estado_informe NOT IN ('X', 'C', 'N') 
 group by consumo_contratos.item_contrato

 select @vContratado = cantidad_producto
 from contratos_items where id_contrato in (
 select id_contrato from contratos_grupos where grupo in (select grupo from grupos_clientes where cliente = @vCliente)
 and fecha_vigencia < getdate() and fecha_vencimiento > getdate() and estado_contrato='A')
 and contratos_items.item_contrato=@vItem

/* set @vConsumo = 12 */


 set @vDisponible = isnull(@vContratado,0)-isnull(@vConsumo,0)


 select @vCliente as cliente,@vItem as item,isnull(@vContratado,0) as contratado,isnull(@vConsumo,0) as consumido,@vDisponible as disponible

END

GO

Used By

No items found