$1 PROCEDURE FastSell_v2_StokSonHareketListe
@stok_kod varchar(25),
@cari_kod varchar(25),
@cikisMi bit--0 GİRİŞ--1ÇIKIŞ
AS
SELECT TOP 10 
	sth_cari_kodu as [Cari Kodu],
	dbo.fn_CarininIsminiBul(sth_cari_cinsi,sth_cari_kodu) as [Cari Unvan],
	dbo.fn_StokHarEvrTip(sth_evraktip) as [Evrak Tipi],
	CASE WHEN sth_normal_iade=0 THEN 'Normal' ELSE 'İade' END as [Normal/İade],
	sth_tarih as [Tarih],
	sth_miktar as [Miktar],
	ROUND((sth_tutar/sth_miktar),2) as [Birim Fiyat],
	ROUND(sth_tutar,2) as [Tutar],
		ROUND((sth_tutar-(sth_iskonto1+sth_iskonto2+sth_iskonto3+sth_iskonto4+sth_iskonto5+sth_iskonto6) +
    (sth_masraf1+sth_masraf2+sth_masraf3+sth_masraf4)+sth_vergi),2)/sth_miktar as [Birim Net Fiyat],
	ROUND((sth_tutar-(sth_iskonto1+sth_iskonto2+sth_iskonto3+sth_iskonto4+sth_iskonto5+sth_iskonto6) +
    (sth_masraf1+sth_masraf2+sth_masraf3+sth_masraf4)+sth_vergi),2) as [Net Tutar]
FROM dbo.STOK_HAREKETLERI WITH (NOLOCK)  LEFT OUTER JOIN dbo.STOK_HAREKETLERI_EK  
WITH (NOLOCK)  on (sthek_related_uid=sth_Guid)   WHERE (sth_stok_kod=@stok_kod) 
and ((@cari_kod!='' and sth_cari_kodu=@cari_kod) or @cari_kod='') and 
((@cikisMi=0 AND (not (sth_cins in (9,15))) AND (sth_tip = 0) and (sth_normal_iade=0) and (sth_tarih<=GETDATE()) AND (sth_evraktip in (0,1,3,4,5,6,7,8,9,12,13,14,16)))  OR
(@cikisMi=1 and (not (sth_cins in (9,15))) AND (sth_tip = 1) and (sth_normal_iade=0) and (sth_tarih<=GETDATE()) AND (sth_evraktip in (0,1,3,4,5,6,7,8,9,12,13,14,16)))) ORDER BY sth_tarih DESC
