Kasa ve işlemyap arasında makbuz no üzerinden bir baglantı kurup fatura kesilen makbuz noları sorgulayan fokniyon
CREATE OR REPLACE FUNCTION HASTANE.fatura_kesilen(kd1 IN NUMBER) RETURN number IS
fatura_toplam number;
BEGIN
select sum(ucreti) into fatura_toplam from hastane.islemyap where
makbuz_no=kd1 and fatura_no is not null;
RETURN(fatura_toplam);
END;
/
Yukarıda belirtilen fonkiyonu kasa detail tablosunda nakit kredi kartı ödeme türlerinde fatura kesilen ve kesilmiyen olarak adlandıran sql
select kasa_no,sum(nakit)Nakit,sum(nakitfatura)NakitFatura,(sum(nakit)-sum(nakitfatura))FaturasızNakit,sum(kredikart)Kredi,sum(kredifatura)KrediFatura,(sum(kredikart)-sum(kredifatura))FaturasızKredi
,sum(KPayiNakit)KPayiNakit,sum(KpayiKredi)KpayiKredi from (
select a.kasa_no,(ucret-ucretcikis) nakit,nvl(fatura_kesilen(a.makbuz_no),0)NakitFatura,0 KrediKart, 0KrediFatura,0 KPayiNakit,0 KpayiKredi from hastane.kasadetail a,hastane.veznekasa b where
a.kasa_no=b.kasa_no(+) and A.ODEME_TIPI='P' and B.ACILIS_T between to_date(:TAR1,'dd.mm.yyyy hh24:mi') and to_date(:TAR2,'dd.mm.yyyy hh24:mi') and A.KATKI_PAYIMI='H'
union all
select a.kasa_no,0 nakit,0 NakitFatura,(ucret-ucretcikis) KrediKart, nvl(fatura_kesilen(a.makbuz_no),0) KrediFatura,0 KPayiNakit,0 KpayiKredi from hastane.kasadetail a,hastane.veznekasa b where
a.kasa_no=b.kasa_no(+) and A.ODEME_TIPI='K' and B.ACILIS_T between to_date(:TAR1,'dd.mm.yyyy hh24:mi') and to_date(:TAR2,'dd.mm.yyyy hh24:mi') and A.KATKI_PAYIMI='H'
union all
select a.kasa_no,0 nakit,0 NakitFatura,0 KrediKart, nvl(fatura_kesilen(a.makbuz_no),0) KrediFatura,(ucret-ucretcikis) KPayiNakit,0 KpayiKredi from hastane.kasadetail a,hastane.veznekasa b where
a.kasa_no=b.kasa_no(+) and A.ODEME_TIPI='P' and B.ACILIS_T between to_date(:TAR1,'dd.mm.yyyy hh24:mi') and to_date(:TAR2,'dd.mm.yyyy hh24:mi') and A.KATKI_PAYIMI='E'
union all
select a.kasa_no,0 nakit,0 NakitFatura,0 KrediKart, nvl(fatura_kesilen(a.makbuz_no),0) KrediFatura,0 KPayiNakit,(ucret-ucretcikis) KpayiKredi from hastane.kasadetail a,hastane.veznekasa b where
a.kasa_no=b.kasa_no(+) and A.ODEME_TIPI='K' and B.ACILIS_T between to_date(:TAR1,'dd.mm.yyyy hh24:mi') and to_date(:TAR2,'dd.mm.yyyy hh24:mi') and A.KATKI_PAYIMI='E'
)
group by kasa_no
![](https://www.alisahan.com/wp-content/uploads/2022/03/kasa.png)