$1 FUNCTION  [dbo].[fn_FastSell_v2_StokSonGiris]
(
@sto_kod nvarchar(25), 
@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 
		Where sth_stok_kod=@sto_kod  and sth_normal_iade = 0 
		  and sth_tip in (0) 
		Order by sth_tarih desc
Return ISNULL(@SonAlis,0)
End