USE [Clinica]
GO
/****** Object:  View [Imed].[VWBonoInterfaz]    Script Date: 18-08-2025 21:38:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE view [Imed].[VWBonoInterfaz]
as
select
bi.IdBonoInterfaz,
bi.IdCita,
lb.FolioBono,
lb.FecEmi,
isnull(SUM(lpv.MontoBon), 0) as MontoBon,
isnull(SUM(lpv.MontoCopago), 0) as MontoCopago,
isnull(SUM(lpv.MontoPrest), 0) as MontoPrest,
isnull(SUM(lob.MtoBonAdic), 0) as MtoBonAdic

from Imed.BonoInterfaz bi
join Imed.ListaBono lb on lb.IdBonoInterfaz = bi.IdBonoInterfaz
join Imed.ListaPrestVta lpv on lpv.IdListaBono = lb.IdListaBono
left join Imed.ListaOtrasBon lob on lob.IdListaPrestVta = lpv.IdListaPrestVta
group by 
bi.IdBonoInterfaz,
bi.IdCita,
lb.FolioBono,
lb.FecEmi
GO
