$1 FUNCTION  [dbo].[fn_FastSell_v2_StokMaliyet]
(
@barkod nvarchar(25),
@depo int,--0 tüm depolar
@tarih datetime
)
RETURNS float AS
BEGIN
	DECLARE 
		@SonAlis float = 0
		Select Top 1
			@SonAlis = ((((((sth_tutar) - (sth_iskonto1+sth_iskonto2+sth_iskonto3+sth_iskonto4+sth_iskonto5+sth_iskonto6)) +
		(sth_masraf1+sth_masraf2+sth_masraf3+sth_masraf4))+sth_vergi) / (sth_miktar)))
		From STOK_HAREKETLERI 
		LEFT OUTER JOIN BARKOD_TANIMLARI ON sth_stok_kod=bar_stokkodu
		Where bar_kodu=@barkod  and sth_normal_iade = 0
		 and (sth_giris_depo_no = @depo or @depo=0)
		  and sth_tip in (0,2) and sth_evraktip in (2,3,13,15)
		Order by sth_tarih desc
Return ISNULL(@SonAlis,0)
End