$1 PROCEDURE [dbo].[FastSell_v2_IrsaliyeFaturalastir]
@evrak_seri varchar(20),
@evrak_sira int,
@guidListe StringList READONLY
AS
DECLARE
@cha_vergi1 float,
@cha_vergi2 float,
@cha_vergi3 float,
@cha_vergi4 float,
@cha_vergi5 float,
@cha_vergi6 float,
@cha_vergi7 float,
@cha_vergi8 float,
@cha_vergi9 float,
@cha_vergi10 float,
@ara_toplam float,
@meblag float,
@iskonto1 float,
@iskonto2 float,
@iskonto3 float,
@iskonto4 float,
@iskonto5 float,
@iskonto6 float

BEGIN
SET @cha_vergi1 = (SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi2 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi3 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi4 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi5 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi6 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi7 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi8 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi9 =(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))
SET @cha_vergi10=(SELECT ISNULL(sum(sth_vergi),0) FROM STOK_HAREKETLERI WHERE (sth_Guid in (SELECT * FROM @guidListe)))

SET @iskonto1=(SELECT SUM(sth_iskonto1) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))		
SET @iskonto2=(SELECT SUM(sth_iskonto2) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))		
SET @iskonto3=(SELECT SUM(sth_iskonto3) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))		
SET @iskonto4=(SELECT SUM(sth_iskonto4) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))		
SET @iskonto5=(SELECT SUM(sth_iskonto5) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))	
SET @iskonto6=(SELECT SUM(sth_iskonto6) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))		

SET @ara_toplam=(SELECT SUM(sth_tutar) FROM STOK_HAREKETLERI WHERE sth_Guid in (SELECT * FROM @guidListe))
SET @meblag=(SELECT SUM((((sth_tutar) - (sth_iskonto1+sth_iskonto2+sth_iskonto3+sth_iskonto4+sth_iskonto5+sth_iskonto6)) +
		(sth_masraf1+sth_masraf2+sth_masraf3+sth_masraf4)) + (sth_vergi))
		FROM STOK_HAREKETLERI
		WHERE sth_Guid in (SELECT * FROM @guidListe))



UPDATE CARI_HESAP_HAREKETLERI
SET
cha_vergi1=@cha_vergi1,
cha_vergi2=@cha_vergi2,
cha_vergi3=@cha_vergi3,
cha_vergi4=@cha_vergi4,
cha_vergi5=@cha_vergi5,
cha_vergi6=@cha_vergi6,
cha_vergi7=@cha_vergi7,
cha_vergi8=@cha_vergi8,
cha_vergi9=@cha_vergi9,
cha_vergi10=@cha_vergi10,
cha_ft_iskonto1=@iskonto1,
cha_ft_iskonto2=@iskonto2,
cha_ft_iskonto3=@iskonto3,
cha_ft_iskonto4=@iskonto4,
cha_ft_iskonto5=@iskonto5,
cha_ft_iskonto6=@iskonto6,
cha_aratoplam=@ara_toplam,
cha_meblag=@meblag
WHERE cha_evrak_tip=63 and cha_evrakno_seri=@evrak_seri and cha_evrakno_sira=@evrak_sira

DECLARE 
@cha_Guid varchar(36)
SET @cha_Guid=(SELECT TOP 1 cha_Guid FROM CARI_HESAP_HAREKETLERI WHERE cha_evrak_tip=63 and cha_evrakno_seri=@evrak_seri and cha_evrakno_sira=@evrak_sira)

UPDATE STOK_HAREKETLERI
	SET sth_fat_uid=@cha_Guid WHERE sth_Guid in (SELECT * FROM @guidListe)

end


