CREATE PROCEDURE [dbo].[spBankFisKaydet]
@Tur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@FisNo		nvarchar(20),
@AnaId		decimal,
@MerkId		decimal,
@PersId		decimal,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_BankaFis(
		BnFTur,BnFTarih,BnFSaat,BnFEvrakNo,BnFFisNo,BnFHesapId,BnFsMerkId,BnFPersId,BnFAciklama,BnFOzelKod1,
		BnFOzelKod2,BnFOzelKod3,BnFKayKullanici,BnFMagazaKodu,BnFKayitTarihi,BnFKayitSaati
		) VALUES (
		@Tur,@Tarih,@Saat,@EvrakNo,@FisNo,@AnaId,@MerkId,@PersId,@Aciklama,@OzelKod1,
		@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_BankaFis SET
		BnFTur=@Tur,BnFTarih=@Tarih,BnFSaat=@Saat,BnFEvrakNo=@EvrakNo,BnFFisNo=@FisNo,
		BnFHesapId=@AnaId,BnFsMerkId=@MerkId,BnFPersId=@PersId,BnFAciklama=@Aciklama,
		BnFOzelKod1=@OzelKod1,BnFOzelKod2=@OzelKod2,BnFOzelKod3=@OzelKod3,BnFDuzKullanici=@Kullanici,
		BnFDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		BnFDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		BnFMagazaKodu=@MagazaKodu
		WHERE BnFId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spBankHarKaydet]
@FisId		decimal,
@Tur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@AnaId		decimal,
@Tipi		tinyint,
@KarsiHsId	decimal,
@Tutar		money,
@Faiz		money,
@KdvOrn		money,
@DovizTip	nvarchar(5),
@Doviz		nvarchar(4),
@DovizTutar	money,
@Kur		money,
@MsMerkId	decimal,
@PersId		decimal,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Komisyon	money,
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_BankaHareket(
		BnHFisId,BnHTur,BnHTarih,BnHSaat,BnhEvrakNo,BnHHesapId,BnHTipi,BnHKarsiHsId,BnHFaiz,BnHKdvOrn,BnHKomisyon, 
		BnHTutar,BnHDovizTip,BnHDoviz,BnHDovizTutar,BnHKur,BnHMsMerkId,BnHPersId,BnHAciklama,BnHOzelKod1,BnHOzelKod2,
		BnHOzelKod3,BnHKayKullanici,BnHMagazaKodu,BnHKayitTarihi,BnHKayitSaati
		) VALUES (
		@FisId,@Tur,@Tarih,@Saat,@EvrakNo,@AnaId,@Tipi,@KarsiHsId,@Faiz,@KdvOrn,@Komisyon,  
		@Tutar,@DovizTip,@Doviz,@DovizTutar,@Kur,@MsMerkId,@PersId,@Aciklama,
		@OzelKod1,@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_BankaHareket SET
		BnHFisId=@FisId,BnHTur=@Tur,BnHTarih=@Tarih,BnHSaat=@Saat,BnHKdvOrn=@KdvOrn,
		BnHEvrakNo=@EvrakNo,BnHHesapId=@AnaId,BnHTipi=@Tipi,BnHFaiz=@Faiz,BnHKomisyon=@Komisyon,
		BnHKarsiHsId=@KarsiHsId,BnHTutar=@Tutar,BnHDovizTip=@DovizTip,BnHDoviz=@Doviz,
		BnHDovizTutar=@DovizTutar,BnHKur=@Kur,BnHMsMerkId=@MsMerkId,BnHPersId=@PersId,
		BnHAciklama=@Aciklama,BnHOzelKod1=@OzelKod1,BnHOzelKod2=@OzelKod2,BnHOzelKod3=@OzelKod3,
		BnHDuzKullanici=@Kullanici,BnHMagazaKodu=@MagazaKodu,
		BnHDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		BnHDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE BnHId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spCariFisKaydet]
@Tur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@FisNo		nvarchar(20),
@AnaId		decimal,
@MerkId		decimal,
@PersId		decimal,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_CariFis(
		CrFTur,CrFTarih,CrFSaat,CrFEvrakNo,CrFFisNo,CrFCariId,CrFsMerkId,CrFPersId,CrFAciklama,CrFOzelKod1,
		CrFOzelKod2,CrFOzelKod3,CrFKayKullanici,CrFMagazaKodu,CrFKayitTarihi,CrFKayitSaati
		) VALUES (
		@Tur,@Tarih,@Saat,@EvrakNo,@FisNo,@AnaId,@MerkId,@PersId,@Aciklama,@OzelKod1,
		@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_CariFis SET
		CrFTur=@Tur,CrFTarih=@Tarih,CrFSaat=@Saat,CrFEvrakNo=@EvrakNo,CrFFisNo=@FisNo,
		CrFCariId=@AnaId,CrFsMerkId=@MerkId,CrFPersId=@PersId,CrFAciklama=@Aciklama,
		CrFOzelKod1=@OzelKod1,CrFOzelKod2=@OzelKod2,CrFOzelKod3=@OzelKod3,CrFDuzKullanici=@Kullanici,
		CrFDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		CrFDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		CrFMagazaKodu=@MagazaKodu
		WHERE CrFId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spCariHarKaydet]
@FisId		decimal,
@Tur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@AnaId		decimal,
@Tipi		tinyint,
@BrAl		tinyint,
@KarsiHsId	decimal,
@Tutar		money,
@Faiz		money,
@DovizTip	nvarchar(5),
@Doviz		nvarchar(4),
@DovizTutar	money,
@Kur		money,
@MsMerkId	decimal,
@PersId		decimal,
@Taksit		tinyint,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@EkPosId	decimal,
@EntgTipi	tinyint,
@EntgId		decimal,
@Deger		Decimal,
@Yeni		Decimal
AS

BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_CariHareket(
		CrHFisId,CrHTur,CrHTarih,CrHSaat,CrhEvrakNo,CrHCariId,CrHTipi,CrHBrAl,CrHKarsiHsId,CrHFaiz,CrHTaksit,
		CrHTutar,CrHDovizTip,CrHDoviz,CrHDovizTutar,CrHKur,CrHMsMerkId,CrHPersId,CrHAciklama,CrHOzelKod1,
		CrHOzelKod2,CrHOzelKod3,CrHEntgTipi,CrHEntgId,CrHKayKullanici,CrHMagazaKodu,CrHEkPosId,
		CrHKayitTarihi,CrHKayitSaati
		) VALUES (
		@FisId,@Tur,@Tarih,@Saat,@EvrakNo,@AnaId,@Tipi,@BrAl,@KarsiHsId,@Faiz,@Taksit,  
		@Tutar,@DovizTip,@Doviz,@DovizTutar,@Kur,@MsMerkId,@PersId,@Aciklama,
		@OzelKod1,@OzelKod2,@OzelKod3,@EntgTipi,@EntgId,@Kullanici,@MagazaKodu,@EkPosId,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_CariHareket SET
		CrHFisId=@FisId,CrHTur=@Tur,CrHTarih=@Tarih,CrHSaat=@Saat,
		CrhEvrakNo=@EvrakNo,CrHCariId=@AnaId,CrHTipi=@Tipi,CrHBrAl=@BrAl,CrHFaiz = @Faiz, 
		CrHKarsiHsId=@KarsiHsId,CrHTutar=@Tutar,CrHDovizTip=@DovizTip,CrHDoviz=@Doviz,
		CrHDovizTutar=@DovizTutar,CrHKur=@Kur,CrHMsMerkId=@MsMerkId,CrHPersId=@PersId,
		CrHAciklama=@Aciklama,CrHOzelKod1=@OzelKod1,CrHOzelKod2=@OzelKod2,CrHOzelKod3=@OzelKod3,
		CrHDuzKullanici=@Kullanici,CrHMagazaKodu=@MagazaKodu,CrHTaksit=@Taksit, 
		CrHEntgTipi=@EntgTipi,CrhEntgId=@EntgId,CrHEkPosId=@EkPosId,
		CrHDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		CrHDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE CrHId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spCariHarSil]
@Deger			DECIMAL,
@Type			TINYINT,
@Senet			TINYINT

AS
BEGIN TRANSACTION
IF @Type = 0 DECLARE CrHar CURSOR FOR SELECT CrHCariId,CrHTipi,CrHTutar,CrHTur,CrHBrAl,CrHKarsiHsId,CrHId,CrHFaiz,CrHDovizTutar FROM Tb_CariHareket where CrHFisId = @Deger 
ELSE DECLARE CrHar CURSOR FOR SELECT CrHCariId,CrHTipi,CrHTutar,CrHTur,CrHBrAl,CrHKarsiHsId,CrHId,CrHFaiz,CrHDovizTutar FROM Tb_CariHareket where CrHId = @Deger  

DECLARE @AnaId DECIMAL
DECLARE @Tutar MONEY
DECLARE @DovTutar MONEY
DECLARE @Tipi TINYINT
DECLARE @Tur TINYINT
DECLARE @BrAl TINYINT
DECLARE @KarsiHs DECIMAL
DECLARE @HrkId DECIMAL
DECLARE @Faiz Money
DECLARE @SenetId DECIMAL
DECLARE @Durum TINYINT

OPEN CrHar
FETCH NEXT FROM CrHar INTO @AnaId,@Tipi,@Tutar,@Tur,@BrAl,@KarsiHs,@HrkId,@Faiz,@DovTutar
WHILE @@FETCH_STATUS=0
BEGIN
	IF @Tur = 1 BEGIN /* Tahsilat */
		IF @Tipi= 4 OR @Tipi = 5 BEGIN
			DELETE Tb_CkSnKart WHERE CksId = @KarsiHs
		END
		IF @Tipi = 1 DELETE Tb_HesGecme WHERE HsgSatisId = @HrkId AND HsgModul=1 
		IF @Senet = 1 BEGIN
			DECLARE Deneme CURSOR FOR SELECT ISNULL(CksId,0),CksDurum FROM Tb_TaksitTahsil TH LEFT JOIN Tb_Taksit TK ON TK.TakId = TH.TkOTaksitId LEFT JOIN Tb_CkSnKart CK ON CK.CksId=TK.TakSenetId WHERE TkOTahsilId =@HrkId AND TkOTipi = 0 AND TkOModul = 1
			OPEN Deneme
			FETCH NEXT FROM Deneme INTO @SenetId,@Durum
			WHILE @@FETCH_STATUS=0
			BEGIN
				IF @SenetId > 0 BEGIN
					IF @Durum = 3 EXEC.spCkSnDrChn @KartId=@SenetId
				END
				FETCH NEXT FROM Deneme INTO @SenetId,@Durum
			END
			CLOSE Deneme
			DEALLOCATE Deneme
		END
		DELETE Tb_TaksitTahsil WHERE TkOCariId = @AnaId AND TkOTahsilId =@HrkId AND TkOTipi = 0 AND TkOModul = 1 
		DELETE Tb_FaturaTahsil WHERE FtOCariId = @AnaId AND FtOTahsilId =@HrkId AND FtOTipi = 0
	END
	IF @Tur = 2 BEGIN /* Ödeme */
		IF @Tipi= 4 OR @Tipi = 5 BEGIN
			IF @BrAl = 0 EXEC.spCkSnDrChn @KartId=@KarsiHs 
			IF @BrAl = 1 DELETE Tb_CkSnKart WHERE CksId = @KarsiHs
		END
		DELETE Tb_FaturaTahsil WHERE FtOCariId = @AnaId AND FtOTahsilId =@HrkId
	END
	FETCH NEXT FROM CrHar INTO @AnaId,@Tipi,@Tutar,@Tur,@BrAl,@KarsiHs,@HrkId,@Faiz,@DovTutar
END
CLOSE CrHar
DEALLOCATE CrHar
IF @Type = 0 
BEGIN
	DELETE FROM Tb_CariFis WHERE CrFId=@Deger 
	DELETE FROM Tb_CariHareket WHERE CrHFisId=@Deger
	IF @Senet = 1 BEGIN
		DECLARE Deneme CURSOR FOR SELECT ISNULL(CksId,0),CksDurum FROM Tb_TaksitTahsil TH LEFT JOIN Tb_Taksit TK ON TK.TakId = TH.TkOTaksitId LEFT JOIN Tb_CkSnKart CK ON CK.CksId=TK.TakSenetId WHERE TkOTahsilId =@Deger AND TkOTipi = 1 AND TkOModul = 1
		OPEN Deneme
		FETCH NEXT FROM Deneme INTO @SenetId,@Durum
		WHILE @@FETCH_STATUS=0
		BEGIN
			IF @SenetId > 0 BEGIN
				IF @Durum = 3 EXEC.spCkSnDrChn @KartId=@SenetId
			END
			FETCH NEXT FROM Deneme INTO @SenetId,@Durum
		END
		CLOSE Deneme
		DEALLOCATE Deneme
	END
	DELETE Tb_TaksitTahsil WHERE TkOCariId = @AnaId AND TkOTahsilId = @Deger AND TkOTipi = 1 AND TkOModul = 1 
	DELETE Tb_FaturaTahsil WHERE FtOCariId = @AnaId AND FtOTahsilId = @Deger AND FtOTipi = 1
END
ELSE 
BEGIN
	SELECT @KarsiHs=CrHFisId FROM Tb_CariHareket WHERE CrHId=@Deger
	DELETE FROM Tb_CariHareket where CrHId=@Deger 
	SELECT @Durum = COUNT(*) FROM Tb_CariHareket WHERE CrHFisId=@KarsiHs
	IF @Durum = 0 DELETE FROM Tb_CariFis WHERE CrFId=@KarsiHs
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spCariKartKaydet]
@CarKod				nvarchar(30),
@CarUnvan			nvarchar(100),
@CarKartTur			tinyint,
@CarAd				nvarchar(30),
@CarSoyAd			nvarchar(50),
@CarTelf1			nvarchar(20),
@CarTelf2			nvarchar(20),
@CarTelf3			nvarchar(20),
@CarTelf4			nvarchar(20),
@CarTelf5			nvarchar(20),
@CarOzelKod1		nvarchar(20),
@CarOzelKod2		nvarchar(20),
@CarOzelKod3		nvarchar(20),
@CarOzelKod4		nvarchar(20),
@CarOzelKod5		nvarchar(20),
@CarKrediLimit		money,
@CarRiskLimit		money,
@CarOdeGun			smallint,
@CarAnaIsk			money,
@CarVerDaire		nvarchar(20),
@CarVerNo			nvarchar(20),
@CarAnaGrup			nvarchar(5),
@CarMail			nvarchar(50),
@CarKartNo			nvarchar(20),
@CarAnaAdres		nvarchar(100),
@CarAnaSemt			nvarchar(20),
@CarAnaIlce			nvarchar(20),
@CarAnaIl			nvarchar(20),
@CarAnaUlke			nvarchar(20),
@CarAnaPosta		nvarchar(10),
@CarAciklama		nvarchar(1000),
@CarUyari			nvarchar(200),
@CarResim			nvarchar(200),
@CarResim1			nvarchar(200),
@CarSekId			decimal,
@CarSorId			decimal,
@CarWebAdr			nvarchar(200),
@CarAltGrup			nvarchar(5),
@CarIsk1			money,
@CarIsk2			money,
@CarSipUst			money,
@CarSipAlt			money,
@CarDoviz			nvarchar(4),
@CarDovizTip		nvarchar(5),
@CarOdGun			tinyint,
@CarOdTur			tinyint,
@CarYazisma			tinyint,
@CarFatura			tinyint,
@CarSevk			tinyint,
@CarVdFrGec			money,
@CarVdFrErk			money,
@CarTanimlar		nvarchar(30),
@CarKartTipi		nvarchar(30),
@CarAciklama1		nvarchar(50),
@CarAciklama2		nvarchar(50),
@CarAciklama3		nvarchar(50),
@CarEkTutar1		money,
@CarEkTutar2		money,
@CarEkTutar3		money,
@CarEkOran1			money,
@CarEkOran2			money,
@CarEkOran3			money,
@CarKullanici		nvarchar(20),
@CarMagazaKodu		nvarchar(50),
@CarCinsiyet		tinyint,
@CarDogumYer		nvarchar(20),
@CarMedeniHal		tinyint,
@CarDogumTarih		date,
@CarEvlilikTarih	date,
@CarEsAd			nvarchar(20),
@CarCocukSayi		tinyint,
@CarAnaAd			nvarchar(20),
@CarBabaAd			nvarchar(20),
@CarAnneKzSoyad		nvarchar(20),
@CarOturEv			tinyint,
@CarAylikKira		money,
@CarOturmaYil		tinyint,
@CarHaneKisi		tinyint,
@CarAskerlik		tinyint,
@CarOgrenim			tinyint,
@CarDin				tinyint,
@CarKan				tinyint,
@CarTcKimlikNo		nvarchar(20),
@CarKimlikNo		nvarchar(20),
@CarKimIl			nvarchar(20),
@CarKimIlce			nvarchar(20),
@CarKimKoy			nvarchar(20),
@CarKimVerYer		nvarchar(20),
@CarKimVerNed		nvarchar(20),
@CarKimTarih		date,
@CarCiltNo			nvarchar(5),
@CarSiraNo			nvarchar(5),
@CarAileNo			nvarchar(5),
@CarUyruk			tinyint,
@CarUyrukUlke		nvarchar(20),
@CarIsyeriAd		nvarchar(30),
@CarGorev			nvarchar(20),
@CarSskNo			nvarchar(20),
@CarEmekliNo		nvarchar(20),
@CarEhliyetTip		nvarchar(2),
@CarEhliyetNo		nvarchar(20),
@CarEhliyetTarih	date,
@CarPasaportNo		nvarchar(20),
@CarMeslek			nvarchar(20),
@CarIlceId			decimal,
@CarIlId			decimal,
@CarUlkeId			decimal,
@CarEftSnTip		tinyint,
@CarEftGnTip		tinyint,
@CarEftTipi			tinyint,
@CarEftPsKt			nvarchar(50),
@CarEirTipi			tinyint,
@CarEiRPsKt			nvarchar(50),
@Deger				Decimal,
@Yeni				Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_CariKart(
		CarKod,CarUnvan,CarKartTur,CarAd,CarSoyAd,CarTelf1,CarTelf2,CarTelf3,CarTelf4,CarTelf5,CarOzelKod1,CarOzelKod2,
		CarOzelKod3,CarOzelKod4,CarOzelKod5,CarKrediLimit,CarRiskLimit,CarOdeGun,CarAnaIsk,CarVerDaire,CarVerNo,CarAnaGrup,
		CarMail,CarKartNo,CarAnaAdres,CarAnaSemt,CarAnaIlce,CarAnaIl,CarAnaUlke,CarAnaPosta,CarAciklama,CarUyari,CarResim,
		CarSekId,CarSorId,CarWebAdr,CarAltGrup,CarIsk1,CarIsk2,CarSipUst,CarSipAlt,CarDoviz,CarDovizTip,CarOdGun,CarOdTur,
		CarYazisma,CarFatura,CarSevk,CarVdFrGec,CarVdFrErk,CarTanimlar,CarKartTipi,CarAciklama1,CarAciklama2,CarAciklama3,
		CarEkTutar1,CarEkTutar2,CarEkTutar3,CarEkOran1,CarEkOran2,CarEkOran3,CarKayKullanici,CarKayitTarihi,CarKayitSaati,
		CarMagazaKodu,CarCinsiyet,CarDogumYer,CarMedeniHal,CarDogumTarih,CarEftSnTip,CarEftGnTip,CarEftTipi,CarEirTipi,
		CarEvlilikTarih,CarEsAd,CarCocukSayi,CarAnaAd,CarBabaAd,CarAnneKzSoyad,CarOturEv,CarAylikKira,CarOturmaYil,CarEiRPsKt,
		CarHaneKisi,CarAskerlik,CarOgrenim,CarDin,CarKan,CarTcKimlikNo,CarKimlikNo,CarKimIl,CarKimIlce,CarKimKoy,CarKimVerYer,
		CarKimVerNed,CarKimTarih,CarCiltNo,CarSiraNo,CarAileNo,CarUyruk,CarUyrukUlke,CarIsyeriAd,CarGorev,CarSskNo,CarEmekliNo,
		CarEhliyetTip,CarEhliyetNo,CarEhliyetTarih,CarPasaportNo,CarMeslek,CarIlId,CarIlceId,CarUlkeId,CarResim1,CarEftPsKt
		) VALUES (
		@CarKod,@CarUnvan,@CarKartTur,@CarAd,@CarSoyAd,@CarTelf1,@CarTelf2,@CarTelf3,@CarTelf4,@CarTelf5,@CarOzelKod1,
		@CarOzelKod2,@CarOzelKod3,@CarOzelKod4,@CarOzelKod5,@CarKrediLimit,@CarRiskLimit,@CarOdeGun,@CarAnaIsk,@CarVerDaire,
		@CarVerNo,@CarAnaGrup,@CarMail,@CarKartNo,@CarAnaAdres,@CarAnaSemt,@CarAnaIlce,@CarAnaIl,@CarAnaUlke,@CarAnaPosta,
		@CarAciklama,@CarUyari,@CarResim,@CarSekId,@CarSorId,@CarWebAdr,@CarAltGrup,@CarIsk1,@CarIsk2,@CarSipUst,
		@CarSipAlt,@CarDoviz,@CarDovizTip,@CarOdGun,@CarOdTur,@CarYazisma,@CarFatura,@CarSevk,@CarVdFrGec,@CarVdFrErk,
		@CarTanimlar,@CarKartTipi,@CarAciklama1,@CarAciklama2,@CarAciklama3,@CarEkTutar1,@CarEkTutar2,@CarEkTutar3,
		@CarEkOran1,@CarEkOran2,@CarEkOran3,@CarKullanici,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		@CarMagazaKodu,@CarCinsiyet,@CarDogumYer,@CarMedeniHal,@CarDogumTarih,@CarEftSnTip,@CarEftGnTip,@CarEftTipi,@CarEirTipi,
		@CarEvlilikTarih,@CarEsAd,@CarCocukSayi,@CarAnaAd,@CarBabaAd,@CarAnneKzSoyad,@CarOturEv,@CarAylikKira,
		@CarOturmaYil,@CarEiRPsKt,@CarHaneKisi,@CarAskerlik,@CarOgrenim,@CarDin,@CarKan,@CarTcKimlikNo,@CarKimlikNo,@CarKimIl,
		@CarKimIlce,@CarKimKoy,@CarKimVerYer,@CarKimVerNed,@CarKimTarih,@CarCiltNo,@CarSiraNo,@CarAileNo,@CarUyruk,
		@CarUyrukUlke,@CarIsyeriAd,@CarGorev,@CarSskNo,@CarEmekliNo,@CarEhliyetTip,@CarEhliyetNo,@CarEhliyetTarih,
		@CarPasaportNo,@CarMeslek,@CarIlId,@CarIlceId,@CarUlkeId,@CarResim1,@CarEftPsKt)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_CariKart SET
		CarKod=@CarKod,CarUnvan=@CarUnvan,CarKartTur=@CarKartTur,CarAd=@CarAd,CarSoyAd=@CarSoyAd,CarTelf1=@CarTelf1,
		CarTelf2=@CarTelf2,CarTelf3=@CarTelf3,CarTelf4=@CarTelf4,CarTelf5=@CarTelf5,CarOzelKod1=@CarOzelKod1,
		CarOzelKod2=@CarOzelKod2,CarOzelKod3=@CarOzelKod3,CarOzelKod4=@CarOzelKod4,CarOzelKod5=@CarOzelKod5,
		CarKrediLimit=@CarKrediLimit,CarRiskLimit=@CarRiskLimit,CarOdeGun=@CarOdeGun,CarAnaIsk=@CarAnaIsk,
		CarVerDaire=@CarVerDaire,CarVerNo=@CarVerNo,CarAnaGrup=@CarAnaGrup,CarMail=@CarMail,CarKartNo=@CarKartNo,
		CarAnaAdres=@CarAnaAdres,CarAnaSemt=@CarAnaSemt,CarAnaIlce=@CarAnaIlce,CarAnaIl=@CarAnaIl,CarAnaUlke=@CarAnaUlke,
		CarAnaPosta=@CarAnaPosta,CarAciklama=@CarAciklama,CarUyari=@CarUyari,CarResim=@CarResim,CarSekId=@CarSekId,
		CarSorId=@CarSorId,CarWebAdr=@CarWebAdr,CarAltGrup=@CarAltGrup,CarIsk1=@CarIsk1,CarIsk2=@CarIsk2,
		CarSipUst=@CarSipUst,CarSipAlt=@CarSipAlt,CarDoviz=@CarDoviz,CarDovizTip=@CarDovizTip,CarOdGun=@CarOdGun,
		CarOdTur=@CarOdTur,CarYazisma=@CarYazisma,CarFatura=@CarFatura,CarSevk=@CarSevk,CarVdFrGec=@CarVdFrGec,
		CarVdFrErk=@CarVdFrErk,CarTanimlar=@CarTanimlar,CarKartTipi=@CarKartTipi,CarAciklama1=@CarAciklama1,
		CarAciklama2=@CarAciklama2,CarAciklama3=@CarAciklama3,CarEkTutar1=@CarEkTutar1,CarEkTutar2=@CarEkTutar2,
		CarEkTutar3=@CarEkTutar3,CarEkOran1=@CarEkOran1,CarEkOran2=@CarEkOran2,CarEkOran3=@CarEkOran3,CarEftTipi=@CarEftTipi,
		CarDuzKullanici=@CarKullanici,CarDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		CarDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),CarEftSnTip=@CarEftSnTip,
		CarMagazaKodu=@CarMagazaKodu,CarCinsiyet=@CarCinsiyet,CarDogumYer=@CarDogumYer,CarMedeniHal=@CarMedeniHal,
		CarDogumTarih=@CarDogumTarih,CarEvlilikTarih=@CarEvlilikTarih,CarEsAd=@CarEsAd,CarCocukSayi=@CarCocukSayi,
		CarAnaAd=@CarAnaAd,CarBabaAd=@CarBabaAd,CarAnneKzSoyad=@CarAnneKzSoyad,CarOturEv=@CarOturEv,CarEftGnTip=@CarEftGnTip,
		CarAylikKira=@CarAylikKira,CarOturmaYil=@CarOturmaYil,CarHaneKisi=@CarHaneKisi,CarAskerlik=@CarAskerlik,
		CarOgrenim=@CarOgrenim,CarDin=@CarDin,CarKan=@CarKan,CarTcKimlikNo=@CarTcKimlikNo,CarKimlikNo=@CarKimlikNo,
		CarKimIl=@CarKimIl,CarKimIlce=@CarKimIlce,CarKimKoy=@CarKimKoy,CarKimVerYer=@CarKimVerYer,CarKimVerNed=@CarKimVerNed,
		CarKimTarih=@CarKimTarih,CarCiltNo=@CarCiltNo,CarSiraNo=@CarSiraNo,CarAileNo=@CarAileNo,CarUyruk=@CarUyruk,
		CarUyrukUlke=@CarUyrukUlke,CarIsyeriAd=@CarIsyeriAd,CarGorev=@CarGorev,CarSskNo=@CarSskNo,CarEmekliNo=@CarEmekliNo,
		CarEhliyetTip=@CarEhliyetTip,CarEhliyetNo=@CarEhliyetNo,CarEhliyetTarih=@CarEhliyetTarih,CarPasaportNo=@CarPasaportNo,
		CarMeslek=@CarMeslek,CarIlId=@CarIlId,CarIlceId=@CarIlceId,CarUlkeId=@CarUlkeId,CarResim1=@CarResim1,
		CarEftPsKt=@CarEftPsKt,CarEirTipi=@CarEirTipi,CarEiRPsKt=@CarEiRPsKt
		WHERE CarId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spCariKartSil] 
@CarId			decimal
AS
BEGIN
	BEGIN TRANSACTION
	DELETE Tb_CariKart WHERE CarId = @CarId 
	DELETE Tb_Adres WHERE AdrModul=1 and AdrKartId = @CarId 
	DELETE Tb_CariBank WHERE CrBCariId = @CarId
	
	DELETE Tb_Yetkili WHERE YtKTip =0 AND YtKKartId = @CarId 
	IF @@ERROR <> 0 
	BEGIN 
		ROLLBACK TRANSACTION 
		SELECT @@ERROR 
	END 
	ELSE
	BEGIN
		COMMIT TRANSACTION
		SELECT 0
	END
END
GO
CREATE PROCEDURE [dbo].[spCkSnDrChn]
@KartId			decimal
AS
DECLARE @Dur1 tinyint
DECLARE @Dur2 tinyint
DECLARE @Dur3 tinyint
DECLARE @Dur4 tinyint
DECLARE @Dur5 tinyint
DECLARE @Dur6 tinyint
DECLARE @Dur7 tinyint
DECLARE @Dur8 tinyint
DECLARE @Dur9 tinyint
DECLARE @Dur0 tinyint
DECLARE @Turu tinyint
DECLARE @Son tinyint = 10
DECLARE @Durumlar TABLE(
TbDurumTx VARCHAR(10),
TbDurum tinyint,
TbTur	tinyint
)
INSERT INTO @Durumlar VALUES ('PORTFOY',0,1)
INSERT INTO @Durumlar VALUES ('CIRO',1,1)
INSERT INTO @Durumlar VALUES ('PRIADE',2,1)
INSERT INTO @Durumlar VALUES ('MSIADE',3,1)
INSERT INTO @Durumlar VALUES ('BNTMCK',4,1)
INSERT INTO @Durumlar VALUES ('CRTMCK',5,1)
INSERT INTO @Durumlar VALUES ('BNTAHSIL',6,1)
INSERT INTO @Durumlar VALUES ('KSTAHSIL',7,1)
INSERT INTO @Durumlar VALUES ('CRTMAL',8,1)
INSERT INTO @Durumlar VALUES ('KARSLKS',9,1)
INSERT INTO @Durumlar VALUES ('PROTESTO',9,2)
INSERT INTO @Durumlar VALUES ('BNODENDI',10,1)
INSERT INTO @Durumlar VALUES ('KSODENDI',11,1)
INSERT INTO @Durumlar VALUES ('TMTAHSIL',12,1)
INSERT INTO @Durumlar VALUES ('BNTAKAS',13,1)

SELECT @Turu=CksTuru,@Dur0=CksDurum0,@Dur1=CksDurum1,@Dur2=CksDurum2,@Dur3=CksDurum3,@Dur4=CksDurum4,@Dur5=CksDurum5,@Dur6=CksDurum6,@Dur7=CksDurum7,@Dur8=CksDurum8,@Dur9=CksDurum9 FROM Tb_CkSnKart WHERE CksId = @KartId 
IF @Dur0 > 0 SET @Son=0
IF @Dur1 > 0 SET @Son=1
IF @Dur2 > 0 SET @Son=2 
IF @Dur3 > 0 SET @Son=3 
IF @Dur4 > 0 SET @Son=4 
IF @Dur5 > 0 SET @Son=5 
IF @Dur6 > 0 SET @Son=6
IF @Dur7 > 0 SET @Son=7
IF @Dur8 > 0 SET @Son=8
IF @Dur9 > 0 SET @Son=9

IF @Turu < 2 SET @Turu=1 ELSE SET @Turu=2

IF @Son = 0 UPDATE Tb_CkSnKart SET CksDurum=CksDurum0-1,CksDurum0=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum0-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 1 UPDATE Tb_CkSnKart SET CksDurum=CksDurum1-1,CksDurum1=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum1-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 2 UPDATE Tb_CkSnKart SET CksDurum=CksDurum2-1,CksDurum2=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum2-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 3 UPDATE Tb_CkSnKart SET CksDurum=CksDurum3-1,CksDurum3=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum3-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 4 UPDATE Tb_CkSnKart SET CksDurum=CksDurum4-1,CksDurum4=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum4-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 5 UPDATE Tb_CkSnKart SET CksDurum=CksDurum5-1,CksDurum5=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum5-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 6 UPDATE Tb_CkSnKart SET CksDurum=CksDurum6-1,CksDurum6=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum6-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 7 UPDATE Tb_CkSnKart SET CksDurum=CksDurum7-1,CksDurum7=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum7-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 8 UPDATE Tb_CkSnKart SET CksDurum=CksDurum8-1,CksDurum8=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum8-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 9 UPDATE Tb_CkSnKart SET CksDurum=CksDurum9-1,CksDurum9=0, CksDurumTx=(SELECT TbDurumTx FROM @Durumlar WHERE TbDurum=CksDurum9-1 AND TbTur=@Turu) WHERE CksId = @KartId 
IF @Son = 10 UPDATE Tb_CkSnKart SET CksDurum=0,CksDurumTx ='PORTFOY' WHERE CksId = @KartId 
GO
CREATE PROCEDURE [dbo].[spCkSnDrUpd]
@KartId			decimal,
@Durum			tinyint,
@DurumTx		nvarchar(10),
@EkId			decimal,
@CrTp			tinyint
AS
DECLARE @Dur1 tinyint
DECLARE @Dur2 tinyint
DECLARE @Dur3 tinyint
DECLARE @Dur4 tinyint
DECLARE @Dur5 tinyint
DECLARE @Dur6 tinyint
DECLARE @Dur7 tinyint
DECLARE @Dur8 tinyint
DECLARE @Dur9 tinyint
DECLARE @Dur0 tinyint

DECLARE @Son tinyint = 10
SELECT @Dur0=CksDurum0,@Dur1=CksDurum1,@Dur2=CksDurum2,@Dur3=CksDurum3,@Dur4=CksDurum4,@Dur5=CksDurum5,@Dur6=CksDurum6,@Dur7=CksDurum7,@Dur8=CksDurum8,@Dur9=CksDurum9 FROM Tb_CkSnKart 
IF @Dur0 > 0 SET @Son=0
IF @Dur1 > 0 SET @Son=1
IF @Dur2 > 0 SET @Son=2 
IF @Dur3 > 0 SET @Son=3 
IF @Dur4 > 0 SET @Son=4 
IF @Dur5 > 0 SET @Son=5 
IF @Dur6 > 0 SET @Son=6
IF @Dur7 > 0 SET @Son=7
IF @Dur8 > 0 SET @Son=8
IF @Dur9 > 0 SET @Son=9
IF @EkId > 0 BEGIN
	IF @Son = 10 UPDATE Tb_CkSnKart SET CksDurum0=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 0 UPDATE Tb_CkSnKart SET CksDurum1=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 1 UPDATE Tb_CkSnKart SET CksDurum2=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 2 UPDATE Tb_CkSnKart SET CksDurum3=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 3 UPDATE Tb_CkSnKart SET CksDurum4=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 4 UPDATE Tb_CkSnKart SET CksDurum5=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 5 UPDATE Tb_CkSnKart SET CksDurum6=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 6 UPDATE Tb_CkSnKart SET CksDurum7=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 7 UPDATE Tb_CkSnKart SET CksDurum8=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
	IF @Son = 8 UPDATE Tb_CkSnKart SET CksDurum9=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx,CksCiroId=@EkId,CksCiroTp=@CrTp WHERE CksId = @KartId 
END
ELSE
BEGIN
	IF @Son = 10 UPDATE Tb_CkSnKart SET CksDurum0=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 0 UPDATE Tb_CkSnKart SET CksDurum1=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 1 UPDATE Tb_CkSnKart SET CksDurum2=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 2 UPDATE Tb_CkSnKart SET CksDurum3=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 3 UPDATE Tb_CkSnKart SET CksDurum4=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 4 UPDATE Tb_CkSnKart SET CksDurum5=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 5 UPDATE Tb_CkSnKart SET CksDurum6=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 6 UPDATE Tb_CkSnKart SET CksDurum7=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 7 UPDATE Tb_CkSnKart SET CksDurum8=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
	IF @Son = 8 UPDATE Tb_CkSnKart SET CksDurum9=CksDurum+1, CksDurum=@Durum,CksDurumTx = @DurumTx WHERE CksId = @KartId 
END
GO
CREATE PROCEDURE [dbo].[spCkSnFisKaydet]
@Tur		tinyint,
@FisTur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@FisNo		nvarchar(20),
@MerkId		decimal,
@PersId		decimal,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_CkSnFis(
		CsFTur,CsFTarih,CsFSaat,CsFEvrakNo,CsFFisNo,CsFsMerkId,CsFPersId,CsFAciklama,CsFOzelKod1,CsFFisTuru,
		CsFOzelKod2,CsFOzelKod3,CsFKayKullanici,CsFMagazaKodu,CsFKayitTarihi,CsFKayitSaati
		) VALUES (
		@Tur,@Tarih,@Saat,@EvrakNo,@FisNo,@MerkId,@PersId,@Aciklama,@OzelKod1,@FisTur,
		@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_CkSnFis SET
		CsFTur=@Tur,CsFTarih=@Tarih,CsFSaat=@Saat,CsFEvrakNo=@EvrakNo,CsFFisNo=@FisNo,
		CsFsMerkId=@MerkId,CsFPersId=@PersId,CsFAciklama=@Aciklama,CsFFisTuru=@FisTur,
		CsFOzelKod1=@OzelKod1,CsFOzelKod2=@OzelKod2,CsFOzelKod3=@OzelKod3,CsFDuzKullanici=@Kullanici,
		CsFDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		CsFDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		CsFMagazaKodu=@MagazaKodu
		WHERE CsFId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spCkSnHarKaydet]
@FisId		decimal,
@Tur		tinyint,
@FisTur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@AnaId		decimal,
@Tipi		tinyint,
@KarsiHsId	decimal,
@Tutar		money,
@DovizTip	nvarchar(5),
@Doviz		nvarchar(4),
@DovizTutar	money,
@Kur		money,
@MsMerkId	decimal,
@PersId		decimal,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
IF @Yeni = 0
	BEGIN
	INSERT Tb_CkSnHareket(
		CsHFisId,CsHTur,CsHTarih,CsHSaat,CshEvrakNo,CsHEvrakId,CsHTipi,CsHKarsiHsId,CsHFisTuru,
		CsHTutar,CsHDovizTip,CsHDoviz,CsHDovizTutar,CsHKur,CsHMsMerkId,CsHPersId,CsHAciklama,CsHOzelKod1,CsHOzelKod2,
		CsHOzelKod3,CsHKayKullanici,CsHMagazaKodu,CsHKayitTarihi,CsHKayitSaati
		) VALUES (
		@FisId,@Tur,@Tarih,@Saat,@EvrakNo,@AnaId,@Tipi,@KarsiHsId,@FisTur,
		@Tutar,@DovizTip,@Doviz,@DovizTutar,@Kur,@MsMerkId,@PersId,@Aciklama,
		@OzelKod1,@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_CkSnHareket SET
		CsHFisId=@FisId,CsHTur=@Tur,CsHTarih=@Tarih,CsHSaat=@Saat,
		CsHEvrakNo=@EvrakNo,CsHEvrakId=@AnaId,CsHTipi=@Tipi,CsHFisTuru=@FisTur,
		CsHKarsiHsId=@KarsiHsId,CsHTutar=@Tutar,CsHDovizTip=@DovizTip,CsHDoviz=@Doviz,
		CsHDovizTutar=@DovizTutar,CsHKur=@Kur,CsHMsMerkId=@MsMerkId,CsHPersId=@PersId,
		CsHAciklama=@Aciklama,CsHOzelKod1=@OzelKod1,CsHOzelKod2=@OzelKod2,CsHOzelKod3=@OzelKod3,
		CsHDuzKullanici=@Kullanici,CsHMagazaKodu=@MagazaKodu,
		CsHDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		CsHDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE CsHId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spCkSnKartKaydet]
@CksPortfoyNo	nvarchar(30),
@CksTutar		money,
@CksDoviz		nvarchar(4),
@CksDovizTip	nvarchar(5),
@CksTanzimTarih	date,
@CksVadeTarih	date,
@CksYetkMahk	nvarchar(20),
@CksKesideYeri	nvarchar(20),
@CksDuzTipi		tinyint,
@CksDuzenId		decimal,
@CksKefilId		decimal,
@CksKefilAdSoy	nvarchar(40), 
@CksKefilTipi	tinyint,
@CksKefVrDa		nvarchar(20),
@CksKefVrNo		nvarchar(20),
@CksKefAdres	nvarchar(100),
@CksKefTCNo		nvarchar(20),
@CksBankaTip	tinyint,
@CksHesapNo		nvarchar(20),
@CksIbanNo		nvarchar(30),
@CksErOdeOran	money,
@CksGcOdeOran	money,
@CksDurum		tinyint,
@CksModul		tinyint,
@CksDurumTx		nvarchar(10),
@CksNo			nvarchar(30),
@CksCariId		decimal,
@CksCiroId		decimal,
@CksTuru		tinyint,
@CksDuzenleyen	nvarchar(40),
@CksPulAdet		tinyint,
@CksPulTutar	money,
@CksOzelKod1	nvarchar(20),
@CksOzelKod2	nvarchar(20),
@CksOzelKod3	nvarchar(20),
@CksOzelKod4	nvarchar(20),
@CksOzelKod5	nvarchar(20),
@CksAciklama	nvarchar(1000),
@CksUyari		nvarchar(200),
@CksKartTuru	tinyint,
@CksHesapId		decimal,
@CksSubeId		decimal,
@CksSubeAd		nvarchar(30),
@CksBankaId		decimal,
@CksKullanici	nvarchar(20),
@CksMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_CkSnKart(CksPortfoyNo,CksTutar,CksDoviz,CksDovizTip,CksTanzimTarih,CksVadeTarih,CksErOdeOran,CksGcOdeOran,
		CksDurum,CksNo,CksCariId,CksTuru,CksDuzenleyen,CksPulAdet,CksPulTutar,CksOzelKod1,CksOzelKod2,CksOzelKod3,
		CksOzelKod4,CksOzelKod5,CksAciklama,CksUyari,CksKartTuru,CksHesapId,CksSubeId,CksMagazaKodu,
		CksKayKullanici,CksYetkMahk,CksKesideYeri,CksDuzTipi,CksKefilAdSoy,CksKefilTipi,CksDurumTx,CksCiroId,
		CksKefVrDa,CksKefVrNo,CksKefAdres,CksKefTCNo,CksBankaTip,CksHesapNo,CksIbanNo,CksDuzenId,CksKefilId,
		CksModul,CksBankaId,CksSubeAd,CksKayitTarihi,CksKayitSaati
		) VALUES (
		@CksPortfoyNo,@CksTutar,@CksDoviz,@CksDovizTip,@CksTanzimTarih,@CksVadeTarih,@CksErOdeOran,@CksGcOdeOran,@CksDurum,
		@CksNo,@CksCariId,@CksTuru,@CksDuzenleyen,@CksPulAdet,@CksPulTutar,@CksOzelKod1,@CksOzelKod2,@CksOzelKod3,
		@CksOzelKod4,@CksOzelKod5,@CksAciklama,@CksUyari,@CksKartTuru,@CksHesapId,@CksSubeId,@CksMagazaKodu,
		@CksKullanici,@CksYetkMahk,@CksKesideYeri,@CksDuzTipi,@CksKefilAdSoy,@CksKefilTipi,@CksDurumTx,@CksCiroId,
		@CksKefVrDa,@CksKefVrNo,@CksKefAdres,@CksKefTCNo,@CksBankaTip,@CksHesapNo,@CksIbanNo,@CksDuzenId,
		@CksKefilId,@CksModul,@CksBankaId,@CksSubeAd,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_CkSnKart SET
		CksPortfoyNo=@CksPortfoyNo,CksTutar=@CksTutar,CksDoviz=@CksDoviz,CksDovizTip=@CksDovizTip,
		CksTanzimTarih=@CksTanzimTarih,CksVadeTarih=@CksVadeTarih,CksErOdeOran=@CksErOdeOran,CksGcOdeOran=@CksGcOdeOran,
		CksDurum=@CksDurum,CksNo=@CksNo,CksCariId=@CksCariId,CksTuru=@CksTuru,CksDuzenleyen=@CksDuzenleyen,
		CksPulAdet=@CksPulAdet,CksPulTutar=@CksPulTutar,CksOzelKod1=@CksOzelKod1,CksOzelKod2=@CksOzelKod2,
		CksOzelKod3=@CksOzelKod3,CksOzelKod4=@CksOzelKod4,CksOzelKod5=@CksOzelKod5,CksDurumTx=@CksDurumTx,
		CksAciklama=@CksAciklama,CksUyari=@CksUyari,CksKartTuru=@CksKartTuru,CksHesapId=@CksHesapId,
		CksSubeId=@CksSubeId,CksYetkMahk=@CksYetkMahk,CksKesideYeri=@CksKesideYeri,CksDuzTipi=@CksDuzTipi,
		CksKefilAdSoy=@CksKefilAdSoy,CksKefilTipi=@CksKefilTipi,CksKefVrDa=@CksKefVrDa,CksKefVrNo=@CksKefVrNo,
		CksKefAdres=@CksKefAdres,CksKefTCNo=@CksKefTCNo,CksBankaTip=@CksBankaTip,CksHesapNo=@CksHesapNo,
		CksIbanNo=@CksIbanNo,CksDuzKullanici=@CksKullanici,CksDuzenId=@CksDuzenId,CksKefilId=@CksKefilId,
		CksMagazaKodu=@CksMagazaKodu,CksCiroId=@CksCiroId,CksBankaId=@CksBankaId,CksSubeAd=@CksSubeAd,	
		CksDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		CksDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE CksId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spEkPosKartKaydet]
@EkpId			decimal,
@EkpAd			nvarchar(20),
@EkpHesapId		decimal,
@EkpGecTip		tinyint,
@EkpKomHesTip	tinyint,
@EkpIslemEkGun	tinyint,
@EkpTaksitEkGun	tinyint,
@EkpVadeGunP	tinyint,
@EkpTakSay		tinyint,
@EkpSabGun1		tinyint,
@EkpSabGun2		tinyint,
@EkpSabGun3		tinyint,
@EkpSabGun4		tinyint,
@EkpGun1		tinyint,
@EkpGun2		tinyint,
@EkpGun3		tinyint,
@EkpGun4		tinyint,
@EkpTatilT		tinyint,
@EkpTatilC		tinyint,
@EkpTatilP		tinyint,
@EkpSatisT		tinyint,
@EkpSatisC		tinyint,
@EkpSatisP		tinyint,
@EkpVadeT		tinyint,
@EkpVadeC		tinyint,
@EkpVadeP		tinyint,
@EkpTkOr01		money,
@EkpTkOr02		money,
@EkpTkOr03		money,
@EkpTkOr04		money,
@EkpTkOr05		money,
@EkpTkOr06		money,
@EkpTkOr07		money,
@EkpTkOr08		money,
@EkpTkOr09		money,
@EkpTkOr10		money,
@EkpTkOr11		money,
@EkpTkOr12		money,
@EkpTkOr13		money,
@EkpTkOr14		money,
@EkpTkOr15		money,
@EkpTkOr16		money,
@EkpTkOr17		money,
@EkpTkOr18		money,
@EkpTkOr19		money,
@EkpTkOr20		money,
@EkpTkOr21		money,
@EkpTkOr22		money,
@EkpTkOr23		money,
@EkpTkOr24		money,
@EkpVerUcr		money,
@EkpVerBas		date,
@EkpVerGun		smallint,
@EkpFormul1		nvarchar(30),
@EkpFormul2		nvarchar(30),
@EkpFormul3		nvarchar(30),
@EkpFormul4		nvarchar(30),
@EkpIlkFor1		nvarchar(30),
@EkpIlkFor2		nvarchar(30),
@EkpIlkFor3		nvarchar(30),
@EkpIlkFor4		nvarchar(30),
@EkpSabitPosUc	money,
@EkpKullanici	nvarchar(20),
@EkpMagazaKodu	nvarchar(50),
@Yeni			Decimal
AS
BEGIN
	if @Yeni = 0
	BEGIN
		INSERT Tb_EkPosKart(EkpId,EkpAd,EkpGecTip,EkpKomHesTip,EkpIslemEkGun,EkpTaksitEkGun,EkpVadeGunP,EkpTakSay,EkpGun1,
		EkpGun2,EkpGun3,EkpGun4,EkpTatilT,EkpTatilC,EkpTatilP,EkpSatisT,EkpSatisC,EkpSatisP,EkpVadeT,EkpVadeC,EkpVadeP,
		EkpTkOr01,EkpTkOr02,EkpTkOr03,EkpTkOr04,EkpTkOr05,EkpTkOr06,EkpTkOr07,EkpTkOr08,EkpTkOr09,EkpTkOr10,EkpTkOr11,
		EkpTkOr12,EkpTkOr13,EkpTkOr14,EkpTkOr15,EkpTkOr16,EkpTkOr17,EkpTkOr18,EkpTkOr19,EkpTkOr20,EkpTkOr21,EkpTkOr22,
		EkpTkOr23,EkpTkOr24,EkpMagazaKodu,EkpKayKullanici,EkpSabGun1,EkpSabGun2,EkpSabGun3,EkpSabGun4,EkpFormul1,
		EkpFormul2,EkpFormul3,EkpFormul4,EkpIlkFor1,EkpIlkFor2,EkpIlkFor3,EkpIlkFor4,EkpVerUcr,EkpVerBas,EkpVerGun,
		EkpHesapId,EkpSabitPosUc,EkpKayitTarihi,EkpKayitSaati
		) VALUES (@EkpId,@EkpAd,@EkpGecTip,@EkpKomHesTip,@EkpIslemEkGun,@EkpTaksitEkGun,@EkpVadeGunP,@EkpTakSay,@EkpGun1,
		@EkpGun2,@EkpGun3,@EkpGun4,@EkpTatilT,@EkpTatilC,@EkpTatilP,@EkpSatisT,@EkpSatisC,@EkpSatisP,@EkpVadeT,@EkpVadeC,@EkpVadeP,
		@EkpTkOr01,@EkpTkOr02,@EkpTkOr03,@EkpTkOr04,@EkpTkOr05,@EkpTkOr06,@EkpTkOr07,@EkpTkOr08,@EkpTkOr09,@EkpTkOr10,@EkpTkOr11,
		@EkpTkOr12,@EkpTkOr13,@EkpTkOr14,@EkpTkOr15,@EkpTkOr16,@EkpTkOr17,@EkpTkOr18,@EkpTkOr19,@EkpTkOr20,@EkpTkOr21,@EkpTkOr22,
		@EkpTkOr23,@EkpTkOr24,@EkpMagazaKodu,@EkpKullanici,@EkpSabGun1,@EkpSabGun2,@EkpSabGun3,@EkpSabGun4,@EkpFormul1,
		@EkpFormul2,@EkpFormul3,@EkpFormul4,@EkpIlkFor1,@EkpIlkFor2,@EkpIlkFor3,@EkpIlkFor4,@EkpVerUcr,@EkpVerBas,@EkpVerGun,
		@EkpHesapId,@EkpSabitPosUc,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
	END
	ELSE
	BEGIN
		UPDATE Tb_EkPosKart SET
		EkpAd=@EkpAd,EkpGecTip=@EkpGecTip,EkpKomHesTip=@EkpKomHesTip,EkpIslemEkGun=@EkpIslemEkGun,
		EkpTaksitEkGun=@EkpTaksitEkGun,EkpVadeGunP=@EkpVadeGunP,EkpTakSay=@EkpTakSay,EkpGun1=@EkpGun1,
		EkpGun2=@EkpGun2,EkpGun3=@EkpGun3,EkpGun4=@EkpGun4,EkpTatilT=@EkpTatilT,EkpTatilC=@EkpTatilC,
		EkpTatilP=@EkpTatilP,EkpSatisT=@EkpSatisT,EkpSatisC=@EkpSatisC,EkpSatisP=@EkpSatisP,EkpVadeT=@EkpVadeT,
		EkpVadeC=@EkpVadeC,EkpVadeP=@EkpVadeP,EkpTkOr01=@EkpTkOr01,EkpTkOr02=@EkpTkOr02,EkpTkOr03=@EkpTkOr03,
		EkpTkOr04=@EkpTkOr04,EkpTkOr05=@EkpTkOr05,EkpTkOr06=@EkpTkOr06,EkpTkOr07=@EkpTkOr07,EkpTkOr08=@EkpTkOr08,
		EkpTkOr09=@EkpTkOr09,EkpTkOr10=@EkpTkOr10,EkpTkOr11=@EkpTkOr11,EkpTkOr12=@EkpTkOr12,EkpTkOr13=@EkpTkOr13,
		EkpTkOr14=@EkpTkOr14,EkpTkOr15=@EkpTkOr15,EkpTkOr16=@EkpTkOr16,EkpTkOr17=@EkpTkOr17,EkpTkOr18=@EkpTkOr18,
		EkpTkOr19=@EkpTkOr19,EkpTkOr20=@EkpTkOr20,EkpTkOr21=@EkpTkOr21,EkpTkOr22=@EkpTkOr22,EkpTkOr23=@EkpTkOr23,
		EkpTkOr24=@EkpTkOr24,EkpMagazaKodu=@EkpMagazaKodu,EkpKayKullanici=@EkpKullanici,EkpSabGun1=@EkpSabGun1,
		EkpSabGun2=@EkpSabGun2,EkpSabGun3=@EkpSabGun3,EkpSabGun4=@EkpSabGun4,EkpFormul1=@EkpFormul1,
		EkpFormul2=@EkpFormul2,EkpFormul3=@EkpFormul3,EkpFormul4=@EkpFormul4,EkpIlkFor1=@EkpIlkFor1,
		EkpIlkFor2=@EkpIlkFor2,EkpIlkFor3=@EkpIlkFor3,EkpIlkFor4=@EkpIlkFor4,EkpVerUcr=@EkpVerUcr,
		EkpVerBas=@EkpVerBas,EkpVerGun=@EkpVerGun,EkpHesapId=@EkpHesapId,EkpSabitPosUc=@EkpSabitPosUc,
		EkpDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		EkpDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5) where EkpId=@EkpId 
	END
END
GO
CREATE PROCEDURE [dbo].[spFatKalemKaydet]
@FisId			decimal,
@Tarih			date,
@Saat			nvarchar(5),
@Tipi			tinyint,
@KdvTipi		tinyint,
@OtvTipi		tinyint,
@SatirTipi		tinyint,
@StokId			decimal,
@Birim			nvarchar(10),
@Miktar			money,
@Fiyat			money,
@Doviz			nvarchar(4),
@DovizTipi		nvarchar(5),
@DovizFiyat		money,
@Kur			money,
@Tutar			money,
@DepoId			decimal,
@PartiId		decimal,
@BirimMiktar	money,
@BirimFiyat		money,
@MalyFiyat		money,
@MalyTutar		money,
@KdvTutar		money,
@KdvMatrah		money,
@OtvTutar		money,
@OtvMatrah		money,
@SMalyTipi		tinyint,
@KdvOran		money,
@OtvOran		money,
@IskOrn1		money,
@IskOrn2		money,
@IskOrn3		money,
@IskOrn4		money,
@IskOrn5		money,
@IskTut1		money,
@IskTut2		money,
@IskTut3		money,
@IskTut4		money,
@IskTut5		money,
@Teslim			tinyint,
@Aciklama		nvarchar(200),
@Kaynak			tinyint,
@KaynakId		decimal,
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_FatKalem(
		FtKFisId,FtKTarih,FtKSaat,FtKStokId,FtKTipi,FtKKdvTipi,FtKOtvTipi,FtKBirim,FtKMiktar,FtKFiyat,FtKDoviz,
		FtKDovizTipi,FtKDovizFiyat,FtKKur,FtKDepoId,FtKPartiId,FtKBirimMiktar,FtKBirimFiyat,FtKMalyFiyat,FtKMalyTutar,
		FtKKdvOran,FtKOtvOran,FtKIskOrn1,FtKIskOrn2,FtKIskOrn3,FtKIskOrn4,FtKIskOrn5,FtKIskTut1,FtKIskTut2,FtKIskTut3,
		FtKIskTut4,FtKIskTut5,FtKTutar,FtKSatirTipi,FtKKaynak,FtKAciklama,FtKTeslim,FtKKaynakId,FtKOtvTutar,FtKKdvTutar,
		FtKKdvMatrah,FtKOtvMatrah      
		) VALUES (
		@FisId,@Tarih,@Saat,@StokId,@Tipi,@KdvTipi,@OtvTipi,@Birim,@Miktar,@Fiyat,@Doviz,@DovizTipi,@DovizFiyat,@Kur,
		@DepoId,@PartiId,@BirimMiktar,@BirimFiyat,@MalyFiyat,@MalyTutar,@KdvOran,@OtvOran,@IskOrn1,@IskOrn2,@IskOrn3,
		@IskOrn4,@IskOrn5,@IskTut1,@IskTut2,@IskTut3,@IskTut4,@IskTut5,@Tutar,@SatirTipi,@Kaynak,@Aciklama,@Teslim,
		@KaynakId,@OtvTutar,@KdvTutar,@KdvMatrah,@OtvMatrah)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_FatKalem SET
		FtKFisId=@FisId,FtKTarih=@Tarih,FtKSaat=@Saat,FtKStokId=@StokId,FtKTipi=@Tipi,FtKKdvTipi=@KdvTipi,
		FtKOtvTipi=@OtvTipi,FtKBirim=@Birim,FtKMiktar=@Miktar,FtKFiyat=@Fiyat,FtKDoviz=@Doviz,FtKDovizTipi=@DovizTipi,
		FtKDovizFiyat=@DovizFiyat,FtKKur=@Kur,FtKDepoId=@DepoId,FtKPartiId=@PartiId,FtKBirimMiktar=@BirimMiktar,
		FtKBirimFiyat=@BirimFiyat,FtKMalyFiyat=@MalyFiyat,FtKMalyTutar=@MalyTutar,FtKKdvOran=@KdvOran,
		FtKOtvOran=@OtvOran,FtKIskOrn1=@IskOrn1,FtKIskOrn2=@IskOrn2,FtKIskOrn3=@IskOrn3,FtKIskOrn4=@IskOrn4,
		FtKIskOrn5=@IskOrn5,FtKIskTut1=@IskTut1,FtKIskTut2=@IskTut2,FtKIskTut3=@IskTut3,FtKIskTut4=@IskTut4,
		FtKIskTut5=@IskTut5,FtKTutar=@Tutar,FtKSatirTipi=@SatirTipi,FtKKaynak=@Kaynak,FtKTeslim=@Teslim,
		FtKAciklama=@Aciklama,FtKOtvTutar=@OtvTutar,FtKKdvTutar=@KdvTutar,FtKKdvMatrah=@KdvMatrah,FtKOtvMatrah=@OtvMatrah 
		WHERE FtKId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spFaturaKaydet]
@Tur			tinyint,
@Tarih			date,
@Saat			nvarchar(5),
@Vade			date,
@No				nvarchar(20),
@CariId			decimal,
@DepoId			decimal,
@PersId			decimal,
@KdvTip			tinyint,
@MsMerkId		decimal,
@OtvTip			tinyint,
@Tip			tinyint,
@OzelKod1		nvarchar(20),
@OzelKod2		nvarchar(20),
@OzelKod3		nvarchar(20),
@Aciklama		nvarchar(500),
@AdresTip		tinyint,
@IskTutar1		money,
@IskTutar2		money,
@IskTutar3		money,
@IskTutar4		money,
@IskTutar5		money,
@IskOran1		money,
@IskOran2		money,
@IskOran3		money,
@IskOran4		money,
@IskOran5		money,
@IskDvTip1		nvarchar(5),
@IskDvTip2		nvarchar(5),
@IskDvTip3		nvarchar(5),
@IskDvTip4		nvarchar(5),
@IskDvTip5		nvarchar(5),
@IskDov1		nvarchar(5),
@IskDov2		nvarchar(5),
@IskDov3		nvarchar(5),
@IskDov4		nvarchar(5),
@IskDov5		nvarchar(5),
@IskDvTut1		money,
@IskDvTut2		money,
@IskDvTut3		money,
@IskDvTut4		money,
@IskDvTut5		money,
@IskKur1		money,
@IskKur2		money,
@IskKur3		money,
@IskKur4		money,
@IskKur5		money,
@KdvOran		money,
@MasTutar1		money,
@MasTutar2		money,
@MasTutar3		money,
@MasTutar4		money,
@MasTutar5		money,
@MasOran1		money,
@MasOran2		money,
@MasOran3		money,
@MasOran4		money,
@MasOran5		money,
@MasDvTip1		nvarchar(5),
@MasDvTip2		nvarchar(5),
@MasDvTip3		nvarchar(5),
@MasDvTip4		nvarchar(5),
@MasDvTip5		nvarchar(5),
@MasDov1		nvarchar(5),
@MasDov2		nvarchar(5),
@MasDov3		nvarchar(5),
@MasDov4		nvarchar(5),
@MasDov5		nvarchar(5),
@MasDvTut1		money,
@MasDvTut2		money,
@MasDvTut3		money,
@MasDvTut4		money,
@MasDvTut5		money,
@MasKur1		money,
@MasKur2		money,
@MasKur3		money,
@MasKur4		money,
@MasKur5		money,
@KdvAlIn1		money,
@KdvAlIn2		money,
@KdvAlEk1		money,
@KdvAlEk2		money,
@TevkOran		money,
@MalToplam		money,
@KalIsk			money,
@GenIsk			money,
@TopIsk			money,
@TopMas			money,
@AraTop			money,
@OtvTop			money,
@KdvMat			money,
@OtvMat			money,
@KdvTut			money,
@BrtTop			money,
@KdvAIn			money,
@KdvAEk			money,
@GenTop			money,
@VerTop			money,
@TevTut			money,
@OdnVer			money,
@Kaynak			tinyint,
@TesTarih		date,
@TesSaat1		nvarchar(5),
@TesSaat2		nvarchar(5),
@TesAlan		nvarchar(50),
@TesPersId		decimal,
@TesAdrTip		tinyint,
@TesYeri		tinyint,
@TesNot			nvarchar(100),
@Kullanici		nvarchar(20),
@MagazaKodu		nvarchar(20),
@FatEfteTipi	tinyint,
@FatEftTvNo		nvarchar(5),
@FatEftUrlAd	nvarchar(200),
@FatEftSisNo	nvarchar(20),
@FatEftTrcNo	integer,
@FatEftFatNo	nvarchar(20),
@FatEftCevTp	tinyint,
@FatEftReqId	integer,
@FatEftSenTp	tinyint,
@EkVerTut	    money,
@AdresId		decimal,
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_Fatura(
		FatTur,FatTarih,FatSaat,FatNo,FatCariId,FatPersId,FatKdvTip,FatMsMerkId,FatOtvTip,FatOzelKod1,FatOzelKod2,
		FatOzelKod3,FatAciklama,FatAdresTip,FatIskTutar1,FatIskTutar2,FatIskTutar3,FatIskTutar4,FatIskTutar5,
		FatIskOran1,FatIskOran2,FatIskOran3,FatIskOran4,FatIskOran5,FatIskDvTip1,FatIskDvTip2,FatIskDvTip3,
		FatIskDvTip4,FatIskDvTip5,FatIskDov1,FatIskDov2,FatIskDov3,FatIskDov4,FatIskDov5,FatIskDvTut1,
		FatIskDvTut2,FatIskDvTut3,FatIskDvTut4,FatIskDvTut5,FatIskKur1,FatIskKur2,FatIskKur3,FatIskKur4,FatIskKur5,
		FatMasTutar1,FatMasTutar2,FatMasTutar3,FatMasTutar4,FatMasTutar5,FatMasOran1,FatMasOran2,FatMasOran3,
		FatMasOran4,FatMasOran5,FatMasDvTip1,FatMasDvTip2,FatMasDvTip3,FatMasDvTip4,FatMasDvTip5,FatMasDov1,
		FatMasDov2,FatMasDov3,FatMasDov4,FatMasDov5,FatMasDvTut1,FatMasDvTut2,FatMasDvTut3,FatMasDvTut4,
		FatMasDvTut5,FatMasKur1,FatMasKur2,FatMasKur3,FatMasKur4,FatMasKur5,FatKdvAlIn1,FatKdvAlIn2,FatKdvAlEk1,
		FatKdvAlEk2,FatTevkOran,FatMalToplam,FatKalIsk,FatGenIsk,FatTopIsk,FatTopMas,FatAraTop,FatOtvTop,FatDepoId,	
		FatKdvMat,FatKdvTut,FatBrtTop,FatKdvAIn,FatKdvAEk,FatGenTop,FatVerTop,FatTevTut,FatOdnVer,FatKayKullanici,
		FatMagazaKodu,FatVade,FatTip,FatKaynak,FatTesTarih,FatTesSaat1,FatTesSaat2,FatTesAlan,FatTesPersId,FatTesAdrTip,
		FatTesYeri,FatTesNot,FatKdvOran,FatOtvMat,FatEfteTipi,FatEftTvNo,FatEftUrlAd,FatEftSisNo,FatEftTrcNo,FatEkVerTut,
		FatEftFatNo,FatEftCevTp,FatEftReqId,FatEftSenTp,FatAdresId,FatKayTarihi,FatKaySaati
		) VALUES (
		@Tur,@Tarih,@Saat,@No,@CariId,@PersId,@KdvTip,@MsMerkId,@OtvTip,@OzelKod1,@OzelKod2,@OzelKod3,@Aciklama,
		@AdresTip,@IskTutar1,@IskTutar2,@IskTutar3,@IskTutar4,@IskTutar5,@IskOran1,@IskOran2,@IskOran3,@IskOran4,
		@IskOran5,@IskDvTip1,@IskDvTip2,@IskDvTip3,@IskDvTip4,@IskDvTip5,@IskDov1,@IskDov2,@IskDov3,@IskDov4,@IskDov5,
		@IskDvTut1,@IskDvTut2,@IskDvTut3,@IskDvTut4,@IskDvTut5,@IskKur1,@IskKur2,@IskKur3,@IskKur4,@IskKur5,
		@MasTutar1,@MasTutar2,@MasTutar3,@MasTutar4,@MasTutar5,@MasOran1,@MasOran2,@MasOran3,@MasOran4,@MasOran5,
		@MasDvTip1,@MasDvTip2,@MasDvTip3,@MasDvTip4,@MasDvTip5,@MasDov1,@MasDov2,@MasDov3,@MasDov4,@MasDov5,
		@MasDvTut1,@MasDvTut2,@MasDvTut3,@MasDvTut4,@MasDvTut5,@MasKur1,@MasKur2,@MasKur3,@MasKur4,@MasKur5,@KdvAlIn1,
		@KdvAlIn2,@KdvAlEk1,@KdvAlEk2,@TevkOran,@MalToplam,@KalIsk,@GenIsk,@TopIsk,@TopMas,@AraTop,@OtvTop,@DepoId,@KdvMat,@KdvTut,@BrtTop,
		@KdvAIn,@KdvAEk,@GenTop,@VerTop,@TevTut,@OdnVer,@Kullanici,@MagazaKodu,@Vade,@Tip,@Kaynak,@TesTarih,@TesSaat1,@TesSaat2,
		@TesAlan,@TesPersId,@TesAdrTip,@TesYeri,@TesNot,@KdvOran,@OtvMat,@FatEfteTipi,@FatEftTvNo,@FatEftUrlAd,@FatEftSisNo,
		@FatEftTrcNo,@EkVerTut,@FatEftFatNo,@FatEftCevTp,@FatEftReqId,@FatEftSenTp,@AdresId,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_Fatura SET
		FatTur=@Tur,FatTarih=@Tarih,FatSaat=@Saat,FatNo=@No,FatCariId=@CariId,FatPersId=@PersId,
		FatKdvTip=@KdvTip,FatMsMerkId=@MsMerkId,FatOtvTip=@OtvTip,FatOzelKod1=@OzelKod1,FatOzelKod2=@OzelKod2,
		FatOzelKod3=@OzelKod3,FatAciklama=@Aciklama,FatAdresTip=@AdresTip,FatIskTutar1=@IskTutar1,
		FatIskTutar2=@IskTutar2,FatIskTutar3=@IskTutar3,FatIskTutar4=@IskTutar4,FatIskTutar5=@IskTutar5,
		FatIskOran1=@IskOran1,FatIskOran2=@IskOran2,FatIskOran3=@IskOran3,FatIskOran4=@IskOran4,
		FatIskOran5=@IskOran5,FatIskDvTip1=@IskDvTip1,FatIskDvTip2=@IskDvTip2,FatIskDvTip3=@IskDvTip3,
		FatIskDvTip4=@IskDvTip4,FatIskDvTip5=@IskDvTip5,FatIskDov1=@IskDov1,FatIskDov2=@IskDov2,
		FatIskDov3=@IskDov3,FatIskDov4=@IskDov4,FatIskDov5=@IskDov5,FatIskDvTut1=@IskDvTut1,
		FatIskDvTut2=@IskDvTut2,FatIskDvTut3=@IskDvTut3,FatIskDvTut4=@IskDvTut4,FatIskDvTut5=@IskDvTut5,
		FatIskKur1=@IskKur1,FatIskKur2=@IskKur2,FatIskKur3=@IskKur3,FatIskKur4=@IskKur4,FatEftReqId=@FatEftReqId,
		FatIskKur5=@IskKur5,FatMasTutar1=@MasTutar1,FatMasTutar2=@MasTutar2,FatMasTutar3=@MasTutar3,
		FatMasTutar4=@MasTutar4,FatMasTutar5=@MasTutar5,FatMasOran1=@MasOran1,FatMasOran2=@MasOran2,
		FatMasOran3=@MasOran3,FatMasOran4=@MasOran4,FatMasOran5=@MasOran5,FatMasDvTip1=@MasDvTip1,
		FatMasDvTip2=@MasDvTip2,FatMasDvTip3=@MasDvTip3,FatMasDvTip4=@MasDvTip4,FatMasDvTip5=@MasDvTip5,
		FatMasDov1=@MasDov1,FatMasDov2=@MasDov2,FatMasDov3=@MasDov3,FatMasDov4=@MasDov4,FatEftCevTp=@FatEftCevTp,
		FatMasDov5=@MasDov5,FatMasDvTut1=@MasDvTut1,FatMasDvTut2=@MasDvTut2,FatMasDvTut3=@MasDvTut3,
		FatMasDvTut4=@MasDvTut4,FatMasDvTut5=@MasDvTut5,FatMasKur1=@MasKur1,FatMasKur2=@MasKur2,
		FatMasKur3=@MasKur3,FatMasKur4=@MasKur4,FatMasKur5=@MasKur5,FatKdvAlIn1=@KdvAlIn1,FatEftSenTp=@FatEftSenTp,
		FatKdvAlIn2=@KdvAlIn2,FatKdvAlEk1=@KdvAlEk1,FatKdvAlEk2=@KdvAlEk2,FatTevkOran=@TevkOran,
		FatMalToplam=@MalToplam,FatKalIsk=@KalIsk,FatGenIsk=@GenIsk,FatOtvMat=@OtvMat,FatEftFatNo=@FatEftFatNo,
		FatTopIsk=@TopIsk,FatTopMas=@TopMas,FatAraTop=@AraTop,FatOtvTop=@OtvTop,FatKdvMat=@KdvMat,
		FatKdvTut=@KdvTut,FatBrtTop=@BrtTop,FatKdvAIn=@KdvAIn,FatKdvAEk=@KdvAEk,FatGenTop=@GenTop,
		FatVerTop=@VerTop,FatTevTut=@TevTut,FatOdnVer=@OdnVer,FatDuzKullanici=@Kullanici,FatAdresId=@AdresId,
		FatVade=@Vade,FatTip=@Tip,FatKaynak=@Kaynak,FatKdvOran=@KdvOran, FatDepoId=@DepoId,
		FatTesTarih=@TesTarih,FatTesSaat1=@TesSaat1,FatTesSaat2=@TesSaat2,FatTesAlan=@TesAlan,
		FatTesPersId=@TesPersId,FatTesAdrTip=@TesAdrTip,FatTesYeri=@TesYeri,FatTesNot=@TesNot,
		FatEfteTipi=@FatEfteTipi, FatDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		FatDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),FatEkVerTut=@EkVerTut,
		FatMagazaKodu=@MagazaKodu,FatEftTvNo=@FatEftTvNo,FatEftUrlAd=@FatEftUrlAd,FatEftSisNo=@FatEftSisNo,FatEftTrcNo=@FatEftTrcNo WHERE FatId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spFaturaSil]
@Deger			decimal,
@Type			tinyint,
@SMalyTipi		tinyint,
@Kapali			decimal
AS
BEGIN TRANSACTION
IF @Type = 0 DECLARE Deneme CURSOR FOR SELECT FtkStokId ,FtkBirimMiktar,FtkTipi,FtkMalyTutar,FtKKaynak,FtKKaynakId,FtKBirimMiktar*FtKBirimFiyat,FtKSatirTipi  FROM Tb_FatKalem where FtKFisId = @Deger 
ELSE DECLARE Deneme CURSOR FOR SELECT FtKStokId ,FtKBirimMiktar,FtKTipi,FtkMalyTutar,FtKKaynak,FtKKaynakId,FtKBirimMiktar*FtKBirimFiyat,FtKSatirTipi FROM Tb_FatKalem where FtKId = @Deger  

DECLARE @StokId DECIMAL
DECLARE @Miktar MONEY
DECLARE @Tutar MONEY
DECLARE @BaslikTip TINYINT
DECLARE @Kaynak TINYINT
DECLARE @KaynakId DECIMAL
DECLARE @BrTutar MONEY
DECLARE @SatirTipi TINYINT

OPEN Deneme
FETCH NEXT FROM Deneme INTO @StokId,@Miktar,@BaslikTip,@Tutar,@Kaynak,@KaynakId,@BrTutar,@SatirTipi
WHILE @@FETCH_STATUS=0
BEGIN
	IF @Kaynak = 1 UPDATE Tb_IrsKalem SET IrkFtMiktar = CASE WHEN IrKMiktar - @Miktar < 0 THEN 0 ELSE IrKFtMiktar - @Miktar END WHERE IrKId = @KaynakId
	IF @Kaynak = 2 
	BEGIN
		DECLARE @SatTeslim Tinyint
		SELECT @SatTeslim=COUNT(SKlId) FROM Tb_SatKalem WHERE SKlId=@KaynakId AND SKlTarih=SKlTesTar1 AND SKlTarih=SKlTesTar2
		IF @SatTeslim = 0 
		BEGIN
			--UPDATE Tb_StokKart SET StkStokCikan=StkStokCikan-@Miktar,StkBakiye=StkBakiye+@Miktar WHERE StkId=@StokId 
			UPDATE Tb_StokKart SET StkSiprCikan=StkSiprCikan+@Miktar,StkStokCikan=StkStokCikan-@Miktar,StkBakiye=StkBakiye+@Miktar WHERE StkId=@StokId 
			UPDATE Tb_SatKalem SET SKlTeslim = 1,SKlTeslimMiktar=SKlTeslimMiktar-@Miktar WHERE SKlId=@KaynakId AND SKlTeslimMiktar > 0 
		END
	END
	IF @Kaynak = 3 UPDATE Tb_SipKalem SET SpKTeslim = 1,SpKTeslimMiktar=SpKTeslimMiktar-@Miktar WHERE SpKId=@KaynakId AND SpKTeslimMiktar > 0   
	IF @Kaynak = 4 UPDATE Tb_TekKalem SET TkKFtIrMiktar=TkKFtIrMiktar-@Miktar WHERE TkKId=@KaynakId AND TkKFtIrMiktar > 0   	
	IF @Kaynak = 5 UPDATE Tb_IrsKalem SET IrkFtMiktar = CASE WHEN IrKMiktar - @Miktar < 0 THEN 0 ELSE IrKFtMiktar - @Miktar END WHERE IrKId = @KaynakId
	FETCH NEXT FROM Deneme INTO @StokId,@Miktar,@BaslikTip,@Tutar,@Kaynak,@KaynakId,@BrTutar,@SatirTipi
END
CLOSE Deneme
DEALLOCATE Deneme
IF @Type = 0 
BEGIN
DECLARE @CariId DECIMAL
DECLARE @GenTop MONEY
DECLARE @Tur TINYINT
DECLARE @Kayn TINYINT
DECLARE @CariHrId DECIMAL
DECLARE @KasaId DECIMAL
DECLARE @CariHrTp TINYINT
	
	SELECT @CariId = FatCariId,@GenTop=FatGenTop,@Tur=FatTur,@Kayn=FatKaynak FROM Tb_Fatura where FatId = @Deger 
	
	IF @Kapali = 0
	BEGIN
		DELETE Tb_FaturaTahsil WHERE FtOCariId=@CariId AND FtOFaturaId=@Deger 
		SELECT @CariHrId=CrHId,@CariHrTp=CrHTipi FROM Tb_CariHareket WHERE CrHEntgTipi=5 AND CrHEntgId = @Deger AND CrHCariId=@CariId
		UPDATE Tb_CariHareket SET CrHEntgTipi=0, CrHEntgId=0 WHERE CrHEntgTipi = 5 AND CrHEntgId = @Deger AND CrHCariId = @CariId 
		IF @CariHrTp > 0 UPDATE Tb_HesGecme SET HsGModul=1,HsgSatisId = @CariHrId WHERE HsGModul=2 AND HsGSatisId=@Deger
	END
	ELSE
	BEGIN
		SELECT @CariHrId=CrHId,@KasaId=CrHKarsiHsId,@CariHrTp=CrHTipi FROM Tb_CariHareket WHERE CrHEntgTipi=5 AND CrHEntgId = @Deger AND CrHCariId=@CariId
		IF @Kapali > 0 
		BEGIN
			IF @CariHrTp > 0 DELETE Tb_HesGecme WHERE HsGModul=2 AND HsGSatisId=@Deger
				
			DELETE Tb_CariFis WHERE CrFId=(SELECT CrHFisId FROM Tb_CariHareket WHERE CrHId=@CariHrId)
			DELETE Tb_CariHareket WHERE CrHId=@CariHrId 
				
		END		
	END
	
	IF @Kayn = 1 UPDATE Tb_Irsaliye SET IrsFaturaId=0 WHERE IrsFaturaId=@Deger
	DELETE FROM Tb_Fatura WHERE FatId=@Deger 
	DELETE FROM Tb_FatKalem WHERE FtKFisId = @Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 2 AND SrnBaslikId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 2 AND RnbBaslikId=@Deger
	DELETE FROM Tb_FaturaTahsil WHERE FtOFaturaId=@Deger
END
ELSE 
BEGIN
	DELETE FROM Tb_FatKalem where FtKId=@Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 2 AND SrnSatirId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 2 AND RnbSatirId=@Deger
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spFirmaKrKartKaydet]
@FkkKod			nvarchar(30),
@FkkAd			nvarchar(100),
@FkkKartNo		nvarchar(20),
@FkkKesTarih	date,
@FkkOdeTarih	date,
@FkkDurum		tinyint,
@FkkOzelKod1	nvarchar(20),
@FkkOzelKod2	nvarchar(20),
@FkkOzelKod3	nvarchar(20),
@FkkOzelKod4	nvarchar(20),
@FkkOzelKod5	nvarchar(20),
@FkkAnaGrup		nvarchar(5),
@FkkAciklama	nvarchar(1000),
@FkkUyari		nvarchar(200),
@FkkBankaId		decimal,
@FkkSorumId		decimal,
@FkkAltGrup		nvarchar(5),
@FkkAciklama1	nvarchar(50),
@FkkAciklama2	nvarchar(50),
@FkkAciklama3	nvarchar(50),
@FkkEkTutar1	money,
@FkkEkTutar2	money,
@FkkEkTutar3	money,
@FkkEkOran1		money,
@FkkEkOran2		money,
@FkkEkOran3		money,
@FkkKullanici	nvarchar(20),
@FkkMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_FirmaKrKart(
		FkkKod,FkkAd,FkkKartNo,FkkKesTarih,FkkOdeTarih,FkkOzelKod1,FkkOzelKod2,FkkOzelKod3,FkkOzelKod4,
		FkkDurum,FkkOzelKod5,FkkAnaGrup,FkkAciklama,FkkUyari,FkkBankaId,FkkSorumId,FkkAltGrup,
		FkkAciklama1,FkkAciklama2,FkkAciklama3,FkkEkTutar1,FkkEkTutar2,FkkEkTutar3,FkkEkOran1,
		FkkEkOran2,FkkEkOran3,FkkKayKullanici,FkkMagazaKodu,FkkKayitTarihi,FkkKayitSaati
		) VALUES (
		@FkkKod,@FkkAd,@FkkKartNo,@FkkKesTarih,@FkkOdeTarih,@FkkOzelKod1,@FkkOzelKod2,@FkkOzelKod3,@FkkOzelKod4,
		@FkkDurum,@FkkOzelKod5,@FkkAnaGrup,@FkkAciklama,@FkkUyari,@FkkBankaId,@FkkSorumId,@FkkAltGrup,
		@FkkAciklama1,@FkkAciklama2,@FkkAciklama3,@FkkEkTutar1,@FkkEkTutar2,
		@FkkEkTutar3,@FkkEkOran1,@FkkEkOran2,@FkkEkOran3,@FkkKullanici,@FkkMagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))	
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_FirmaKrKart SET
		FkkKod=@FkkKod,FkkAd=@FkkAd,FkkKartNo=@FkkKartNo,FkkKesTarih=@FkkKesTarih,FkkOdeTarih=@FkkOdeTarih,
		FkkOzelKod1=@FkkOzelKod1,FkkOzelKod2=@FkkOzelKod2,FkkOzelKod3=@FkkOzelKod3,FkkOzelKod4=@FkkOzelKod4,
		FkkOzelKod5=@FkkOzelKod5,FkkAnaGrup=@FkkAnaGrup,FkkAciklama=@FkkAciklama,FkkUyari=@FkkUyari,
		FkkBankaId=@FkkBankaId,	FkkSorumId=@FkkSorumId,FkkAltGrup=@FkkAltGrup,FkkAciklama1=@FkkAciklama1,
		FkkAciklama2=@FkkAciklama2,FkkAciklama3=@FkkAciklama3,FkkEkTutar1=@FkkEkTutar1,FkkEkTutar2=@FkkEkTutar2,
		FkkEkTutar3=@FkkEkTutar3,FkkEkOran1=@FkkEkOran1,FkkEkOran2=@FkkEkOran2,FkkEkOran3=@FkkEkOran3,
		FkkDuzKullanici=@FkkKullanici,FkkMagazaKodu=@FkkMagazaKodu,FkkDurum=@FkkDurum,
		FkkDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		FkkDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE FkkId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spHesapKartKaydet]
@HesKod			nvarchar(30),
@HesAd			nvarchar(100),
@HesHesapNo		nvarchar(20),
@HesIban		nvarchar(30),
@HesDoviz		nvarchar(4),
@HesDovizTip	nvarchar(5),
@HesMinBakiye	money,
@HesMaxBakiye	money,
@HesOzelKod1	nvarchar(20),
@HesOzelKod2	nvarchar(20),
@HesOzelKod3	nvarchar(20),
@HesOzelKod4	nvarchar(20),
@HesOzelKod5	nvarchar(20),
@HesAnaGrup		nvarchar(5),
@HesAciklama	nvarchar(1000),
@HesUyari		nvarchar(200),
@HesSubeId		decimal,
@HesSorumId		decimal,
@HesAltGrup		nvarchar(5),
@HesTanimlar	nvarchar(30),
@HesKartTipi	nvarchar(20),
@HesHavUcret	tinyint,
@HesEftUcret	tinyint,
@HesHavOrT		money,
@HesEftOrT		money,
@HesHavId		decimal,
@HesEftId		decimal,
@HesKarneNo		tinyint,
@HesKrNoOnTk	nvarchar(5),
@HesKrNoKdBy	tinyint,
@HesAciklama1	nvarchar(50),
@HesAciklama2	nvarchar(50),
@HesAciklama3	nvarchar(50),
@HesEkTutar1	money,
@HesEkTutar2	money,
@HesEkTutar3	money,
@HesEkOran1		money,
@HesEkOran2		money,
@HesEkOran3		money,
@HesGecTip		tinyint,
@HesKomHesTip	tinyint,
@HesIslemEkGun	tinyint,
@HesTaksitEkGun	tinyint,
@HesVadeGunP	tinyint,
@HesTakSay		tinyint,
@HesSabGun1		tinyint,
@HesSabGun2		tinyint,
@HesSabGun3		tinyint,
@HesSabGun4		tinyint,
@HesGun1		tinyint,
@HesGun2		tinyint,
@HesGun3		tinyint,
@HesGun4		tinyint,
@HesTatilT		tinyint,
@HesTatilC		tinyint,
@HesTatilP		tinyint,
@HesSatisT		tinyint,
@HesSatisC		tinyint,
@HesSatisP		tinyint,
@HesVadeT		tinyint,
@HesVadeC		tinyint,
@HesVadeP		tinyint,
@HesTkOr01		money,
@HesTkOr02		money,
@HesTkOr03		money,
@HesTkOr04		money,
@HesTkOr05		money,
@HesTkOr06		money,
@HesTkOr07		money,
@HesTkOr08		money,
@HesTkOr09		money,
@HesTkOr10		money,
@HesTkOr11		money,
@HesTkOr12		money,
@HesTkOr13		money,
@HesTkOr14		money,
@HesTkOr15		money,
@HesTkOr16		money,
@HesTkOr17		money,
@HesTkOr18		money,
@HesTkOr19		money,
@HesTkOr20		money,
@HesTkOr21		money,
@HesTkOr22		money,
@HesTkOr23		money,
@HesTkOr24		money,
@HesVerUcr		money,
@HesVerBas		date,
@HesVerGun		smallint,
@HesFormul1		nvarchar(30),
@HesFormul2		nvarchar(30),
@HesFormul3		nvarchar(30),
@HesFormul4		nvarchar(30),
@HesIlkFor1		nvarchar(30),
@HesIlkFor2		nvarchar(30),
@HesIlkFor3		nvarchar(30),
@HesIlkFor4		nvarchar(30),
@HesSabitPosUc	money,
@HesMxHavUcr	money,
@HesMnHavUcr	money,
@HesMxEftUcr	money,
@HesMnEftUcr	money,
@HesKullanici	nvarchar(20),
@HesMagazaKodu	nvarchar(50),
@HesPosAd		nvarchar(20),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
	if @Yeni = 0
	BEGIN
		INSERT Tb_HesapKart(HesKod,HesAd,HesHesapNo,HesIban,HesDoviz,HesDovizTip,HesMinBakiye,HesMaxBakiye,HesOzelKod1,
		HesOzelKod2,HesOzelKod3,HesOzelKod4,HesOzelKod5,HesAnaGrup,HesAciklama,HesUyari,HesSubeId,HesSorumId,HesAltGrup,
		HesTanimlar,HesKartTipi,HesHavUcret,HesEftUcret,HesHavOrT,HesEftOrT,HesHavId,HesKarneNo,HesKrNoOnTk,HesKrNoKdBy,
		HesEftId,HesAciklama1,HesAciklama2,HesAciklama3,HesEkTutar1,HesEkTutar2,HesEkTutar3,
		HesEkOran1,HesEkOran2,HesEkOran3,HesGecTip,HesKomHesTip,HesIslemEkGun,HesTaksitEkGun,HesVadeGunP,HesTakSay,HesGun1,
		HesGun2,HesGun3,HesGun4,HesTatilT,HesTatilC,HesTatilP,HesSatisT,HesSatisC,HesSatisP,HesVadeT,HesVadeC,HesVadeP,
		HesTkOr01,HesTkOr02,HesTkOr03,HesTkOr04,HesTkOr05,HesTkOr06,HesTkOr07,HesTkOr08,HesTkOr09,HesTkOr10,HesTkOr11,
		HesTkOr12,HesTkOr13,HesTkOr14,HesTkOr15,HesTkOr16,HesTkOr17,HesTkOr18,HesTkOr19,HesTkOr20,HesTkOr21,HesTkOr22,
		HesTkOr23,HesTkOr24,HesMagazaKodu,HesKayKullanici,HesSabitPosUc,HesMxHavUcr,HesMnHavUcr,HesMxEftUcr,
		HesMnEftUcr,HesSabGun1,HesSabGun2,HesSabGun3,HesSabGun4,HesFormul1,HesFormul2,HesFormul3,HesFormul4,
		HesIlkFor1,HesIlkFor2,HesIlkFor3,HesIlkFor4,HesVerUcr,HesVerBas,HesVerGun,HesPosAd,HesKayitTarihi,HesKayitSaati
		) VALUES (@HesKod,@HesAd,@HesHesapNo,@HesIban,@HesDoviz,@HesDovizTip,@HesMinBakiye,@HesMaxBakiye,@HesOzelKod1,
		@HesOzelKod2,@HesOzelKod3,@HesOzelKod4,@HesOzelKod5,@HesAnaGrup,@HesAciklama,@HesUyari,@HesSubeId,@HesSorumId,
		@HesAltGrup,@HesTanimlar,@HesKartTipi,@HesHavUcret,@HesEftUcret,@HesHavOrT,@HesEftOrT,
		@HesHavId,@HesKarneNo,@HesKrNoOnTk,@HesKrNoKdBy,@HesEftId,@HesAciklama1,@HesAciklama2,
		@HesAciklama3,@HesEkTutar1,@HesEkTutar2,@HesEkTutar3,@HesEkOran1,@HesEkOran2,@HesEkOran3,@HesGecTip,@HesKomHesTip,
		@HesIslemEkGun,@HesTaksitEkGun,@HesVadeGunP,@HesTakSay,@HesGun1,@HesGun2,@HesGun3,@HesGun4,@HesTatilT,@HesTatilC,
		@HesTatilP,@HesSatisT,@HesSatisC,@HesSatisP,@HesVadeT,@HesVadeC,@HesVadeP,@HesTkOr01,@HesTkOr02,@HesTkOr03,@HesTkOr04,
		@HesTkOr05,@HesTkOr06,@HesTkOr07,@HesTkOr08,@HesTkOr09,@HesTkOr10,@HesTkOr11,@HesTkOr12,@HesTkOr13,@HesTkOr14,
		@HesTkOr15,@HesTkOr16,@HesTkOr17,@HesTkOr18,@HesTkOr19,@HesTkOr20,@HesTkOr21,@HesTkOr22,@HesTkOr23,@HesTkOr24,
		@HesMagazaKodu,@HesKullanici,@HesSabitPosUc,@HesMxHavUcr,@HesMnHavUcr,@HesMxEftUcr,@HesMnEftUcr,@HesSabGun1,
		@HesSabGun2,@HesSabGun3,@HesSabGun4,@HesFormul1,@HesFormul2,@HesFormul3,@HesFormul4,@HesIlkFor1,@HesIlkFor2,
		@HesIlkFor3,@HesIlkFor4,@HesVerUcr,@HesVerBas,@HesVerGun,@HesPosAd,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_HesapKart SET
		HesKod=@HesKod,HesAd=@HesAd,HesHesapNo=@HesHesapNo,HesIban=@HesIban,HesDoviz=@HesDoviz,HesDovizTip=@HesDovizTip,
		HesMinBakiye=@HesMinBakiye,HesMaxBakiye=@HesMaxBakiye,HesOzelKod1=@HesOzelKod1,HesOzelKod2=@HesOzelKod2,
		HesOzelKod3=@HesOzelKod3,HesOzelKod4=@HesOzelKod4,HesOzelKod5=@HesOzelKod5,HesAnaGrup=@HesAnaGrup,
		HesAciklama=@HesAciklama,HesUyari=@HesUyari,HesSubeId=@HesSubeId,HesSorumId=@HesSorumId,HesAltGrup=@HesAltGrup,
		HesTanimlar=@HesTanimlar,HesKartTipi=@HesKartTipi,HesHavUcret=@HesHavUcret,HesEftUcret=@HesEftUcret,
		HesHavOrT=@HesHavOrT,HesEftOrT=@HesEftOrT,HesKarneNo=@HesKarneNo,HesKrNoOnTk=@HesKrNoOnTk,
		HesHavId=@HesHavId,HesEftId=@HesEftId,HesKrNoKdBy=@HesKrNoKdBy,HesPosAd=@HesPosAd,
		HesAciklama1=@HesAciklama1,HesAciklama2=@HesAciklama2,HesAciklama3=@HesAciklama3,
		HesEkTutar1=@HesEkTutar1,HesEkTutar2=@HesEkTutar2,HesEkTutar3=@HesEkTutar3,HesEkOran1=@HesEkOran1,HesEkOran2=@HesEkOran2,
		HesEkOran3=@HesEkOran3,HesGecTip=@HesGecTip,HesKomHesTip=@HesKomHesTip,HesIslemEkGun=@HesIslemEkGun,
		HesTaksitEkGun=@HesTaksitEkGun,HesVadeGunP=@HesVadeGunP,HesTakSay=@HesTakSay,HesGun1=@HesGun1,HesGun2=@HesGun2,
		HesGun3=@HesGun3,HesGun4=@HesGun4,HesTatilT=@HesTatilT,HesTatilC=@HesTatilC,HesTatilP=@HesTatilP,
		HesSatisT=@HesSatisT,HesSatisC=@HesSatisC,HesSatisP=@HesSatisP,HesVadeT=@HesVadeT,@HesVadeC=@HesVadeC,
		HesVadeP=@HesVadeP,HesTkOr01=@HesTkOr01,HesTkOr02=@HesTkOr02,HesTkOr03=@HesTkOr03,HesTkOr04=@HesTkOr04,
		HesTkOr05=@HesTkOr05,HesTkOr06=@HesTkOr06,HesTkOr07=@HesTkOr07,HesTkOr08=@HesTkOr08,
		HesTkOr09=@HesTkOr09,HesTkOr10=@HesTkOr10,HesTkOr11=@HesTkOr11,HesTkOr12=@HesTkOr12,HesTkOr13=@HesTkOr13,
		HesTkOr14=@HesTkOr14,HesTkOr15=@HesTkOr15,HesTkOr16=@HesTkOr16,HesTkOr17=@HesTkOr17,HesTkOr18=@HesTkOr18,
		HesTkOr19=@HesTkOr19,HesTkOr20=@HesTkOr20,HesTkOr21=@HesTkOr21,HesTkOr22=@HesTkOr22,HesTkOr23=@HesTkOr23,
		HesTkOr24=@HesTkOr24,HesMagazaKodu=@HesMagazaKodu,HesDuzKullanici=@HesKullanici,HesSabitPosUc=@HesSabitPosUc,
		HesMxHavUcr=@HesMxHavUcr,HesMnHavUcr=@HesMnHavUcr,HesMxEftUcr=@HesMxEftUcr,HesMnEftUcr=@HesMnEftUcr,
		HesSabGun1=@HesSabGun1,HesSabGun2=@HesSabGun2,HesSabGun3=@HesSabGun3,HesSabGun4=@HesSabGun4,
		HesFormul1=@HesFormul1,HesFormul2=@HesFormul2,HesFormul3=@HesFormul3,HesFormul4=@HesFormul4,
		HesIlkFor1=@HesIlkFor1,HesIlkFor2=@HesIlkFor2,HesIlkFor3=@HesIlkFor3,
		HesIlkFor4=@HesIlkFor4,HesVerUcr=@HesVerUcr,HesVerBas=@HesVerBas,HesVerGun=@HesVerGun,
		HesDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		HesDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5) where HesId=@Deger 
	END
END
GO
CREATE PROCEDURE [dbo].[spHizmetKartKaydet]
@HizKod				nvarchar(30),
@HizCins			nvarchar(100),
@HizKisaCins		nvarchar(50),
@HizAnaBirim		nvarchar(10),
@HizAnaDoviz		nvarchar(4),
@HizAnaDovTip		nvarchar(5),
@HizFiyat1			money,
@HizFiyat2			money,
@HizFiyat3			money,
@HizFiyat4			money,
@HizFiyat5			money,
@HizDoviz1			nvarchar(4),
@HizDoviz2			nvarchar(4),
@HizDoviz3			nvarchar(4),
@HizDoviz4			nvarchar(4),
@HizDoviz5			nvarchar(4),
@HizDovTip1			nvarchar(5),
@HizDovTip2			nvarchar(5),
@HizDovTip3			nvarchar(5),
@HizDovTip4			nvarchar(5),
@HizDovTip5			nvarchar(5),
@HizOzelKod1		nvarchar(20),
@HizOzelKod2		nvarchar(20),
@HizOzelKod3		nvarchar(20),
@HizOzelKod4		nvarchar(20),
@HizOzelKod5		nvarchar(20),
@HizAnaKdv			money,
@HizAnaIskonto		money,
@HizAnaGrup			nvarchar(5),
@HizBarkodTipi		tinyint,
@HizBarkod			nvarchar(50),
@HizAciklama		nvarchar(1000),
@HizUyari			nvarchar(200),
@HizToptanKdv		money,
@HizPerakKdv		money,
@HizTopAlisIsk		money,
@HizPerAlisIsk		money,
@HizTopSatisIsk		money,
@HizPerSatisIsk		money,
@HizOtvTipi			tinyint,
@HizOtvOranTutar	money,
@HizTevkifatOrani	money,
@HizTanimlar		nvarchar(50),
@HizUrunTipi		nvarchar(50),
@HizTopAlisFiyTip	tinyint,
@HizTopSatisFiyTip	tinyint,
@HizPerAlisFiyTip	tinyint,
@HizPerSatisFiyTip	tinyint,
@HizAltGrup			nvarchar(5),
@HizAciklama1		nvarchar(50),
@HizAciklama2		nvarchar(50),
@HizAciklama3		nvarchar(50),
@HizEkTutar1		money,
@HizEkTutar2		money,
@HizEkTutar3		money,
@HizEkOran1			money,
@HizEkOran2			money,
@HizEkOran3			money,
@HizKullanici		nvarchar(20),
@HizMagazaKodu		nvarchar(20),
@HizKdvId			decimal,
@HizPerKdvId		decimal,
@HizTopKdvId		decimal,
@HizTevkId			decimal,
@HizOtvTip			nvarchar(5),
@Deger				decimal,
@Yeni				decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_HizmetKart(
		HizKod,HizCins,HizKisaCins,HizAnaBirim,HizFiyat1,HizFiyat2,HizFiyat3,HizFiyat4,HizFiyat5,HizDoviz1,
		HizDoviz2,HizDoviz3,HizDoviz4,HizDoviz5,HizOzelKod1,HizOzelKod2,HizOzelKod3,HizOzelKod4,HizOzelKod5,
		HizDovTip1,HizDovTip2,HizDovTip3,HizDovTip4,HizDovTip5,HizAnaDovTip,
		HizAnaKdv,HizAnaIskonto,HizAnaGrup,HizBarkodTipi,HizBarkod,HizAciklama,HizUyari,HizToptanKdv,HizPerakKdv,
		HizTopAlisIsk,HizPerAlisIsk,HizTopSatisIsk,HizPerSatisIsk,HizOtvTipi,HizOtvOranTutar,HizTevkifatOrani,
		HizTanimlar,HizUrunTipi,HizTopAlisFiyTip,HizTopSatisFiyTip,HizPerAlisFiyTip,HizPerSatisFiyTip,
		HizAltGrup,HizAciklama1,HizAciklama2,HizAciklama3,HizEkTutar1,HizEkTutar2,HizEkTutar3,HizEkOran1,
		HizEkOran2,HizEkOran3,HizKayKullanici,HizMagazaKodu,HizKayitSaati,HizKayitTarihi,HizKdvId,HizTopKdvId,
		HizPerKdvId,HizTevkId,HizAnaDoviz,HizOtvTip     
		) VALUES (
		@HizKod,@HizCins,@HizKisaCins,@HizAnaBirim,@HizFiyat1,@HizFiyat2,@HizFiyat3,@HizFiyat4,@HizFiyat5,
		@HizDoviz1,@HizDoviz2,@HizDoviz3,@HizDoviz4,@HizDoviz5,@HizOzelKod1,@HizOzelKod2,@HizOzelKod3,@HizOzelKod4,
		@HizOzelKod5,@HizDovTip1,@HizDovTip2,@HizDovTip3,@HizDovTip4,@HizDovTip5,@HizAnaDovTip,
		@HizAnaKdv,@HizAnaIskonto,@HizAnaGrup,@HizBarkodTipi,@HizBarkod,@HizAciklama,@HizUyari,
		@HizToptanKdv,@HizPerakKdv,@HizTopAlisIsk,@HizPerAlisIsk,@HizTopSatisIsk,@HizPerSatisIsk,@HizOtvTipi,
		@HizOtvOranTutar,@HizTevkifatOrani,@HizTanimlar,@HizUrunTipi,@HizTopAlisFiyTip,@HizTopSatisFiyTip,@HizPerAlisFiyTip,
		@HizPerSatisFiyTip,@HizAltGrup,@HizAciklama1,@HizAciklama2,@HizAciklama3,@HizEkTutar1,@HizEkTutar2,@HizEkTutar3,
		@HizEkOran1,@HizEkOran2,@HizEkOran3,@HizKullanici,@HizMagazaKodu,substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),@HizKdvId,@HizTopKdvId,@HizPerKdvId,@HizTevkId,@HizAnaDoviz,@HizOtvTip
		)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_HizmetKart SET
		HizKod=@HizKod,HizCins=@HizCins,HizKisaCins=@HizKisaCins,HizAnaBirim=@HizAnaBirim,HizFiyat1=@HizFiyat1,
		HizFiyat2=@HizFiyat2,HizFiyat3=@HizFiyat3,HizFiyat4=@HizFiyat4,HizFiyat5=@HizFiyat5,HizDoviz1=@HizDoviz1,
		HizDoviz2=@HizDoviz2,HizDoviz3=@HizDoviz3,HizDoviz4=@HizDoviz4,HizDoviz5=@HizDoviz5,HizOzelKod1=@HizOzelKod1,
		HizOzelKod2=@HizOzelKod2,HizOzelKod3=@HizOzelKod3,HizOzelKod4=@HizOzelKod4,HizOzelKod5=@HizOzelKod5,
		HizDovTip1=@HizDovTip1,HizDovTip2=@HizDovTip2,HizDovTip3=@HizDovTip3,HizDovTip4=@HizDovTip4,HizDovTip5=@HizDovTip5,
		HizAnaDovTip=@HizAnaDovTip,HizAnaKdv=@HizAnaKdv,HizAnaIskonto=@HizAnaIskonto,HizAnaGrup=@HizAnaGrup,
		HizBarkodTipi=@HizBarkodTipi,HizBarkod=@HizBarkod,HizAciklama=@HizAciklama,HizUyari=@HizUyari,
		HizToptanKdv=@HizToptanKdv,HizPerakKdv=@HizPerakKdv,HizTopAlisIsk=@HizTopAlisIsk,HizPerAlisIsk=@HizPerAlisIsk,
		HizTopSatisIsk=@HizTopSatisIsk,HizPerSatisIsk=@HizPerSatisIsk,HizOtvTipi=@HizOtvTipi,HizOtvOranTutar=@HizOtvOranTutar,
		HizTevkifatOrani=@HizTevkifatOrani,HizTanimlar=@HizTanimlar,HizUrunTipi=@HizUrunTipi,HizTopAlisFiyTip=@HizTopAlisFiyTip,
		HizTopSatisFiyTip=@HizTopSatisFiyTip,HizPerAlisFiyTip=@HizPerAlisFiyTip,HizPerSatisFiyTip=@HizPerSatisFiyTip,
		HizAltGrup=@HizAltGrup,HizAciklama1=@HizAciklama1,HizAciklama2=@HizAciklama2,HizAciklama3=@HizAciklama3,
		HizEkTutar1=@HizEkTutar1,HizEkTutar2=@HizEkTutar2,HizEkTutar3=@HizEkTutar3,HizEkOran1=@HizEkOran1,HizEkOran2=@HizEkOran2,
		HizEkOran3=@HizEkOran3,HizDuzKullanici=@HizKullanici,HizOtvTip=@HizOtvTip,
		HizDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		HizDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		HizKdvId=@HizKdvId,HizTopKdvId=@HizTopKdvId,HizPerKdvId=@HizPerKdvId,HizTevkId=@HizTevkId,HizAnaDoviz=@HizAnaDoviz
		WHERE HizId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spIrsaliyeKaydet]
@Tur			tinyint,
@Tarih			date,
@Saat			nvarchar(5),
@No				nvarchar(20),
@CariId			decimal,
@PersId			decimal,
@DepoId			decimal,
@KdvTip			tinyint,
@MsMerkId		decimal,
@OtvTip			tinyint,
@OzelKod1		nvarchar(20),
@OzelKod2		nvarchar(20),
@OzelKod3		nvarchar(20),
@Aciklama		nvarchar(200),
@AdresTip		tinyint,
@IskTutar1		money,
@IskTutar2		money,
@IskTutar3		money,
@IskTutar4		money,
@IskTutar5		money,
@IskOran1		money,
@IskOran2		money,
@IskOran3		money,
@IskOran4		money,
@IskOran5		money,
@IskDvTip1		nvarchar(5),
@IskDvTip2		nvarchar(5),
@IskDvTip3		nvarchar(5),
@IskDvTip4		nvarchar(5),
@IskDvTip5		nvarchar(5),
@IskDov1		nvarchar(5),
@IskDov2		nvarchar(5),
@IskDov3		nvarchar(5),
@IskDov4		nvarchar(5),
@IskDov5		nvarchar(5),
@IskDvTut1		money,
@IskDvTut2		money,
@IskDvTut3		money,
@IskDvTut4		money,
@IskDvTut5		money,
@IskKur1		money,
@IskKur2		money,
@IskKur3		money,
@IskKur4		money,
@IskKur5		money,
@MasTutar1		money,
@MasTutar2		money,
@MasTutar3		money,
@MasTutar4		money,
@MasTutar5		money,
@MasOran1		money,
@MasOran2		money,
@MasOran3		money,
@MasOran4		money,
@MasOran5		money,
@MasDvTip1		nvarchar(5),
@MasDvTip2		nvarchar(5),
@MasDvTip3		nvarchar(5),
@MasDvTip4		nvarchar(5),
@MasDvTip5		nvarchar(5),
@MasDov1		nvarchar(5),
@MasDov2		nvarchar(5),
@MasDov3		nvarchar(5),
@MasDov4		nvarchar(5),
@MasDov5		nvarchar(5),
@MasDvTut1		money,
@MasDvTut2		money,
@MasDvTut3		money,
@MasDvTut4		money,
@MasDvTut5		money,
@MasKur1		money,
@MasKur2		money,
@MasKur3		money,
@MasKur4		money,
@MasKur5		money,
@KdvAlIn1		money,
@KdvAlIn2		money,
@KdvAlEk1		money,
@KdvAlEk2		money,
@TevkOran		money,
@KdvOran		money,
@MalToplam		money,
@KalIsk			money,
@GenIsk			money,
@TopIsk			money,
@TopMas			money,
@AraTop			money,
@OtvTop			money,
@KdvMat			money,
@KdvTut			money,
@BrtTop			money,
@KdvAIn			money,
@KdvAEk			money,
@GenTop			money,
@VerTop			money,
@TevTut			money,
@OdnVer			money,
@Kaynak			tinyint,
@TesTarih		date,
@TesSaat1		nvarchar(5),
@TesSaat2		nvarchar(5),
@TesAlan		nvarchar(50),
@TesPersId		decimal,
@TesAdrTip		tinyint,
@TesYeri		tinyint,
@EkVerTut		money,
@AdresId		decimal,
@IrseIrTipi		tinyint,
@TesNot			nvarchar(100),
@Kullanici		nvarchar(20),
@MagazaKodu		nvarchar(20),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_Irsaliye(
		IrsTur,IrsTarih,IrsSaat,IrsNo,IrsCariId,IrsPersId,IrsKdvTip,IrsMsMerkId,IrsOtvTip,IrsOzelKod1,IrsOzelKod2,
		IrsOzelKod3,IrsAciklama,IrsAdresTip,IrsIskTutar1,IrsIskTutar2,IrsIskTutar3,IrsIskTutar4,IrsIskTutar5,
		IrsIskOran1,IrsIskOran2,IrsIskOran3,IrsIskOran4,IrsIskOran5,IrsIskDvTip1,IrsIskDvTip2,IrsIskDvTip3,
		IrsIskDvTip4,IrsIskDvTip5,IrsIskDov1,IrsIskDov2,IrsIskDov3,IrsIskDov4,IrsIskDov5,IrsIskDvTut1,
		IrsIskDvTut2,IrsIskDvTut3,IrsIskDvTut4,IrsIskDvTut5,IrsIskKur1,IrsIskKur2,IrsIskKur3,IrsIskKur4,IrsIskKur5,
		IrsMasTutar1,IrsMasTutar2,IrsMasTutar3,IrsMasTutar4,IrsMasTutar5,IrsMasOran1,IrsMasOran2,IrsMasOran3,
		IrsMasOran4,IrsMasOran5,IrsMasDvTip1,IrsMasDvTip2,IrsMasDvTip3,IrsMasDvTip4,IrsMasDvTip5,IrsMasDov1,
		IrsMasDov2,IrsMasDov3,IrsMasDov4,IrsMasDov5,IrsMasDvTut1,IrsMasDvTut2,IrsMasDvTut3,IrsMasDvTut4,
		IrsMasDvTut5,IrsMasKur1,IrsMasKur2,IrsMasKur3,IrsMasKur4,IrsMasKur5,IrsKdvAlIn1,IrsKdvAlIn2,IrsKdvAlEk1,
		IrsKdvAlEk2,IrsTevkOran,IrsKdvOran,IrsMalToplam,IrsKalIsk,IrsGenIsk,IrsTopIsk,IrsTopMas,IrsAraTop,IrsOtvTop,	
		IrsKdvMat,IrsKdvTut,IrsBrtTop,IrsKdvAIn,IrsKdvAEk,IrsGenTop,IrsVerTop,IrsTevTut,IrsOdnVer,IrsKayKullanici,
		IrsMagazaKodu,IrsKaynak,IrsTesTarih,IrsTesSaat1,IrsTesSaat2,IrsTesAlan,IrsTesPersId,IrsTesAdrTip,IrsTesYeri,
		IrseIrTipi,IrsTesNot,IrsDepoId,IrsEkVerTut,IrsAdresId,IrsKayTarihi,IrsKaySaati
		) VALUES (
		@Tur,@Tarih,@Saat,@No,@CariId,@PersId,@KdvTip,@MsMerkId,@OtvTip,@OzelKod1,@OzelKod2,@OzelKod3,@Aciklama,
		@AdresTip,@IskTutar1,@IskTutar2,@IskTutar3,@IskTutar4,@IskTutar5,@IskOran1,@IskOran2,@IskOran3,@IskOran4,
		@IskOran5,@IskDvTip1,@IskDvTip2,@IskDvTip3,@IskDvTip4,@IskDvTip5,@IskDov1,@IskDov2,@IskDov3,@IskDov4,@IskDov5,
		@IskDvTut1,@IskDvTut2,@IskDvTut3,@IskDvTut4,@IskDvTut5,@IskKur1,@IskKur2,@IskKur3,@IskKur4,@IskKur5,
		@MasTutar1,@MasTutar2,@MasTutar3,@MasTutar4,@MasTutar5,@MasOran1,@MasOran2,@MasOran3,@MasOran4,@MasOran5,
		@MasDvTip1,@MasDvTip2,@MasDvTip3,@MasDvTip4,@MasDvTip5,@MasDov1,@MasDov2,@MasDov3,@MasDov4,@MasDov5,
		@MasDvTut1,@MasDvTut2,@MasDvTut3,@MasDvTut4,@MasDvTut5,@MasKur1,@MasKur2,@MasKur3,@MasKur4,@MasKur5,@KdvAlIn1,
		@KdvAlIn2,@KdvAlEk1,@KdvAlEk2,@TevkOran,@KdvOran,@MalToplam,@KalIsk,@GenIsk,@TopIsk,@TopMas,@AraTop,@OtvTop,
		@KdvMat,@KdvTut,@BrtTop,@KdvAIn,@KdvAEk,@GenTop,@VerTop,@TevTut,@OdnVer,@Kullanici,@MagazaKodu,@Kaynak,
		@TesTarih,@TesSaat1,@TesSaat2,@TesAlan,@TesPersId,@TesAdrTip,@TesYeri,@TesNot,@IrseIrTipi,@DepoId,@EkVerTut,@AdresId,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_Irsaliye SET
		IrsTur=@Tur,IrsTarih=@Tarih,IrsSaat=@Saat,IrsNo=@No,IrsCariId=@CariId,IrsPersId=@PersId,
		IrsKdvTip=@KdvTip,IrsMsMerkId=@MsMerkId,IrsOtvTip=@OtvTip,IrsOzelKod1=@OzelKod1,IrsOzelKod2=@OzelKod2,
		IrsOzelKod3=@OzelKod3,IrsAciklama=@Aciklama,IrsAdresTip=@AdresTip,IrsIskTutar1=@IskTutar1,
		IrsIskTutar2=@IskTutar2,IrsIskTutar3=@IskTutar3,IrsIskTutar4=@IskTutar4,IrsIskTutar5=@IskTutar5,
		IrsIskOran1=@IskOran1,IrsIskOran2=@IskOran2,IrsIskOran3=@IskOran3,IrsIskOran4=@IskOran4,
		IrsIskOran5=@IskOran5,IrsIskDvTip1=@IskDvTip1,IrsIskDvTip2=@IskDvTip2,IrsIskDvTip3=@IskDvTip3,
		IrsIskDvTip4=@IskDvTip4,IrsIskDvTip5=@IskDvTip5,IrsIskDov1=@IskDov1,IrsIskDov2=@IskDov2,
		IrsIskDov3=@IskDov3,IrsIskDov4=@IskDov4,IrsIskDov5=@IskDov5,IrsIskDvTut1=@IskDvTut1,
		IrsIskDvTut2=@IskDvTut2,IrsIskDvTut3=@IskDvTut3,IrsIskDvTut4=@IskDvTut4,IrsIskDvTut5=@IskDvTut5,
		IrsIskKur1=@IskKur1,IrsIskKur2=@IskKur2,IrsIskKur3=@IskKur3,IrsIskKur4=@IskKur4,
		IrsIskKur5=@IskKur5,IrsMasTutar1=@MasTutar1,IrsMasTutar2=@MasTutar2,IrsMasTutar3=@MasTutar3,
		IrsMasTutar4=@MasTutar4,IrsMasTutar5=@MasTutar5,IrsMasOran1=@MasOran1,IrsMasOran2=@MasOran2,
		IrsMasOran3=@MasOran3,IrsMasOran4=@MasOran4,IrsMasOran5=@MasOran5,IrsMasDvTip1=@MasDvTip1,
		IrsMasDvTip2=@MasDvTip2,IrsMasDvTip3=@MasDvTip3,IrsMasDvTip4=@MasDvTip4,IrsMasDvTip5=@MasDvTip5,
		IrsMasDov1=@MasDov1,IrsMasDov2=@MasDov2,IrsMasDov3=@MasDov3,IrsMasDov4=@MasDov4,
		IrsMasDov5=@MasDov5,IrsMasDvTut1=@MasDvTut1,IrsMasDvTut2=@MasDvTut2,IrsMasDvTut3=@MasDvTut3,
		IrsMasDvTut4=@MasDvTut4,IrsMasDvTut5=@MasDvTut5,IrsMasKur1=@MasKur1,IrsMasKur2=@MasKur2,
		IrsMasKur3=@MasKur3,IrsMasKur4=@MasKur4,IrsMasKur5=@MasKur5,IrsKdvAlIn1=@KdvAlIn1,IrsAdresId=@AdresId,
		IrsKdvAlIn2=@KdvAlIn2,IrsKdvAlEk1=@KdvAlEk1,IrsKdvAlEk2=@KdvAlEk2,IrsTevkOran=@TevkOran,
		IrsKdvOran=@KdvOran,IrsMalToplam=@MalToplam,IrsKalIsk=@KalIsk,IrsGenIsk=@GenIsk,IrsDepoId=@DepoId,
		IrsTopIsk=@TopIsk,IrsTopMas=@TopMas,IrsAraTop=@AraTop,IrsOtvTop=@OtvTop,IrsKdvMat=@KdvMat,
		IrsKdvTut=@KdvTut,IrsBrtTop=@BrtTop,IrsKdvAIn=@KdvAIn,IrsKdvAEk=@KdvAEk,IrsGenTop=@GenTop,
		IrsVerTop=@VerTop,IrsTevTut=@TevTut,IrsOdnVer=@OdnVer,IrsDuzKullanici=@Kullanici,IrsKaynak=@Kaynak,
		IrsTesTarih=@TesTarih,IrsTesSaat1=@TesSaat1,IrsTesSaat2=@TesSaat2,IrsTesAlan=@TesAlan,
		IrsTesPersId=@TesPersId,IrsTesAdrTip=@TesAdrTip,IrsTesYeri=@TesYeri,IrsTesNot=@TesNot,
		IrsDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),IrsEkVerTut=@EkVerTut,
		IrsDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		IrsMagazaKodu=@MagazaKodu,IrseIrTipi=@IrseIrTipi WHERE IrsId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spIrsaliyeSil]
@Deger			decimal,
@Type			tinyint,
@SMalyTipi		tinyint
AS
BEGIN TRANSACTION
IF @Type = 0 DECLARE Deneme CURSOR FOR SELECT IrkStokId ,IrkBirimMiktar,IrKKaynak,IrkKaynakId  FROM Tb_IrsKalem where IrKFisId = @Deger 
ELSE DECLARE Deneme CURSOR FOR SELECT IrKStokId ,IrKBirimMiktar,IrKKaynak,IrkKaynakId FROM Tb_IrsKalem where IrKId = @Deger  

DECLARE @StokId DECIMAL
DECLARE @Miktar MONEY
DECLARE @Kaynak TINYINT
DECLARE @KaynakId DECIMAL

OPEN Deneme
FETCH NEXT FROM Deneme INTO @StokId,@Miktar,@Kaynak,@KaynakId
WHILE @@FETCH_STATUS=0
BEGIN
	IF @Kaynak = 2 
	BEGIN
		DECLARE @SatTeslim Tinyint
		SELECT @SatTeslim=COUNT(SKlId) FROM Tb_SatKalem WHERE SKlId=@KaynakId AND SKlTarih=SKlTesTar1 AND SKlTarih=SKlTesTar2
		IF @SatTeslim = 0 
		BEGIN
			UPDATE Tb_SatKalem SET SKlTeslim = 1,SKlTeslimMiktar=SKlTeslimMiktar-@Miktar WHERE SKlId=@KaynakId AND SKlTeslimMiktar > 0 
		END
	END
	IF @Kaynak = 3 UPDATE Tb_SipKalem SET SpKTeslim = 1,SpKTeslimMiktar=SpKTeslimMiktar-@Miktar WHERE SpKId=@KaynakId AND SpKTeslimMiktar > 0 
	IF @Kaynak = 4 UPDATE Tb_TekKalem SET TkKFtIrMiktar=TkKFtIrMiktar-@Miktar WHERE TkKId=@KaynakId AND TkKFtIrMiktar > 0   	
	FETCH NEXT FROM Deneme INTO @StokId,@Miktar,@Kaynak,@KaynakId
END
CLOSE Deneme
DEALLOCATE Deneme
IF @Type = 0 
BEGIN
	DELETE FROM Tb_Irsaliye WHERE IrsId=@Deger 
	DELETE FROM Tb_IrsKalem WHERE IrKFisId = @Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 1 AND SrnBaslikId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 1 AND RnbBaslikId=@Deger
	DELETE FROM Tb_eft_eIrsaliye WHERE EiRIrsId = @Deger
END
ELSE 
BEGIN
	DELETE FROM Tb_IrsKalem where IrKId=@Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 1 AND SrnSatirId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 1 AND RnbSatirId=@Deger
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spIrsKalemKaydet]
@FisId			decimal,
@Tarih			date,
@Saat			nvarchar(5),
@StokId			decimal,
@Tipi			tinyint,
@KdvTipi		tinyint,
@OtvTipi		tinyint,
@Birim			nvarchar(10),
@Miktar			money,
@Fiyat			money,
@Doviz			nvarchar(4),
@DovizTipi		nvarchar(5),
@DovizFiyat		money,
@Kur			money,
@Tutar			money,
@DepoId			decimal,
@PartiId		decimal,
@BirimMiktar	money,
@BirimFiyat		money,
@MalyFiyat		money,
@MalyTutar		money,
@OtvTutar		money,
@SMalyTipi		tinyint,
@KdvOran		money,
@OtvOran		money,
@IskOrn1		money,
@IskOrn2		money,
@IskOrn3		money,
@IskOrn4		money,
@IskOrn5		money,
@IskTut1		money,
@IskTut2		money,
@IskTut3		money,
@IskTut4		money,
@IskTut5		money,
@Aciklama		nvarchar(200),
@Kaynak			tinyint,
@IrKRedMiktar	money,
@IrKFazMiktar	money,
@IrKEksMiktar	money,
@IrKRedSebep	nvarchar(100),
@KaynakId		decimal,
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_IrsKalem(
		IrKFisId,IrkTarih,IrkSaat,IrkStokId,IrkTipi,IrkKdvTipi,IrkOtvTipi,IrkBirim,IrkMiktar,IrkFiyat,IrkDoviz,
		IrkDovizTipi,IrkDovizFiyat,IrkKur,IrkDepoId,IrkPartiId,IrkBirimMiktar,IrkBirimFiyat,IrkMalyFiyat,IrkMalyTutar,
		IrkKdvOran,IrkOtvOran,IrkIskOrn1,IrkIskOrn2,IrkIskOrn3,IrkIskOrn4,IrkIskOrn5,IrkIskTut1,IrkIskTut2,IrkIskTut3,
		IrkIskTut4,IrkIskTut5,IrkTutar,IrKKaynak,IrKAciklama,IrkKaynakId,IrKOtvTutar,IrKRedMiktar,IrKFazMiktar,IrKEksMiktar,IrKRedSebep 
		) VALUES (
		@FisId,@Tarih,@Saat,@StokId,@Tipi,@KdvTipi,@OtvTipi,@Birim,@Miktar,@Fiyat,@Doviz,@DovizTipi,@DovizFiyat,@Kur,
		@DepoId,@PartiId,@BirimMiktar,@BirimFiyat,@MalyFiyat,@MalyTutar,@KdvOran,@OtvOran,@IskOrn1,@IskOrn2,@IskOrn3,
		@IskOrn4,@IskOrn5,@IskTut1,@IskTut2,@IskTut3,@IskTut4,@IskTut5,@Tutar,@Kaynak,@Aciklama,@KaynakId,@OtvTutar,
		@IrKRedMiktar,@IrKFazMiktar,@IrKEksMiktar,@IrKRedSebep)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_IrsKalem SET
		IrKFisId=@FisId,IrkTarih=@Tarih,IrkSaat=@Saat,IrkStokId=@StokId,IrkTipi=@Tipi,IrkKdvTipi=@KdvTipi,
		IrkOtvTipi=@OtvTipi,IrkBirim=@Birim,IrkMiktar=@Miktar,IrkFiyat=@Fiyat,IrkDoviz=@Doviz,IrkDovizTipi=@DovizTipi,
		IrkDovizFiyat=@DovizFiyat,IrkKur=@Kur,IrkDepoId=@DepoId,IrkPartiId=@PartiId,IrkBirimMiktar=@BirimMiktar,
		IrkBirimFiyat=@BirimFiyat,IrkMalyFiyat=@MalyFiyat,IrkMalyTutar=@MalyTutar,IrkKdvOran=@KdvOran,
		IrkOtvOran=@OtvOran,IrkIskOrn1=@IskOrn1,IrkIskOrn2=@IskOrn2,IrkIskOrn3=@IskOrn3,IrkIskOrn4=@IskOrn4,
		IrkIskOrn5=@IskOrn5,IrkIskTut1=@IskTut1,IrkIskTut2=@IskTut2,IrkIskTut3=@IskTut3,IrkIskTut4=@IskTut4,
		IrkIskTut5=@IskTut5,IrkTutar=@Tutar,IrKKaynak=@Kaynak,IrKAciklama=@Aciklama,IrKOtvTutar=@OtvTutar WHERE IrKId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spKasaFisKaydet]
@Tur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@FisNo		nvarchar(20),
@AnaId		decimal,
@MerkId		decimal,
@PersId		decimal,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_KasaFis(
		KsFTur,KsFTarih,KsFSaat,KsFEvrakNo,KsFFisNo,KsFKasaId,KsFsMerkId,KsFPersId,KsFAciklama,KsFOzelKod1,
		KsFOzelKod2,KsFOzelKod3,KsFKayKullanici,KsFMagazaKodu,KsFKayitTarihi,KsFKayitSaati
		) VALUES (
		@Tur,@Tarih,@Saat,@EvrakNo,@FisNo,@AnaId,@MerkId,@PersId,@Aciklama,@OzelKod1,
		@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_KasaFis SET
		KsFTur=@Tur,KsFTarih=@Tarih,KsFSaat=@Saat,KsFEvrakNo=@EvrakNo,KsFFisNo=@FisNo,
		KsFKasaId=@AnaId,KsFsMerkId=@MerkId,KsFPersId=@PersId,KsFAciklama=@Aciklama,
		KsFOzelKod1=@OzelKod1,KsFOzelKod2=@OzelKod2,KsFOzelKod3=@OzelKod3,KsFDuzKullanici=@Kullanici,
		KsFDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		KsFDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		KsFMagazaKodu=@MagazaKodu
		WHERE KsFId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spKasaHarKaydet]
@FisId		decimal,
@Tur		tinyint,
@Tarih		date,
@Saat		nvarchar(5),
@EvrakNo	nvarchar(20),
@AnaId		decimal,
@Tipi		tinyint,
@KarsiHsId	decimal,
@Tutar		money,
@Faiz		money,
@DovizTip	nvarchar(5),
@Doviz		nvarchar(4),
@DovizTutar	money,
@Kur		money,
@MsMerkId	decimal,
@PersId		decimal,
@KdvOrn		money,
@Aciklama	nvarchar(200),
@OzelKod1	nvarchar(20),
@OzelKod2	nvarchar(20),
@OzelKod3	nvarchar(20),
@Kullanici	nvarchar(20),
@MagazaKodu	nvarchar(20),
@Deger		Decimal,
@Yeni		Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
		INSERT Tb_KasaHareket(
		KsHFisId,KsHTur,KsHTarih,KsHSaat,KshEvrakNo,KsHKasaId,KsHTipi,KsHKarsiHsId,KsHFaiz,KsHKdvOrn,
		KsHTutar,KsHDovizTip,KsHDoviz,KsHDovizTutar,KsHKur,KsHMsMerkId,KsHPersId,KsHAciklama,KsHOzelKod1,KsHOzelKod2,
		KsHOzelKod3,KsHKayKullanici,KsHMagazaKodu,KsHKayitTarihi,KsHKayitSaati
		) VALUES (
		@FisId,@Tur,@Tarih,@Saat,@EvrakNo,@AnaId,@Tipi,@KarsiHsId,@Faiz,@KdvOrn, 
		@Tutar,@DovizTip,@Doviz,@DovizTutar,@Kur,@MsMerkId,@PersId,@Aciklama,
		@OzelKod1,@OzelKod2,@OzelKod3,@Kullanici,@MagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_KasaHareket SET
		KsHFisId=@FisId,KsHTur=@Tur,KsHTarih=@Tarih,KsHSaat=@Saat,KsHKdvOrn=@KdvOrn, 
		KsHEvrakNo=@EvrakNo,KsHKasaId=@AnaId,KsHTipi=@Tipi,KsHFaiz=@Faiz, 
		KsHKarsiHsId=@KarsiHsId,KsHTutar=@Tutar,KsHDovizTip=@DovizTip,KsHDoviz=@Doviz,
		KsHDovizTutar=@DovizTutar,KsHKur=@Kur,KsHMsMerkId=@MsMerkId,KsHPersId=@PersId,
		KsHAciklama=@Aciklama,KsHOzelKod1=@OzelKod1,KsHOzelKod2=@OzelKod2,KsHOzelKod3=@OzelKod3,
		KsHDuzKullanici=@Kullanici,KsHMagazaKodu=@MagazaKodu,
		KsHDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		KsHDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE KsHId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spKasaKartKaydet]
@KasKod			nvarchar(30),
@KasAd			nvarchar(100),
@KasOzelKod1	nvarchar(20),
@KasOzelKod2	nvarchar(20),
@KasOzelKod3	nvarchar(20),
@KasOzelKod4	nvarchar(20),
@KasOzelKod5	nvarchar(20),
@KasMinBakiye	money,
@KasMaxBakiye	money,
@KasAnaGrup		nvarchar(5),
@KasAciklama	nvarchar(1000),
@KasUyari		nvarchar(200),
@KasSorId1		decimal,
@KasSorId2		decimal,
@KasAltGrup		nvarchar(5),
@KasDoviz		nvarchar(4),
@KasDovizTip	nvarchar(5),
@KasTanimlar	nvarchar(30),
@KasAciklama1	nvarchar(50),
@KasAciklama2	nvarchar(50),
@KasAciklama3	nvarchar(50),
@KasEkTutar1	money,
@KasEkTutar2	money,
@KasEkTutar3	money,
@KasEkOran1		money,
@KasEkOran2		money,
@KasEkOran3		money,
@KasKullanici	nvarchar(20),
@KasMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_KasaKart (
		KasKod,KasAd,KasOzelKod1,KasOzelKod2,KasOzelKod3,KasOzelKod4,KasOzelKod5,KasMinBakiye,KasMaxBakiye,
		KasAnaGrup,KasAciklama,KasUyari,KasSorId1,KasSorId2,KasAltGrup,KasDoviz,KasDovizTip,KasTanimlar,
		KasAciklama1,KasAciklama2,KasAciklama3,KasEkTutar1,KasEkTutar2,KasEkTutar3,KasEkOran1,KasEkOran2,
		KasEkOran3,KasKayKullanici,KasMagazaKodu,KasKayitTarihi,KasKayitSaati
		) VALUES (
		@KasKod,@KasAd,@KasOzelKod1,@KasOzelKod2,@KasOzelKod3,@KasOzelKod4,@KasOzelKod5,@KasMinBakiye,@KasMaxBakiye,
		@KasAnaGrup,@KasAciklama,@KasUyari,@KasSorId1,@KasSorId2,@KasAltGrup,@KasDoviz,@KasDovizTip,@KasTanimlar,
		@KasAciklama1,@KasAciklama2,@KasAciklama3,@KasEkTutar1,@KasEkTutar2,@KasEkTutar3,@KasEkOran1,@KasEkOran2,
		@KasEkOran3,@KasKullanici,@KasMagazaKodu,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_KasaKart SET
		KasKod=@KasKod,KasAd=@KasAd,KasOzelKod1=@KasOzelKod1,KasOzelKod2=@KasOzelKod2,
		KasOzelKod3=@KasOzelKod3,KasOzelKod4=@KasOzelKod4,KasOzelKod5=@KasOzelKod5,
		KasMinBakiye=@KasMinBakiye,KasMaxBakiye=@KasMaxBakiye,KasAnaGrup=@KasAnaGrup,
		KasAciklama=@KasAciklama,KasUyari=@KasUyari,KasSorId1=@KasSorId1,KasSorId2=@KasSorId2,
		KasAltGrup=@KasAltGrup,KasDoviz=@KasDoviz,KasDovizTip=@KasDovizTip,KasTanimlar=@KasTanimlar,
		KasAciklama1=@KasAciklama1,KasAciklama2=@KasAciklama2,KasAciklama3=@KasAciklama3,
		KasEkTutar1=@KasEkTutar1,KasEkTutar2=@KasEkTutar2,KasEkTutar3=@KasEkTutar3,
		KasEkOran1=@KasEkOran1,KasEkOran2=@KasEkOran2,KasEkOran3=@KasEkOran3,
		KasDuzKullanici=@KasKullanici,KasMagazaKodu=@KasMagazaKodu,
		KasDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		KasDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE KasId=@Deger 
	END
END
GO
CREATE PROCEDURE [dbo].[spKrediKaydet]
@KreKod			nvarchar(30),
@KreTarih		date,
@KreSaat		time,
@KreDurum		tinyint,
@KreAd			nvarchar(100),
@KreDoviz		nvarchar(4),
@KreDovizTip	nvarchar(5),
@KreTutar		money,
@KreFaiz		money,
@KreKkdf		money,
@KreTeminat		tinyint,
@KreTuru		tinyint,
@KreMasraf		money,
@KreTaksitAdet	tinyint,
@KreOdeme		money,
@KreTkEkle		tinyint,
@KreBsmv		money,
@KreSozlesmeNo	nvarchar(20),
@KreVadeBasl	date,
@KreVadeGun		tinyint,
@KreErOdeOran	money,
@KreSorumId		decimal,
@KreGcOdeOran	money,
@KreSubeId		decimal,
@KreOzelKod1	nvarchar(20),
@KreOzelKod2	nvarchar(20),
@KreOzelKod3	nvarchar(20),
@KreOzelKod4	nvarchar(20),
@KreOzelKod5	nvarchar(20),
@KreAciklama	nvarchar(1000),
@KreUyari		nvarchar(200),
@KreKullanici	nvarchar(20),
@KreMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_Kredi(
		KreKod,KreTarih,KreSaat,KreAd,KreDoviz,KreDovizTip,KreTutar,KreFaiz,KreKkdf,KreDurum,KreOdeme,KreTkEkle,
		KreTeminat,KreTuru,KreMasraf,KreTaksitAdet,KreBsmv,KreSozlesmeNo,KreVadeBasl,KreVadeGun,
		KreErOdeOran,KreSorumId,KreGcOdeOran,KreOzelKod1,KreOzelKod2,KreOzelKod3,KreOzelKod4,KreSubeId,
		KreOzelKod5,KreAciklama,KreUyari,KreKayKullanici,KreMagazaKodu,KreKayitTarihi,KreKayitSaati
		) VALUES (
		@KreKod,@KreTarih,@KreSaat,@KreAd,@KreDoviz,@KreDovizTip,@KreTutar,@KreFaiz,@KreKkdf,@KreDurum,
		@KreOdeme,@KreTkEkle,@KreTeminat,@KreTuru,@KreMasraf,@KreTaksitAdet,@KreBsmv,@KreSozlesmeNo,
		@KreVadeBasl,@KreVadeGun,@KreErOdeOran,@KreSorumId,@KreGcOdeOran,@KreOzelKod1,
		@KreOzelKod2,@KreOzelKod3,@KreOzelKod4,@KreSubeId,@KreOzelKod5,@KreAciklama,@KreUyari,
		@KreKullanici,@KreMagazaKodu,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_Kredi SET
		KreKod=@KreKod,KreTarih=@KreTarih,KreSaat=@KreSaat,KreAd=@KreAd,KreDoviz=@KreDoviz,
		KreDovizTip=@KreDovizTip,KreTutar=@KreTutar,KreFaiz=@KreFaiz,KreKkdf=@KreKkdf,
		KreTeminat=@KreTeminat,KreTuru=@KreTuru,KreMasraf=@KreMasraf,KreTaksitAdet=@KreTaksitAdet,
		KreBsmv=@KreBsmv,KreSozlesmeNo=@KreSozlesmeNo,KreVadeBasl=@KreVadeBasl,
		KreVadeGun=@KreVadeGun,KreErOdeOran=@KreErOdeOran,KreSorumId=@KreSorumId,
		KreGcOdeOran=@KreGcOdeOran,KreOzelKod1=@KreOzelKod1,KreOzelKod2=@KreOzelKod2,
		KreOzelKod3=@KreOzelKod3,KreOzelKod4=@KreOzelKod4,KreOzelKod5=@KreOzelKod5,
		KreAciklama=@KreAciklama,KreUyari=@KreUyari,KreDuzKullanici=@KreKullanici,
		KreMagazaKodu=@KreMagazaKodu,KreDurum=@KreDurum,KreSubeId=@KreSubeId,
		KreOdeme=@KreOdeme,KreTkEkle=@KreTkEkle,
		KreDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		KreDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE KreId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spMasrafKartKaydet]
@MasKod			nvarchar(30),
@MasAd			nvarchar(100),
@MasOzelKod1	nvarchar(20),
@MasOzelKod2	nvarchar(20),
@MasOzelKod3	nvarchar(20),
@MasOzelKod4	nvarchar(20),
@MasOzelKod5	nvarchar(20),
@MasAnaGrup		nvarchar(5),
@MasAciklama	nvarchar(1000),
@MasUyari		nvarchar(200),
@MasPerId		decimal,
@MasSorId		decimal,
@MasAltGrup		nvarchar(5),
@MasDurum		tinyint,
@MasPersBg		tinyint,
@MasAlacak		tinyint,
@MasAlTutar		money,
@MasKsGider		money,
@MasBnGider		money,
@MasAciklama1	nvarchar(50),
@MasAciklama2	nvarchar(50),
@MasAciklama3	nvarchar(50),
@MasKdvOrn		money,
@MasKdvId		decimal,
@MasEkTutar1	money,
@MasEkTutar2	money,
@MasEkTutar3	money,
@MasEkOran1		money,
@MasEkOran2		money,
@MasEkOran3		money,
@MasKullanici	nvarchar(20),
@MasMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_MasrafKart (
		MasKod,MasAd,MasOzelKod1,MasOzelKod2,MasOzelKod3,MasOzelKod4,MasOzelKod5,MasAnaGrup,MasAciklama,MasUyari,
		MasPerId,MasAltGrup,MasDurum,MasPersBg,MasAciklama1,MasAciklama2,MasAciklama3,MasSorId,MasKdvOrn,MasKdvId,
		MasAlacak,MasAlTutar,MasKsGider,MasBnGider,MasEkTutar1,MasEkTutar2,MasEkTutar3,MasEkOran1,MasEkOran2,
		MasEkOran3,MasKayKullanici,MasMagazaKodu,MasKayitTarihi,MasKayitSaati
		) VALUES (
		@MasKod,@MasAd,@MasOzelKod1,@MasOzelKod2,@MasOzelKod3,@MasOzelKod4,@MasOzelKod5,@MasAnaGrup,@MasAciklama,
		@MasUyari,@MasPerId,@MasAltGrup,@MasDurum,@MasPersBg,@MasAciklama1,@MasAciklama2,@MasAciklama3,@MasSorId,
		@MasKdvOrn,@MasKdvId,@MasAlacak,@MasAlTutar,@MasKsGider,@MasBnGider,@MasEkTutar1,@MasEkTutar2,@MasEkTutar3,
		@MasEkOran1,@MasEkOran2,@MasEkOran3,@MasKullanici,@MasMagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_MasrafKart SET
		MasKod=@MasKod,MasAd=@MasAd,MasOzelKod1=@MasOzelKod1,MasOzelKod2=@MasOzelKod2,MasOzelKod3=@MasOzelKod3,
		MasOzelKod4=@MasOzelKod4,MasOzelKod5=@MasOzelKod5,MasAnaGrup=@MasAnaGrup,MasAciklama=@MasAciklama,MasUyari=@MasUyari,
		MasPerId=@MasPerId,MasAltGrup=@MasAltGrup,MasDurum=@MasDurum,MasSorId=@MasSorId,MasBnGider=@MasBnGider,
		MasPersBg=@MasPersBg,MasAciklama1=@MasAciklama1,MasAciklama2=@MasAciklama2,MasAciklama3=@MasAciklama3,
		MasEkTutar1=@MasEkTutar1,MasEkTutar2=@MasEkTutar2,MasEkTutar3=@MasEkTutar3,MasKsGider=@MasKsGider,
		MasEkOran1=@MasEkOran1,MasEkOran2=@MasEkOran2,MasEkOran3=@MasEkOran3,MasAlTutar=@MasAlTutar,MasKdvId=@MasKdvId, 
		MasDuzKullanici=@MasKullanici,MasMagazaKodu=@MasMagazaKodu,MasAlacak=@MasAlacak,MasKdvOrn=@MasKdvOrn, 
		MasDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		MasDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE MasId=@Deger 
	END
END
GO
CREATE PROCEDURE [dbo].[spMasrafMerkKaydet]
@MmzKod			nvarchar(30),
@MmzAd			nvarchar(100),
@MmzOzelKod1	nvarchar(20),
@MmzOzelKod2	nvarchar(20),
@MmzOzelKod3	nvarchar(20),
@MmzOzelKod4	nvarchar(20),
@MmzOzelKod5	nvarchar(20),
@MmzAnaGrup		nvarchar(5),
@MmzAciklama	nvarchar(1000),
@MmzUyari		nvarchar(200),
@MmzSorId		decimal,
@MmzAltGrup		nvarchar(5),
@MmzButGelir	money,
@MmzButGider	money,
@MmzDurum		tinyint,
@MmzAciklama1	nvarchar(50),
@MmzAciklama2	nvarchar(50),
@MmzAciklama3	nvarchar(50),
@MmzEkTutar1	money,
@MmzEkTutar2	money,
@MmzEkTutar3	money,
@MmzEkOran1		money,
@MmzEkOran2		money,
@MmzEkOran3		money,
@MmzKullanici	nvarchar(20),
@MmzMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_MasrafMerk (
		MmzKod,MmzAd,MmzOzelKod1,MmzOzelKod2,MmzOzelKod3,MmzOzelKod4,MmzOzelKod5,MmzAnaGrup,MmzAciklama,MmzUyari,MmzSorId,
		MmzAltGrup,MmzDurum,MmzAciklama1,MmzAciklama2,MmzAciklama3,MmzEkTutar1,MmzEkTutar2,
		MmzEkTutar3,MmzEkOran1,MmzEkOran2,MmzEkOran3,MmzKayKullanici,MmzMagazaKodu,MmzKayitTarihi,MmzButGelir,MmzButGider,MmzKayitSaati
		) VALUES (
		@MmzKod,@MmzAd,@MmzOzelKod1,@MmzOzelKod2,@MmzOzelKod3,@MmzOzelKod4,@MmzOzelKod5,@MmzAnaGrup,@MmzAciklama,@MmzUyari,
		@MmzSorId,@MmzAltGrup,@MmzDurum,@MmzAciklama1,@MmzAciklama2,@MmzAciklama3,
		@MmzEkTutar1,@MmzEkTutar2,@MmzEkTutar3,@MmzEkOran1,@MmzEkOran2,@MmzEkOran3,@MmzKullanici,@MmzMagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),@MmzButGelir,@MmzButGider,  
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_MasrafMerk SET
		MmzKod=@MmzKod,MmzAd=@MmzAd,MmzOzelKod1=@MmzOzelKod1,MmzOzelKod2=@MmzOzelKod2,MmzOzelKod3=@MmzOzelKod3,
		MmzOzelKod4=@MmzOzelKod4,MmzOzelKod5=@MmzOzelKod5,MmzAnaGrup=@MmzAnaGrup,MmzAciklama=@MmzAciklama,MmzUyari=@MmzUyari,
		MmzSorId=@MmzSorId,MmzAltGrup=@MmzAltGrup,MmzDurum=@MmzDurum,
		MmzAciklama1=@MmzAciklama1,MmzAciklama2=@MmzAciklama2,MmzAciklama3=@MmzAciklama3,
		MmzEkTutar1=@MmzEkTutar1,MmzEkTutar2=@MmzEkTutar2,MmzEkTutar3=@MmzEkTutar3,
		MmzEkOran1=@MmzEkOran1,MmzEkOran2=@MmzEkOran2,MmzEkOran3=@MmzEkOran3,MmzButGelir=@MmzButGelir,MmzButGider=@MmzButGider,
		MmzDuzKullanici=@MmzKullanici,MmzMagazaKodu=@MmzMagazaKodu,
		MmzDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		MmzDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE MmzId=@Deger 
	END
END
GO
CREATE PROCEDURE [dbo].[spOdemeKartKaydet]
@OdKKod			nvarchar(30),
@OdKAd			nvarchar(100),
@OdKOzelKod1	nvarchar(20),
@OdKOzelKod2	nvarchar(20),
@OdKOzelKod3	nvarchar(20),
@OdKOzelKod4	nvarchar(20),
@OdKOzelKod5	nvarchar(20),
@OdKAnaGrup		nvarchar(5),
@OdKKomOran		money,
@OdKAciklama	nvarchar(1000),
@OdKUyari		nvarchar(200),
@OdKSorId		decimal,
@OdKCariId		decimal,
@OdKAltGrup		nvarchar(5),
@OdKDurum		tinyint,
@OdKAciklama1	nvarchar(50),
@OdKAciklama2	nvarchar(50),
@OdKAciklama3	nvarchar(50),
@OdKEkTutar1	money,
@OdKEkTutar2	money,
@OdKEkTutar3	money,
@OdKEkOran1		money,
@OdKEkOran2		money,
@OdKEkOran3		money,
@OdKKullanici	nvarchar(20),
@OdKMagazaKodu	nvarchar(50),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_OdemeKart (
		OdKKod,OdKAd,OdKOzelKod1,OdKOzelKod2,OdKOzelKod3,OdKOzelKod4,OdKOzelKod5,OdKAnaGrup,OdKAciklama,OdKUyari,OdKCariId,
		OdKAltGrup,OdKDurum,OdKSorId,OdKKomOran,OdKAciklama1,OdKAciklama2,OdKAciklama3,OdKEkTutar1,OdKEkTutar2,
		OdKEkTutar3,OdKEkOran1,OdKEkOran2,OdKEkOran3,OdKKayKullanici,OdKMagazaKodu,OdKKayitTarihi,OdKKayitSaati
		) VALUES (
		@OdKKod,@OdKAd,@OdKOzelKod1,@OdKOzelKod2,@OdKOzelKod3,@OdKOzelKod4,@OdKOzelKod5,@OdKAnaGrup,@OdKAciklama,@OdKUyari,
		@OdKCariId,@OdKAltGrup,@OdKDurum,@OdKSorId,@OdKKomOran,@OdKAciklama1,@OdKAciklama2,@OdKAciklama3,
		@OdKEkTutar1,@OdKEkTutar2,@OdKEkTutar3,@OdKEkOran1,@OdKEkOran2,@OdKEkOran3,@OdKKullanici,@OdKMagazaKodu,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_OdemeKart SET
		OdKKod=@OdKKod,OdKAd=@OdKAd,OdKOzelKod1=@OdKOzelKod1,OdKOzelKod2=@OdKOzelKod2,OdKOzelKod3=@OdKOzelKod3,
		OdKOzelKod4=@OdKOzelKod4,OdKOzelKod5=@OdKOzelKod5,OdKAnaGrup=@OdKAnaGrup,OdKAciklama=@OdKAciklama,OdKUyari=@OdKUyari,
		OdKCariId=@OdKCariId,OdKAltGrup=@OdKAltGrup,OdKDurum=@OdKDurum,OdKSorId=@OdKSorId,
		OdKAciklama1=@OdKAciklama1,OdKAciklama2=@OdKAciklama2,OdKAciklama3=@OdKAciklama3,
		OdKEkTutar1=@OdKEkTutar1,OdKEkTutar2=@OdKEkTutar2,OdKEkTutar3=@OdKEkTutar3,
		OdKEkOran1=@OdKEkOran1,OdKEkOran2=@OdKEkOran2,OdKEkOran3=@OdKEkOran3,OdKKomOran=@OdKKomOran,
		OdKDuzKullanici=@OdKKullanici,OdKMagazaKodu=@OdKMagazaKodu,
		OdKDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		OdKDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE OdKId=@Deger 
	END
END
GO
CREATE PROCEDURE [dbo].[spPartiKartKaydet]
@PrtKod				nvarchar(30),
@PrtBaslTarih		date,
@PrtBitsTarih		date,
@PrtAd				nvarchar(100),
@PrtStokId			decimal,
@PrtOzelKod1		nvarchar(20),
@PrtOzelKod2		nvarchar(20),
@PrtOzelKod3		nvarchar(20),
@PrtOzelKod4		nvarchar(20),
@PrtOzelKod5		nvarchar(20),
@PrtAciklama		nvarchar(1000),
@PrtUyari			nvarchar(200),
@PrtAnaGrup			nvarchar(5),
@PrtAltGrup			nvarchar(5),
@PrtRenId			decimal,
@PrtBeden			nvarchar(10),
@PrtEn				money,
@PrtBoy				money,
@PrtYukseklik		money,
@PrtAgirlik			money,
@PrtAciklama1		nvarchar(50),
@PrtAciklama2		nvarchar(50),
@PrtAciklama3		nvarchar(50),
@PrtEkTutar1		money,
@PrtEkTutar2		money,
@PrtEkTutar3		money,
@PrtEkOran1			money,
@PrtEkOran2			money,
@PrtEkOran3			money,
@PrtKullanici		nvarchar(20),
@PrtMagazaKodu		nvarchar(20),
@Deger				decimal,
@Yeni				decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
		INSERT Tb_PartiKart(PrtKod,PrtAd,PrtStokId,PrtAciklama,PrtUyari,PrtAnaGrup,PrtAltGrup,PrtRenId,PrtBeden,PrtEn,
		PrtBoy,PrtYukseklik,PrtAgirlik,PrtOzelKod1,PrtOzelKod2,PrtOzelKod3,PrtOzelKod4,PrtOzelKod5,PrtBaslTarih,PrtBitsTarih,
		PrtKayKullanici,PrtMagazaKodu,PrtAciklama1,PrtAciklama2,PrtAciklama3,PrtEkTutar1,PrtEkTutar2,PrtEkTutar3,
		PrtEkOran1,PrtEkOran2,PrtEkOran3,PrtKayitTarihi,PrtKayitSaati
		) VALUES (
		@PrtKod,@PrtAd,@PrtStokId,@PrtAciklama,@PrtUyari,@PrtAnaGrup,@PrtAltGrup,@PrtRenId,@PrtBeden,@PrtEn,@PrtBoy,
		@PrtYukseklik,@PrtAgirlik,@PrtOzelKod1,@PrtOzelKod2,@PrtOzelKod3,@PrtOzelKod4,@PrtOzelKod5,@PrtBaslTarih,@PrtBitsTarih,
		@PrtKullanici,@PrtMagazaKodu,@PrtAciklama1,@PrtAciklama2,@PrtAciklama3,@PrtEkTutar1,@PrtEkTutar2,@PrtEkTutar3,
		@PrtEkOran1,@PrtEkOran2,@PrtEkOran3,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		)
		SELECT @@Identity
	END
	ELSE              
	BEGIN
		UPDATE Tb_PartiKart SET
		PrtKod=@PrtKod,PrtAd=@PrtAd,PrtStokId=@PrtStokId,PrtAciklama=@PrtAciklama,PrtUyari=@PrtUyari,PrtAnaGrup=@PrtAnaGrup,
		PrtAltGrup=@PrtAltGrup,PrtRenId=@PrtRenId,PrtBeden=@PrtBeden,PrtEn=@PrtEn,PrtBoy=@PrtBoy,PrtYukseklik=@PrtYukseklik,
		PrtAgirlik=@PrtAgirlik,PrtOzelKod1=@PrtOzelKod1,PrtOzelKod2=@PrtOzelKod2,PrtOzelKod3=@PrtOzelKod3,PrtOzelKod4=@PrtOzelKod4,
		PrtOzelKod5=@PrtOzelKod5,PrtBaslTarih=@PrtBaslTarih,PrtBitsTarih=@PrtBitsTarih,PrtAciklama1=@PrtAciklama1,PrtAciklama2=@PrtAciklama2,
		PrtAciklama3=@PrtAciklama3,PrtEkTutar1=@PrtEkTutar1,PrtEkTutar2=@PrtEkTutar2,PrtEkTutar3=@PrtEkTutar3,
		PrtEkOran1=@PrtEkOran1,PrtEkOran2=@PrtEkOran2,PrtEkOran3=@PrtEkOran3,
		PrtDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),				            
		PrtDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE PrtId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spSatisKaydet]
@Tur			tinyint,
@Tarih			date,
@Vade			date,
@Saat			nvarchar(5),
@No				nvarchar(20),
@CariId			decimal,
@PersId			decimal,
@DepoId			decimal,
@KdvTip			tinyint,
@MsMerkId		decimal,
@OtvTip			tinyint,
@OzelKod1		nvarchar(20),
@OzelKod2		nvarchar(20),
@OzelKod3		nvarchar(20),
@Aciklama		nvarchar(200),
@AdresTip		tinyint,
@IskTutar1		money,
@IskTutar2		money,
@IskTutar3		money,
@IskTutar4		money,
@IskTutar5		money,
@IskOran1		money,
@IskOran2		money,
@IskOran3		money,
@IskOran4		money,
@IskOran5		money,
@IskDvTip1		nvarchar(5),
@IskDvTip2		nvarchar(5),
@IskDvTip3		nvarchar(5),
@IskDvTip4		nvarchar(5),
@IskDvTip5		nvarchar(5),
@IskDov1		nvarchar(5),
@IskDov2		nvarchar(5),
@IskDov3		nvarchar(5),
@IskDov4		nvarchar(5),
@IskDov5		nvarchar(5),
@IskDvTut1		money,
@IskDvTut2		money,
@IskDvTut3		money,
@IskDvTut4		money,
@IskDvTut5		money,
@IskKur1		money,
@IskKur2		money,
@IskKur3		money,
@IskKur4		money,
@IskKur5		money,
@MasTutar1		money,
@MasTutar2		money,
@MasTutar3		money,
@MasTutar4		money,
@MasTutar5		money,
@MasOran1		money,
@MasOran2		money,
@MasOran3		money,
@MasOran4		money,
@MasOran5		money,
@MasDvTip1		nvarchar(5),
@MasDvTip2		nvarchar(5),
@MasDvTip3		nvarchar(5),
@MasDvTip4		nvarchar(5),
@MasDvTip5		nvarchar(5),
@MasDov1		nvarchar(5),
@MasDov2		nvarchar(5),
@MasDov3		nvarchar(5),
@MasDov4		nvarchar(5),
@MasDov5		nvarchar(5),
@MasDvTut1		money,
@MasDvTut2		money,
@MasDvTut3		money,
@MasDvTut4		money,
@MasDvTut5		money,
@MasKur1		money,
@MasKur2		money,
@MasKur3		money,
@MasKur4		money,
@MasKur5		money,
@KdvAlIn1		money,
@KdvAlIn2		money,
@KdvAlEk1		money,
@KdvAlEk2		money,
@TevkOran		money,
@KdvOran		money,
@MalToplam		money,
@KalIsk			money,
@GenIsk			money,
@TopIsk			money,
@TopMas			money,
@AraTop			money,
@OtvTop			money,
@KdvMat			money,
@OtvMat			money,
@KdvTut			money,
@BrtTop			money,
@KdvAIn			money,
@KdvAEk			money,
@GenTop			money,
@VerTop			money,
@TevTut			money,
@OdnVer			money,
@KefilId1		decimal,
@KefilId2		decimal,
@KefilId3		decimal,
@KefilId4		decimal,
@KefilTip		tinyint,
@TesTarih		date,
@TesSaat1		nvarchar(5),
@TesSaat2		nvarchar(5),
@TesAlan		nvarchar(50),
@TesPersId		decimal,
@TesAdrTip		tinyint,
@TesYeri		tinyint,
@TesNot			nvarchar(100),
@EkVerTut		money,
@Kullanici		nvarchar(20),
@MagazaKodu		nvarchar(20),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_Satis(
		SatTur,SatTarih,SatSaat,SatNo,SatCariId,SatPersId,SatKdvTip,SatMsMerkId,SatOtvTip,SatOzelKod1,SatOzelKod2,
		SatOzelKod3,SatAciklama,SatAdresTip,SatIskTutar1,SatIskTutar2,SatIskTutar3,SatIskTutar4,SatIskTutar5,
		SatIskOran1,SatIskOran2,SatIskOran3,SatIskOran4,SatIskOran5,SatIskDvTip1,SatIskDvTip2,SatIskDvTip3,
		SatIskDvTip4,SatIskDvTip5,SatIskDov1,SatIskDov2,SatIskDov3,SatIskDov4,SatIskDov5,SatIskDvTut1,SatIskDvTut2,
		SatIskDvTut3,SatIskDvTut4,SatIskDvTut5,SatIskKur1,SatIskKur2,SatIskKur3,SatIskKur4,SatIskKur5,
		SatMasTutar1,SatMasTutar2,SatMasTutar3,SatMasTutar4,SatMasTutar5,SatMasOran1,SatMasOran2,SatMasOran3,
		SatMasOran4,SatMasOran5,SatMasDvTip1,SatMasDvTip2,SatMasDvTip3,SatMasDvTip4,SatMasDvTip5,SatMasDov1,
		SatMasDov2,SatMasDov3,SatMasDov4,SatMasDov5,SatMasDvTut1,SatMasDvTut2,SatMasDvTut3,SatMasDvTut4,
		SatMasDvTut5,SatMasKur1,SatMasKur2,SatMasKur3,SatMasKur4,SatMasKur5,SatKdvAlIn1,SatKdvAlIn2,SatKdvAlEk1,
		SatKdvAlEk2,SatTevkOran,SatKdvOran,SatMalToplam,SatKalIsk,SatGenIsk,SatTopIsk,SatTopMas,SatAraTop,SatOtvTop,
		SatKdvMat,SatKdvTut,SatBrtTop,SatKdvAIn,SatKdvAEk,SatGenTop,SatVerTop,SatTevTut,SatOdnVer,
		SatKayKullanici,SatMagazaKodu,SatKefilId1,SatKefilId2,SatKefilId3,SatKefilId4,SatKefilTip,SatTesTarih,
		SatTesSaat1,SatTesSaat2,SatTesAlan,SatTesPersId,SatTesAdrTip,SatTesYeri,SatTesNot,SatVade,SatOtvMat,
		SatDepoId,SatEkVerTut,SatKayTarihi,SatKaySaati
		) VALUES (
		@Tur,@Tarih,@Saat,@No,@CariId,@PersId,@KdvTip,@MsMerkId,@OtvTip,@OzelKod1,@OzelKod2,@OzelKod3,@Aciklama,
		@AdresTip,@IskTutar1,@IskTutar2,@IskTutar3,@IskTutar4,@IskTutar5,@IskOran1,@IskOran2,@IskOran3,@IskOran4,
		@IskOran5,@IskDvTip1,@IskDvTip2,@IskDvTip3,@IskDvTip4,@IskDvTip5,@IskDov1,@IskDov2,@IskDov3,@IskDov4,@IskDov5,
		@IskDvTut1,@IskDvTut2,@IskDvTut3,@IskDvTut4,@IskDvTut5,@IskKur1,@IskKur2,@IskKur3,@IskKur4,@IskKur5,
		@MasTutar1,@MasTutar2,@MasTutar3,@MasTutar4,@MasTutar5,@MasOran1,@MasOran2,@MasOran3,@MasOran4,@MasOran5,
		@MasDvTip1,@MasDvTip2,@MasDvTip3,@MasDvTip4,@MasDvTip5,@MasDov1,@MasDov2,@MasDov3,@MasDov4,@MasDov5,
		@MasDvTut1,@MasDvTut2,@MasDvTut3,@MasDvTut4,@MasDvTut5,@MasKur1,@MasKur2,@MasKur3,@MasKur4,@MasKur5,@KdvAlIn1,
		@KdvAlIn2,@KdvAlEk1,@KdvAlEk2,@TevkOran,@KdvOran,@MalToplam,@KalIsk,@GenIsk,@TopIsk,@TopMas,@AraTop,@OtvTop,    
		@KdvMat,@KdvTut,@BrtTop,@KdvAIn,@KdvAEk,@GenTop,@VerTop,@TevTut,@OdnVer,@Kullanici,@MagazaKodu,
		@KefilId1,@KefilId2,@KefilId3,@KefilId4,@KefilTip,@TesTarih,@TesSaat1,@TesSaat2,@TesAlan,@TesPersId,
		@TesAdrTip,@TesYeri,@TesNot,@Vade,@OtvMat,@DepoId,@EkVerTut, 
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_Satis SET
		SatTur=@Tur,SatTarih=@Tarih,SatSaat=@Saat,SatNo=@No,SatCariId=@CariId,SatPersId=@PersId,
		SatKdvTip=@KdvTip,SatMsMerkId=@MsMerkId,SatOtvTip=@OtvTip,SatOzelKod1=@OzelKod1,SatOzelKod2=@OzelKod2,
		SatOzelKod3=@OzelKod3,SatAciklama=@Aciklama,SatAdresTip=@AdresTip,SatIskTutar1=@IskTutar1,
		SatIskTutar2=@IskTutar2,SatIskTutar3=@IskTutar3,SatIskTutar4=@IskTutar4,SatIskTutar5=@IskTutar5,
		SatIskOran1=@IskOran1,SatIskOran2=@IskOran2,SatIskOran3=@IskOran3,SatIskOran4=@IskOran4,
		SatIskOran5=@IskOran5,SatIskDvTip1=@IskDvTip1,SatIskDvTip2=@IskDvTip2,SatIskDvTip3=@IskDvTip3,
		SatIskDvTip4=@IskDvTip4,SatIskDvTip5=@IskDvTip5,SatIskDov1=@IskDov1,SatIskDov2=@IskDov2,
		SatIskDov3=@IskDov3,SatIskDov4=@IskDov4,SatIskDov5=@IskDov5,SatIskDvTut1=@IskDvTut1,
		SatIskDvTut2=@IskDvTut2,SatIskDvTut3=@IskDvTut3,SatIskDvTut4=@IskDvTut4,SatIskDvTut5=@IskDvTut5,
		SatIskKur1=@IskKur1,SatIskKur2=@IskKur2,SatIskKur3=@IskKur3,SatIskKur4=@IskKur4,SatIskKur5=@IskKur5,
		SatMasTutar1=@MasTutar1,SatMasTutar2=@MasTutar2,SatMasTutar3=@MasTutar3,SatEkVerTut=@EkVerTut,
		SatMasTutar4=@MasTutar4,SatMasTutar5=@MasTutar5,SatMasOran1=@MasOran1,SatMasOran2=@MasOran2,
		SatMasOran3=@MasOran3,SatMasOran4=@MasOran4,SatMasOran5=@MasOran5,SatMasDvTip1=@MasDvTip1,
		SatMasDvTip2=@MasDvTip2,SatMasDvTip3=@MasDvTip3,SatMasDvTip4=@MasDvTip4,SatMasDvTip5=@MasDvTip5,
		SatMasDov1=@MasDov1,SatMasDov2=@MasDov2,SatMasDov3=@MasDov3,SatMasDov4=@MasDov4,
		SatMasDov5=@MasDov5,SatMasDvTut1=@MasDvTut1,SatMasDvTut2=@MasDvTut2,SatMasDvTut3=@MasDvTut3,
		SatMasDvTut4=@MasDvTut4,SatMasDvTut5=@MasDvTut5,SatMasKur1=@MasKur1,SatMasKur2=@MasKur2,
		SatMasKur3=@MasKur3,SatMasKur4=@MasKur4,SatMasKur5=@MasKur5,SatKdvAlIn1=@KdvAlIn1,
		SatKdvAlIn2=@KdvAlIn2,SatKdvAlEk1=@KdvAlEk1,SatKdvAlEk2=@KdvAlEk2,SatTevkOran=@TevkOran,SatKdvOran=@KdvOran,
		SatMalToplam=@MalToplam,SatKalIsk=@KalIsk,SatGenIsk=@GenIsk,SatTopIsk=@TopIsk,SatTopMas=@TopMas,
		SatAraTop=@AraTop,SatOtvTop=@OtvTop,SatKdvMat=@KdvMat,SatKdvTut=@KdvTut,SatBrtTop=@BrtTop,SatKdvAIn=@KdvAIn,
		SatKdvAEk=@KdvAEk,SatGenTop=@GenTop,SatVerTop=@VerTop,SatTevTut=@TevTut,SatOdnVer=@OdnVer,
		SatDuzKullanici=@Kullanici,SatTesTarih=@TesTarih,SatTesSaat1=@TesSaat1,SatTesSaat2=@TesSaat2,
		SatTesAlan=@TesAlan,SatTesPersId=@TesPersId,SatTesAdrTip=@TesAdrTip,SatTesYeri=@TesYeri,SatTesNot=@TesNot,
		SatKefilId1=@KefilId1,SatKefilId2=@KefilId2,SatKefilId3=@KefilId3,SatKefilId4=@KefilId4,SatKefilTip=@KefilTip,
		SatVade=@Vade,SatOtvMat=@OtvMat, SatDepoId=@DepoId,
		SatDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		SatDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		SatMagazaKodu=@MagazaKodu WHERE SatId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spSatisSil]
@Deger			decimal,
@Type			tinyint,
@CariH			tinyint,
@SentH			tinyint,
@SMalyTipi		tinyint
AS
BEGIN TRANSACTION
IF @Type = 0 
BEGIN
DECLARE @CariId DECIMAL
DECLARE @GenTop MONEY
	
	SELECT @CariId = SatCariId,@GenTop=SatGenTop FROM Tb_Satis where SatId = @Deger 
	UPDATE Tb_CariKart SET CarSatisBorc = CarSatisBorc - @GenTop,CarBakiye = CarBakiye - @GenTop WHERE CarId = @CariId 
	DELETE FROM Tb_Satis WHERE SatId=@Deger 
	DELETE FROM Tb_SatKalem WHERE SKlFisId = @Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 3 AND SrnBaslikId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 3 AND RnbBaslikId=@Deger
	IF @SentH = 1 DELETE Tb_CkSnKart WHERE CksId IN (SELECT TakSenetId FROM Tb_Taksit WHERE TakSatisId = @Deger) ELSE UPDATE Tb_CkSnKart SET CksModul = 0 WHERE CksId IN (SELECT TakSenetId FROM Tb_Taksit WHERE TakSatisId = @Deger)
	DELETE Tb_Taksit WHERE TakSatisId = @Deger
	IF @CariH = 1 BEGIN
		DELETE Tb_CariFis WHERE CrFId IN (SELECT CrHFisId FROM Tb_CariHareket WHERE CrHEntgId = @Deger AND (CrHEntgTipi=1 OR CrHEntgTipi=2) AND CrHCariId = @CariId)
		DELETE Tb_CariHareket WHERE CrHEntgId = @Deger AND (CrHEntgTipi=1 OR CrHEntgTipi=2)  AND CrHCariId = @CariId
		DELETE Tb_HesGecme WHERE HsgModul=0 AND HsgSatisId = @Deger 
	END
	ELSE
	BEGIN
		UPDATE Tb_CariHareket SET CrHEntgTipi=0, CrHEntgId=0 WHERE CrHEntgId=@Deger AND (CrHEntgTipi=2 OR CrHEntgTipi=1) AND CrHCariId = @CariId
		UPDATE Tb_HesGecme SET HsGModul=1,HsgSatisId = HsGCrHId WHERE HsGModul=0 AND HsGSatisId=@Deger
	END
END
ELSE 
BEGIN
	DELETE FROM Tb_SatKalem where SKlId=@Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 3 AND SrnSatirId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 3 AND RnbSatirId=@Deger
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spSatKalemKaydet]
@FisId			decimal,
@Tarih			date,
@Saat			nvarchar(5),
@Tipi			tinyint,
@KdvTipi		tinyint,
@OtvTipi		tinyint,
@SatirTipi		tinyint,
@StokId			decimal,
@Birim			nvarchar(10),
@Miktar			money,
@Fiyat			money,
@Doviz			nvarchar(4),
@DovizTipi		nvarchar(5),
@DovizFiyat		money,
@Kur			money,
@Tutar			money,
@DepoId			decimal,
@PartiId		decimal,
@BirimMiktar	money,
@BirimFiyat		money,
@MalyFiyat		money,
@MalyTutar		money,
@OtvTutar		money,
@KdvMatrah		money,
@KdvTutar		money,
@OtvMatrah		money,
@SMalyTipi		tinyint,
@KdvOran		money,
@OtvOran		money,
@IskOrn1		money,
@IskOrn2		money,
@IskOrn3		money,
@IskOrn4		money,
@IskOrn5		money,
@IskTut1		money,
@IskTut2		money,
@IskTut3		money,
@IskTut4		money,
@IskTut5		money,
@Aciklama		nvarchar(200),
@TesTarih1		date,
@TesTarih2		date,
@Teslim			tinyint,
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	DECLARE @TslMk Money
	IF @Teslim = 0 SET @TslMk=@Miktar ELSE SET @TslMk=0
	INSERT Tb_SatKalem(
		SKlFisId,SKlTarih,SKlSaat,SKlStokId,SKlTipi,SKlKdvTipi,SKlOtvTipi,SKlBirim,SKlMiktar,SKlFiyat,SKlDoviz,
		SKlDovizTipi,SKlDovizFiyat,SKlKur,SKlDepoId,SKlPartiId,SKlBirimMiktar,SKlBirimFiyat,SKlMalyFiyat,SKlMalyTutar,
		SKlKdvOran,SKlOtvOran,SKlIskOrn1,SKlIskOrn2,SKlIskOrn3,SKlIskOrn4,SKlIskOrn5,SKlIskTut1,SKlIskTut2,SKlIskTut3,
		SKlIskTut4,SKlIskTut5,SKlTutar,SKlSatirTipi,SKlTesTar1,SKlTesTar2,SKlAciklama,SKlTeslim,SKlOtvTutar,SKlKdvTutar,
		SKlOtvMatrah,SKlKdvMatrah,SklTeslimMiktar) 
		VALUES (
		@FisId,@Tarih,@Saat,@StokId,@Tipi,@KdvTipi,@OtvTipi,@Birim,@Miktar,@Fiyat,@Doviz,@DovizTipi,@DovizFiyat,@Kur,
		@DepoId,@PartiId,@BirimMiktar,@BirimFiyat,@MalyFiyat,@MalyTutar,@KdvOran,@OtvOran,@IskOrn1,@IskOrn2,@IskOrn3,
		@IskOrn4,@IskOrn5,@IskTut1,@IskTut2,@IskTut3,@IskTut4,@IskTut5,@Tutar,@SatirTipi,@TesTarih1,@TesTarih2,@Aciklama,
		@Teslim,@OtvTutar,@KdvTutar,@OtvMatrah,@KdvMatrah,@TslMk)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		DECLARE @UpdBirimMiktar MONEY
		DECLARE @UpdTeslimMiktar MONEY
		DECLARE @UpdTeslim TINYINT
		SELECT @UpdTeslim=SKlTeslim,@UpdBirimMiktar=SKlBirimMiktar,@UpdTeslimMiktar=SKlTeslimMiktar FROM Tb_SatKalem WHERE SKlId = @Deger
		IF @UpdTeslim=0 AND @Teslim = 1 
		BEGIN
			IF @UpdBirimMiktar = @UpdTeslimMiktar SET @UpdTeslimMiktar=0
		END
		UPDATE Tb_SatKalem SET
		SKlFisId=@FisId,SKlTarih=@Tarih,SKlSaat=@Saat,SKlStokId=@StokId,SKlTipi=@Tipi,SKlKdvTipi=@KdvTipi,
		SKlOtvTipi=@OtvTipi,SKlBirim=@Birim,SKlMiktar=@Miktar,SKlFiyat=@Fiyat,SKlDoviz=@Doviz,SKlDovizTipi=@DovizTipi,
		SKlDovizFiyat=@DovizFiyat,SKlKur=@Kur,SKlDepoId=@DepoId,SKlPartiId=@PartiId,SKlBirimMiktar=@BirimMiktar,
		SKlBirimFiyat=@BirimFiyat,SKlMalyFiyat=@MalyFiyat,SKlMalyTutar=@MalyTutar,SKlKdvOran=@KdvOran,
		SKlOtvOran=@OtvOran,SKlIskOrn1=@IskOrn1,SKlIskOrn2=@IskOrn2,SKlIskOrn3=@IskOrn3,SKlIskOrn4=@IskOrn4,
		SKlIskOrn5=@IskOrn5,SKlIskTut1=@IskTut1,SKlIskTut2=@IskTut2,SKlIskTut3=@IskTut3,SKlIskTut4=@IskTut4,
		SKlIskTut5=@IskTut5,SKlTutar=@Tutar,SKlSatirTipi=@SatirTipi,SKlTesTar1=@TesTarih1,SKlTesTar2=@TesTarih2,
		SKlAciklama=@Aciklama,SKlTeslim=@Teslim,SKlOtvTutar=@OtvTutar,SKlKdvTutar=@KdvTutar,SKlKdvMatrah=@KdvMatrah,
		SKlOtvMatrah=@OtvMatrah,SKlTeslimMiktar=@UpdTeslimMiktar WHERE SKlId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[SpSiparisKaydet]
@Tur			tinyint,
@Tarih			date,
@Saat			nvarchar(5),
@No				nvarchar(20),
@Tip			tinyint,
@CariId			decimal,
@PersId			decimal,
@DepoId			decimal,
@KdvTip			tinyint,
@MsMerkId		decimal,
@OtvTip			tinyint,
@OzelKod1		nvarchar(20),
@OzelKod2		nvarchar(20),
@OzelKod3		nvarchar(20),
@Aciklama		nvarchar(200),
@AdresTip		tinyint,
@IskTutar1		money,
@IskTutar2		money,
@IskTutar3		money,
@IskTutar4		money,
@IskTutar5		money,
@IskOran1		money,
@IskOran2		money,
@IskOran3		money,
@IskOran4		money,
@IskOran5		money,
@IskDvTip1		nvarchar(5),
@IskDvTip2		nvarchar(5),
@IskDvTip3		nvarchar(5),
@IskDvTip4		nvarchar(5),
@IskDvTip5		nvarchar(5),
@IskDov1		nvarchar(5),
@IskDov2		nvarchar(5),
@IskDov3		nvarchar(5),
@IskDov4		nvarchar(5),
@IskDov5		nvarchar(5),
@IskDvTut1		money,
@IskDvTut2		money,
@IskDvTut3		money,
@IskDvTut4		money,
@IskDvTut5		money,
@IskKur1		money,
@IskKur2		money,
@IskKur3		money,
@IskKur4		money,
@IskKur5		money,
@MasTutar1		money,
@MasTutar2		money,
@MasTutar3		money,
@MasTutar4		money,
@MasTutar5		money,
@MasOran1		money,
@MasOran2		money,
@MasOran3		money,
@MasOran4		money,
@MasOran5		money,
@MasDvTip1		nvarchar(5),
@MasDvTip2		nvarchar(5),
@MasDvTip3		nvarchar(5),
@MasDvTip4		nvarchar(5),
@MasDvTip5		nvarchar(5),
@MasDov1		nvarchar(5),
@MasDov2		nvarchar(5),
@MasDov3		nvarchar(5),
@MasDov4		nvarchar(5),
@MasDov5		nvarchar(5),
@MasDvTut1		money,
@MasDvTut2		money,
@MasDvTut3		money,
@MasDvTut4		money,
@MasDvTut5		money,
@MasKur1		money,
@MasKur2		money,
@MasKur3		money,
@MasKur4		money,
@MasKur5		money,
@KdvAlIn1		money,
@KdvAlIn2		money,
@KdvAlEk1		money,
@KdvAlEk2		money,
@TevkOran		money,
@KdvOran		money,
@MalToplam		money,
@KalIsk			money,
@GenIsk			money,
@TopIsk			money,
@TopMas			money,
@AraTop			money,
@OtvTop			money,
@KdvMat			money,
@KdvTut			money,
@BrtTop			money,
@KdvAIn			money,
@KdvAEk			money,
@GenTop			money,
@VerTop			money,
@TevTut			money,
@OdnVer			money,
@EkVerTut		money,
@Kaynak			tinyint,
@Kullanici		nvarchar(20),
@MagazaKodu		nvarchar(20),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_Siparis(
		SipTur,SipTarih,SipSaat,SipNo,SipCariId,SipPersId,SipKdvTip,SipMsMerkId,SipOtvTip,SipOzelKod1,SipOzelKod2,
		SipOzelKod3,SipAciklama,SipAdresTip,SipIskTutar1,SipIskTutar2,SipIskTutar3,SipIskTutar4,SipIskTutar5,
		SipIskOran1,SipIskOran2,SipIskOran3,SipIskOran4,SipIskOran5,SipIskDvTip1,SipIskDvTip2,SipIskDvTip3,
		SipIskDvTip4,SipIskDvTip5,SipIskDov1,SipIskDov2,SipIskDov3,SipIskDov4,SipIskDov5,SipIskDvTut1,
		SipIskDvTut2,SipIskDvTut3,SipIskDvTut4,SipIskDvTut5,SipIskKur1,SipIskKur2,SipIskKur3,SipIskKur4,SipIskKur5,
		SipMasTutar1,SipMasTutar2,SipMasTutar3,SipMasTutar4,SipMasTutar5,SipMasOran1,SipMasOran2,SipMasOran3,
		SipMasOran4,SipMasOran5,SipMasDvTip1,SipMasDvTip2,SipMasDvTip3,SipMasDvTip4,SipMasDvTip5,SipMasDov1,
		SipMasDov2,SipMasDov3,SipMasDov4,SipMasDov5,SipMasDvTut1,SipMasDvTut2,SipMasDvTut3,SipMasDvTut4,
		SipMasDvTut5,SipMasKur1,SipMasKur2,SipMasKur3,SipMasKur4,SipMasKur5,SipKdvAlIn1,SipKdvAlIn2,SipKdvAlEk1,
		SipKdvAlEk2,SipTevkOran,SipKdvOran,SipMalToplam,SipKalIsk,SipGenIsk,SipTopIsk,SipTopMas,SipAraTop,SipOtvTop,	
		SipKdvMat,SipKdvTut,SipBrtTop,SipKdvAIn,SipKdvAEk,SipGenTop,SipVerTop,SipTevTut,SipOdnVer,SipKayKullanici,
		SipTip,SipMagazaKodu,SipDepoId,SipEkVerTut,SipKaynak,SipKayTarihi,SipKaySaati
		) VALUES (
		@Tur,@Tarih,@Saat,@No,@CariId,@PersId,@KdvTip,@MsMerkId,@OtvTip,@OzelKod1,@OzelKod2,@OzelKod3,@Aciklama,
		@AdresTip,@IskTutar1,@IskTutar2,@IskTutar3,@IskTutar4,@IskTutar5,@IskOran1,@IskOran2,@IskOran3,@IskOran4,
		@IskOran5,@IskDvTip1,@IskDvTip2,@IskDvTip3,@IskDvTip4,@IskDvTip5,@IskDov1,@IskDov2,@IskDov3,@IskDov4,@IskDov5,
		@IskDvTut1,@IskDvTut2,@IskDvTut3,@IskDvTut4,@IskDvTut5,@IskKur1,@IskKur2,@IskKur3,@IskKur4,@IskKur5,
		@MasTutar1,@MasTutar2,@MasTutar3,@MasTutar4,@MasTutar5,@MasOran1,@MasOran2,@MasOran3,@MasOran4,@MasOran5,
		@MasDvTip1,@MasDvTip2,@MasDvTip3,@MasDvTip4,@MasDvTip5,@MasDov1,@MasDov2,@MasDov3,@MasDov4,@MasDov5,
		@MasDvTut1,@MasDvTut2,@MasDvTut3,@MasDvTut4,@MasDvTut5,@MasKur1,@MasKur2,@MasKur3,@MasKur4,@MasKur5,@KdvAlIn1,
		@KdvAlIn2,@KdvAlEk1,@KdvAlEk2,@TevkOran,@KdvOran,@MalToplam,@KalIsk,@GenIsk,@TopIsk,@TopMas,@AraTop,@OtvTop,
		@KdvMat,@KdvTut,@BrtTop,@KdvAIn,@KdvAEk,@GenTop,@VerTop,@TevTut,@OdnVer,@Kullanici,@Tip,@MagazaKodu,@DepoId,@EkVerTut,@Kaynak,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_Siparis SET
		SipTur=@Tur,SipTarih=@Tarih,SipSaat=@Saat,SipNo=@No,SipCariId=@CariId,SipPersId=@PersId,
		SipKdvTip=@KdvTip,SipMsMerkId=@MsMerkId,SipOtvTip=@OtvTip,SipOzelKod1=@OzelKod1,SipOzelKod2=@OzelKod2,
		SipOzelKod3=@OzelKod3,SipAciklama=@Aciklama,SipAdresTip=@AdresTip,SipIskTutar1=@IskTutar1,
		SipIskTutar2=@IskTutar2,SipIskTutar3=@IskTutar3,SipIskTutar4=@IskTutar4,SipIskTutar5=@IskTutar5,
		SipIskOran1=@IskOran1,SipIskOran2=@IskOran2,SipIskOran3=@IskOran3,SipIskOran4=@IskOran4,
		SipIskOran5=@IskOran5,SipIskDvTip1=@IskDvTip1,SipIskDvTip2=@IskDvTip2,SipIskDvTip3=@IskDvTip3,
		SipIskDvTip4=@IskDvTip4,SipIskDvTip5=@IskDvTip5,SipIskDov1=@IskDov1,SipIskDov2=@IskDov2,
		SipIskDov3=@IskDov3,SipIskDov4=@IskDov4,SipIskDov5=@IskDov5,SipIskDvTut1=@IskDvTut1,
		SipIskDvTut2=@IskDvTut2,SipIskDvTut3=@IskDvTut3,SipIskDvTut4=@IskDvTut4,SipIskDvTut5=@IskDvTut5,
		SipIskKur1=@IskKur1,SipIskKur2=@IskKur2,SipIskKur3=@IskKur3,SipIskKur4=@IskKur4,
		SipIskKur5=@IskKur5,SipMasTutar1=@MasTutar1,SipMasTutar2=@MasTutar2,SipMasTutar3=@MasTutar3,
		SipMasTutar4=@MasTutar4,SipMasTutar5=@MasTutar5,SipMasOran1=@MasOran1,SipMasOran2=@MasOran2,
		SipMasOran3=@MasOran3,SipMasOran4=@MasOran4,SipMasOran5=@MasOran5,SipMasDvTip1=@MasDvTip1,
		SipMasDvTip2=@MasDvTip2,SipMasDvTip3=@MasDvTip3,SipMasDvTip4=@MasDvTip4,SipMasDvTip5=@MasDvTip5,
		SipMasDov1=@MasDov1,SipMasDov2=@MasDov2,SipMasDov3=@MasDov3,SipMasDov4=@MasDov4,
		SipMasDov5=@MasDov5,SipMasDvTut1=@MasDvTut1,SipMasDvTut2=@MasDvTut2,SipMasDvTut3=@MasDvTut3,
		SipMasDvTut4=@MasDvTut4,SipMasDvTut5=@MasDvTut5,SipMasKur1=@MasKur1,SipMasKur2=@MasKur2,
		SipMasKur3=@MasKur3,SipMasKur4=@MasKur4,SipMasKur5=@MasKur5,SipKdvAlIn1=@KdvAlIn1,SipEkVerTut=@EkVerTut,
		SipKdvAlIn2=@KdvAlIn2,SipKdvAlEk1=@KdvAlEk1,SipKdvAlEk2=@KdvAlEk2,SipTevkOran=@TevkOran,
		SipKdvOran=@KdvOran,SipMalToplam=@MalToplam,SipKalIsk=@KalIsk,SipGenIsk=@GenIsk,SipDepoId=@DepoId,
		SipTopIsk=@TopIsk,SipTopMas=@TopMas,SipAraTop=@AraTop,SipOtvTop=@OtvTop,SipKdvMat=@KdvMat,
		SipKdvTut=@KdvTut,SipBrtTop=@BrtTop,SipKdvAIn=@KdvAIn,SipKdvAEk=@KdvAEk,SipGenTop=@GenTop,
		SipVerTop=@VerTop,SipTevTut=@TevTut,SipOdnVer=@OdnVer,SipDuzKullanici=@Kullanici,
		SipDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		SipDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		SipMagazaKodu=@MagazaKodu WHERE SipId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spSiparisSil]
@Deger			decimal,
@Type			tinyint
AS
BEGIN TRANSACTION
IF @Type = 0 
BEGIN
	DELETE FROM Tb_Siparis WHERE SipId=@Deger 
	DELETE FROM Tb_SipKalem WHERE SpKFisId = @Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 3 AND RnbBaslikId=@Deger
END
ELSE 
BEGIN
	DELETE FROM Tb_SipKalem where SpKId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 3 AND RnbSatirId=@Deger
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spSipKalemKaydet]
@FisId			decimal,
@Tarih			date,
@Saat			nvarchar(5),
@Tipi			tinyint,
@KdvTipi		tinyint,
@OtvTipi		tinyint,
@StokId			decimal,
@Birim			nvarchar(10),
@Miktar			money,
@Fiyat			money,
@Doviz			nvarchar(4),
@DovizTipi		nvarchar(5),
@DovizFiyat		money,
@Kur			money,
@Tutar			money,
@BirimMiktar	money,
@BirimFiyat		money,
@MalyFiyat		money,
@MalyTutar		money,
@OtvTutar		money,
@SMalyTipi		tinyint,
@KdvOran		money,
@OtvOran		money,
@IskOrn1		money,
@IskOrn2		money,
@IskOrn3		money,
@IskOrn4		money,
@IskOrn5		money,
@IskTut1		money,
@IskTut2		money,
@IskTut3		money,
@IskTut4		money,
@IskTut5		money,
@TesTarih1		date,
@TesTarih2		date,
@DepoId			decimal,
@Aciklama		nvarchar(200),
@Kaynak			tinyint,
@KaynakId		decimal,
@Teslim			tinyint,
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_SipKalem(
		SpKFisId,SpkTarih,SpkSaat,SpkStokId,SpkTipi,SpkKdvTipi,SpkOtvTipi,SpkBirim,SpkMiktar,SpkFiyat,SpkDoviz,
		SpkDovizTipi,SpkDovizFiyat,SpkKur,SpkBirimMiktar,SpkBirimFiyat,SpkMalyFiyat,SpkMalyTutar,
		SpkKdvOran,SpkOtvOran,SpkIskOrn1,SpkIskOrn2,SpkIskOrn3,SpkIskOrn4,SpkIskOrn5,SpkIskTut1,SpkIskTut2,SpkIskTut3,
		SpkIskTut4,SpkIskTut5,SpkTutar,SpKTesTar1,SpKTesTar2,SpKTeslim,SpKAciklama,SpKOtvTutar,SpkDepoId,SpKKaynak,SpKKaynakId  
		) VALUES (
		@FisId,@Tarih,@Saat,@StokId,@Tipi,@KdvTipi,@OtvTipi,@Birim,@Miktar,@Fiyat,@Doviz,@DovizTipi,@DovizFiyat,@Kur,
		@BirimMiktar,@BirimFiyat,@MalyFiyat,@MalyTutar,@KdvOran,@OtvOran,@IskOrn1,@IskOrn2,@IskOrn3,
		@IskOrn4,@IskOrn5,@IskTut1,@IskTut2,@IskTut3,@IskTut4,@IskTut5,@Tutar,@TesTarih1,@TesTarih2,@Teslim,
		@Aciklama,@OtvTutar,@DepoId,@Kaynak,@KaynakId)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_SipKalem SET
		SpKFisId=@FisId,SpkTarih=@Tarih,SpkSaat=@Saat,SpkStokId=@StokId,SpkTipi=@Tipi,SpkKdvTipi=@KdvTipi,
		SpkOtvTipi=@OtvTipi,SpkBirim=@Birim,SpkMiktar=@Miktar,SpkFiyat=@Fiyat,SpkDoviz=@Doviz,SpkDovizTipi=@DovizTipi,
		SpkDovizFiyat=@DovizFiyat,SpkKur=@Kur,SpkBirimMiktar=@BirimMiktar,
		SpkBirimFiyat=@BirimFiyat,SpkMalyFiyat=@MalyFiyat,SpkMalyTutar=@MalyTutar,SpkKdvOran=@KdvOran,
		SpkOtvOran=@OtvOran,SpkIskOrn1=@IskOrn1,SpkIskOrn2=@IskOrn2,SpkIskOrn3=@IskOrn3,SpkIskOrn4=@IskOrn4,
		SpkIskOrn5=@IskOrn5,SpkIskTut1=@IskTut1,SpkIskTut2=@IskTut2,SpkIskTut3=@IskTut3,SpkIskTut4=@IskTut4,
		SpkIskTut5=@IskTut5,SpkTutar=@Tutar,SpKTesTar1=@TesTarih1,SpKTesTar2=@TesTarih2,SpKTeslim=@Teslim,
		SpKAciklama=@Aciklama,SpKOtvTutar=@OtvTutar,SpkDepoId=@DepoId WHERE SpKId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spSonnoBul] 
@Alan	nvarchar(100),
@Table  nvarchar(100),
@EkWh	nvarchar(100),
@Boy	smallint,
@OnTk	nvarchar(10)
AS
DECLARE @Sonuc nvarchar(50)
DECLARE @Kalan	nvarchar(50)
DECLARE @KalanI nvarchar(50)
DECLARE @OtBy	smallint
DECLARE @Komut	nvarchar(1000)
DECLARE @myWh	nvarchar(100)
DECLARE @Son	tinyint
BEGIN
	SET @Son=0
	SET @myWh = ''
	Set @OtBy = LEN(@Ontk)
	IF @OnTk = '' BEGIN
		IF @EkWh <> '' Set @myWh = ' Where ' + @EkWh 
		Set @Komut ='Select @Kalan=isnull(max(' + @Alan + '),0) from ' + @Table + @myWh
		EXEC sp_executesql @Komut, N'@Kalan nvarchar(20) Output',@KalanI Output 
		IF ISNUMERIC(@KalanI)= 0 SET @KalanI=1 ELSE SET @KalanI=@KalanI+1
		SET @Kalan = CONVERT(Varchar,@KalanI)
		SET @Son=1
	END
	ELSE
	BEGIN
		IF @EkWh <> '' Set @myWh = ' AND ' + @EkWh 
		Set @Komut ='select @Kalan=isnull(max(' + @Alan + '),0) from ' + @Table + ' where SUBSTRING(' + @Alan + ',1,' + convert(nvarchar,@OtBy)  + ') = ''' + @OnTk + '''' + @myWh 
		EXEC sp_executesql @Komut, N'@Kalan nvarchar(20) Output',@Kalan Output 
		IF @Kalan <> '0'
		BEGIN
			IF ISNUMERIC(SUBSTRING(@Kalan,@OtBy+1,LEN(@Kalan)-@OtBy)) = 1
			BEGIN
				SET @KalanI = SUBSTRING(@Kalan,@OtBy+1,LEN(@Kalan)-@OtBy)
				SET @Kalan = CONVERT(Varchar,@KalanI + 1)
				SET @Son=1
			END
		END
		ELSE
		BEGIN
			SET @Kalan = CONVERT(Varchar,@Kalan + 1)
			SET @Son=1
		END
	END
	IF @Son=1
	BEGIN
		SET @Sonuc=@OnTk + REPLICATE('0',@Boy-LEN(@Kalan)-@OtBy) + @Kalan
		IF @EkWh <> '' Set @myWh = ' AND ' + @EkWh 
		Set @Komut='Select @Kalan=count(*) from ' + @Table + ' Where ' + @Alan + '=''' + @sonuc + '''' + @myWh 
		EXEC sp_executesql @Komut, N'@Kalan nvarchar(20) Output',@Kalan Output 
		IF @Kalan >=1 Set @Sonuc='0'
	END
	ELSE
	BEGIN
		Set @Sonuc='0'
	END
	SELECT isnull(@Sonuc,0)
	
END
GO
CREATE PROCEDURE [dbo].[spStokHarkBaslikKaydet]
@ShbFisTur		tinyint,
@ShbTarih		date,
@ShbSaat		Nvarchar(5),
@ShbFisNo		nvarchar(20),
@ShbEvrakNo		nvarchar(20),
@ShbPersId		decimal,
@ShbOzKod1		nvarchar(20),
@ShbOzKod2		nvarchar(20),
@ShbOzKod3		nvarchar(20),
@ShbKdvTipi		tinyint,
@ShbAciklama	nvarchar(200),
@ShbKullanici	nvarchar(20),
@ShbMagazaKodu	nvarchar(20),
@ShbCariId		decimal,
@ShbTopTutar	money,
@Deger			decimal,
@Yeni			decimal
AS
BEGIN
	if @Yeni = 0
	BEGIN
		INSERT dbo.Tb_StkHarBaslik (
			ShbFisTur,ShbTarih,ShbFisNo,ShbEvrakNo,ShbPersId,ShbOzKod1,ShbOzKod2,ShbOzKod3,ShbSaat,
			ShbKdvTipi,ShbAciklama,ShbMagazaKodu,ShbKayKullanici,ShbCariId,ShbTopTutar,ShbKayitTarihi,ShbKayitSaati
			) VALUES (
			@ShbFisTur,@ShbTarih,@ShbFisNo,@ShbEvrakNo,@ShbPersId,@ShbOzKod1,@ShbOzKod2,@ShbOzKod3,@ShbSaat,
			@ShbKdvTipi,@ShbAciklama,@ShbMagazaKodu,@ShbKullanici,@ShbCariId,@ShbTopTutar,
			CONVERT([date],CONVERT([varchar],getdate(),(112)),(0)),
			substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
			SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE dbo.Tb_StkHarBaslik Set
		ShbFisTur=@ShbFisTur,ShbTarih=@ShbTarih,ShbFisNo=@ShbFisNo,ShbEvrakNo=@ShbEvrakNo,ShbPersId=@ShbPersId,
		ShbOzKod1=@ShbOzKod1,ShbOzKod2=@ShbOzKod2,ShbOzKod3=@ShbOzKod3,ShbKdvTipi=@ShbKdvTipi,ShbSaat=@ShbSaat,
		ShbAciklama=@ShbAciklama,ShbDuzKullanici=@ShbKullanici,ShbCariId=@ShbCariId,ShbTopTutar=@ShbTopTutar,
		ShbDuzeltTarihi=CONVERT([date],CONVERT([varchar],getdate(),(112)),(0)),
		ShbDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		where ShbId=@deger
	END
END
GO
CREATE PROCEDURE [dbo].[spStokHarkKalemKaydet]
@ShkBaslikId	decimal,
@ShkTipi		tinyint,
@ShkBaslikTipi	tinyint,
@Tarih			date,
@ShkSaat		nvarchar(5),
@ShkKdvTipi		tinyint,
@StokId			decimal,
@ShkKdvOran		money,
@ShkBirim		nvarchar(10),
@ShkMiktar		money,
@ShkFiyat		money,
@ShkTutar		money,
@ShkDoviz		nvarchar(4),
@ShkDovizTip	nvarchar(5),
@ShkDovizFiyat	money,
@ShkKur			money,
@ShkDepoId		decimal,
@ShkGirenDepoId	decimal,
@BirimMiktar	money,
@ShkBirimFiyat	money,
@MalyFiyat		money,
@MalyTutar		money,
@SMalyTipi		tinyint,
@ShkPartiId		decimal,
@ShkCariId		decimal,
@Deger			decimal,
@Yeni			decimal
AS

BEGIN
	if @Yeni = 0
	BEGIN
		INSERT dbo.Tb_StkHarKalem (
		ShkBaslikId,ShkTipi,ShkTarih,ShkKdvTipi,ShkBaslikTipi,ShkStokId,ShkBirim,ShkMiktar,ShkFiyat,ShkTutar,ShkKdvOran,
		ShkDoviz,ShkDovizFiyat,ShkKur,ShkDepoId,ShkGirenDepoId,ShkBirimMiktar,ShkBirimFiyat,ShkMalyFiyat,ShkMalyTutar,
		ShkDovizTip,ShkPartiId,ShkSaat,ShkCariId  
		) VALUES (
		@ShkBaslikId,@ShkTipi,@Tarih,@ShkKdvTipi,@ShkBaslikTipi,@StokId,@ShkBirim,@ShkMiktar,@ShkFiyat,@ShkTutar,@ShkKdvOran,
		@ShkDoviz,@ShkDovizFiyat,@ShkKur,@ShkDepoId,@ShkGirenDepoId,@BirimMiktar,@ShkBirimFiyat,@MalyFiyat,@MalyTutar,
		@ShkDovizTip,@ShkPartiId,@ShkSaat,@ShkCariId)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE dbo.Tb_StkHarKalem Set
		ShkTipi=@ShkTipi,ShkTarih=@Tarih,ShkKdvTipi=@ShkKdvTipi,ShkStokId=@StokId,ShkBirim=@ShkBirim,
		ShkMiktar=@ShkMiktar,ShkFiyat=@ShkFiyat,ShkTutar=@ShkTutar,ShkDoviz=@ShkDoviz,ShkDovizFiyat=@ShkDovizFiyat,
		ShkKur=@ShkKur,ShkDepoId=@ShkDepoId,ShkGirenDepoId=@ShkGirenDepoId,ShkBirimMiktar=@BirimMiktar,
		ShkBirimFiyat=@ShkBirimFiyat,ShkKdvOran=@ShkKdvOran,ShkMalyFiyat=@MalyFiyat,ShkMalyTutar=@MalyTutar,
		ShkDovizTip=@ShkDovizTip,ShkPartiId=@ShkPartiId,ShkSaat=@ShkSaat,ShkCariId=@ShkCariId
		where ShkId=@deger
	END
END
GO
CREATE PROCEDURE [dbo].[spStokHarkSil]
@Deger			decimal,
@Type			tinyint
AS
BEGIN TRANSACTION
IF @Type = 0 
BEGIN
	DELETE FROM Tb_StkHarBaslik WHERE ShbId=@Deger 
	DELETE FROM Tb_StkHarKalem WHERE ShkBaslikId = @Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul=0 AND SrnBaslikId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 0 AND RnbBaslikId=@Deger
END
ELSE 
BEGIN
	DELETE FROM Tb_StkHarKalem where ShkId=@Deger 
	DELETE FROM Tb_SeriNo WHERE SrnSatirId=@Deger AND SrnModul = 0
	DELETE FROM Tb_RnBdHareket WHERE RnbSatirId=@Deger AND RnbModul = 0
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spStokKartKaydet]
@StkKod				nvarchar(30),
@StkCins			nvarchar(100),
@StkKisaCins		nvarchar(50),
@StkAnaBirim		nvarchar(10),
@StkAnaDoviz		nvarchar(4),
@StkAnaDovTip		nvarchar(5),
@StkFiyat1			money,
@StkFiyat2			money,
@StkFiyat3			money,
@StkFiyat4			money,
@StkFiyat5			money,
@StkDoviz1			nvarchar(4),
@StkDoviz2			nvarchar(4),
@StkDoviz3			nvarchar(4),
@StkDoviz4			nvarchar(4),
@StkDoviz5			nvarchar(4),
@StkDovTip1			nvarchar(5),
@StkDovTip2			nvarchar(5),
@StkDovTip3			nvarchar(5),
@StkDovTip4			nvarchar(5),
@StkDovTip5			nvarchar(5),
@StkOzelKod1		nvarchar(20),
@StkOzelKod2		nvarchar(20),
@StkOzelKod3		nvarchar(20),
@StkOzelKod4		nvarchar(20),
@StkOzelKod5		nvarchar(20),
@StkAnaKdv			money,
@StkAnaIskonto		money,
@StkNormalSeviye	money,
@StkKritikSeviye	money,
@StkAnaGrup			nvarchar(5),
@StkBarkodTipi		tinyint,
@StkBarkod			nvarchar(50),
@StkAciklama		nvarchar(1000),
@StkUyari			nvarchar(200),
@StkResim			nvarchar(200),
@StkDepId			decimal,
@StkMarId			decimal,
@StkModId			decimal,
@StkKatId			decimal,
@StkKolId			decimal,
@StkRenId			decimal,
@StkBeden			nvarchar(10),
@StkTurId			decimal,
@StkSezId			decimal,
@StkYil				nvarchar(4),
@StkSekId			decimal,
@StkHamId			decimal,
@StkHamTip			tinyint,
@StkReyId			decimal,
@StkCinsiyet		tinyint,
@StkRaf1			nvarchar(20),
@StkRaf2			nvarchar(20),
@StkToptanKdv		money,
@StkPerakKdv		money,
@StkTopAlisIsk		money,
@StkPerAlisIsk		money,
@StkTopSatisIsk		money,
@StkPerSatisIsk		money,
@StkPrimMaxIsk		money,
@StkPrimGun			money,
@StkEn				money,
@StkBoy				money,
@StkYukseklik		money,
@StkAgirlik			money,
@StkOtvTipi			tinyint,
@StkOtvOranTutar	money,
@StkKarOran			money,
@StkFireOran		money,
@StkPrimOran		money,
@StkGaranti			money,
@StkTevkifatOrani	money,
@StkPuanDegeri		money,
@StkRafOmru			money,
@StkUreticiId		decimal,
@StkTedarikciId		decimal,
@StkUreticiTip		tinyint,
@StkUrStokKodu		nvarchar(30),
@StkUrStokCinsi		nvarchar(50),
@StkTanimlar		nvarchar(50),
@StkUrunTipi		nvarchar(50),
@StkAlisFiyTip		tinyint,
@StkSatisFiyTip		tinyint,
@StkUretFiyTip		tinyint,
@StkSiprFiyTip		tinyint,
@StkTekFiyTip		tinyint,
@StkSiparisGun		nvarchar(10),
@StkUrunSorumluId	decimal,
@StkCikisDepoId		decimal,
@StkGirisDepoId		decimal,
@StkAltGrup			nvarchar(5),
@StkSiparisBirim	nvarchar(20),
@StkAciklama1		nvarchar(50),
@StkAciklama2		nvarchar(50),
@StkAciklama3		nvarchar(50),
@StkEkTutar1		money,
@StkEkTutar2		money,
@StkEkTutar3		money,
@StkEkOran1			money,
@StkEkOran2			money,
@StkEkOran3			money,
@StkKullanici		nvarchar(20),
@StkMagazaKodu		nvarchar(20),
@StkBedenSeriId		decimal,
@StkBirim1			nvarchar(10),
@StkBirim2			nvarchar(10),
@StkBirim3			nvarchar(10),
@StkBirim4			nvarchar(10),
@StkBirim5			nvarchar(10),
@StkCarpan1			money,
@StkCarpan2			money,
@StkCarpan3			money,
@StkCarpan4			money,
@StkCarpan5			money,
@StkBolen1			money,
@StkBolen2			money,
@StkBolen3			money,
@StkBolen4			money,
@StkBolen5			money,
@StkEn1				money,
@StkEn2				money,
@StkEn3				money,
@StkEn4				money,
@StkEn5				money,
@StkBoy1			money,
@StkBoy2			money,
@StkBoy3			money,
@StkBoy4			money,
@StkBoy5			money,
@StkYuk1			money,
@StkYuk2			money,
@StkYuk3			money,
@StkYuk4			money,
@StkYuk5			money,
@StkAgr1			money,
@StkAgr2			money,
@StkAgr3			money,
@StkAgr4			money,
@StkAgr5			money,
@StkKdvId			decimal,
@StkPerKdvId		decimal,
@StkTopKdvId		decimal,
@StkTevkId			decimal,
@StkOtvTip			nvarchar(5),
@Deger				decimal,
@Yeni				decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_StokKart(
		StkKod,StkCins,StkKisaCins,StkAnaBirim,StkFiyat1,StkFiyat2,StkFiyat3,StkFiyat4,StkFiyat5,StkDoviz1,
		StkDoviz2,StkDoviz3,StkDoviz4,StkDoviz5,StkOzelKod1,StkOzelKod2,StkOzelKod3,StkOzelKod4,StkOzelKod5,
		StkDovTip1,StkDovTip2,StkDovTip3,StkDovTip4,StkDovTip5,StkAnaDovTip,
		StkAnaKdv,StkAnaIskonto,StkNormalSeviye,StkKritikSeviye,StkAnaGrup,StkBarkodTipi,StkBarkod,
		StkAciklama,StkUyari,StkResim,StkDepId,StkMarId,StkModId,StkKatId,StkKolId,StkRenId,StkBeden,StkTurId,
		StkSezId,StkYil,StkSekId,StkHamId,StkReyId,StkCinsiyet,StkRaf1,StkRaf2,StkToptanKdv,StkPerakKdv,StkTopAlisIsk,
		StkPerAlisIsk,StkTopSatisIsk,StkPerSatisIsk,StkPrimMaxIsk,StkPrimGun,StkEn,StkBoy,StkYukseklik,StkAgirlik,StkOtvTipi,
		StkOtvOranTutar,StkKarOran,StkFireOran,StkPrimOran,StkGaranti,StkTevkifatOrani,StkPuanDegeri,StkRafOmru,StkUreticiId,
		StkTedarikciId,StkUreticiTip,StkUrStokKodu,StkUrStokCinsi,StkTanimlar,StkUrunTipi,StkAlisFiyTip,
		StkSatisFiyTip,StkUretFiyTip,StkSiprFiyTip,StkSiparisGun,StkUrunSorumluId,StkCikisDepoId,StkGirisDepoId,
		StkAltGrup,StkSiparisBirim,StkAciklama1,StkAciklama2,StkAciklama3,StkEkTutar1,StkEkTutar2,StkEkTutar3,StkEkOran1,
		StkEkOran2,StkEkOran3,StkKayKullanici,StkMagazaKodu,StkBedenSeriId,StkKayitSaati,StkBirim1,StkBirim2,
		StkBirim3,StkBirim4,StkBirim5,StkCarpan1,StkCarpan2,StkCarpan3,StkCarpan4,StkCarpan5,StkBolen1,StkBolen2,StkBolen3,
		StkBolen4,StkBolen5,StkEn1,StkEn2,StkEn3,StkEn4,StkEn5,StkBoy1,StkBoy2,StkBoy3,StkBoy4,StkBoy5,StkYuk1,StkYuk2,
		StkYuk3,StkYuk4,StkYuk5,StkAgr1,StkAgr2,StkAgr3,StkAgr4,StkAgr5,StkHamTip,StkKayitTarihi,StkKdvId,StkTopKdvId,
		StkPerKdvId,StkTevkId,StkAnaDoviz,StkOtvTip,StkTekFiyTip     
		) VALUES (
		@StkKod,@StkCins,@StkKisaCins,@StkAnaBirim,@StkFiyat1,@StkFiyat2,@StkFiyat3,@StkFiyat4,@StkFiyat5,
		@StkDoviz1,@StkDoviz2,@StkDoviz3,@StkDoviz4,@StkDoviz5,@StkOzelKod1,@StkOzelKod2,@StkOzelKod3,@StkOzelKod4,@StkOzelKod5,
		@StkDovTip1,@StkDovTip2,@StkDovTip3,@StkDovTip4,@StkDovTip5,@StkAnaDovTip,
		@StkAnaKdv,@StkAnaIskonto,@StkNormalSeviye,@StkKritikSeviye,@StkAnaGrup,@StkBarkodTipi,@StkBarkod,@StkAciklama,@StkUyari,
		@StkResim,@StkDepId,@StkMarId,@StkModId,@StkKatId,@StkKolId,@StkRenId,@StkBeden,@StkTurId,@StkSezId,@StkYil,@StkSekId,
		@StkHamId,@StkReyId,@StkCinsiyet,@StkRaf1,@StkRaf2,@StkToptanKdv,@StkPerakKdv,@StkTopAlisIsk,@StkPerAlisIsk,@StkTopSatisIsk,
		@StkPerSatisIsk,@StkPrimMaxIsk,@StkPrimGun,@StkEn,@StkBoy,@StkYukseklik,@StkAgirlik,@StkOtvTipi,@StkOtvOranTutar,
		@StkKarOran,@StkFireOran,@StkPrimOran,@StkGaranti,@StkTevkifatOrani,@StkPuanDegeri,@StkRafOmru,@StkUreticiId,
		@StkTedarikciId,@StkUreticiTip,@StkUrStokKodu,@StkUrStokCinsi,@StkTanimlar,@StkUrunTipi,@StkAlisFiyTip,
		@StkSatisFiyTip,@StkUretFiyTip,@StkSiprFiyTip,@StkSiparisGun,@StkUrunSorumluId,@StkCikisDepoId,@StkGirisDepoId,
		@StkAltGrup,@StkSiparisBirim,@StkAciklama1,@StkAciklama2,@StkAciklama3,@StkEkTutar1,@StkEkTutar2,@StkEkTutar3,@StkEkOran1,
		@StkEkOran2,@StkEkOran3,@StkKullanici,@StkMagazaKodu,@StkBedenSeriId,substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		@StkBirim1,@StkBirim2,@StkBirim3,@StkBirim4,@StkBirim5,@StkCarpan1,@StkCarpan2,@StkCarpan3,@StkCarpan4,@StkCarpan5,
		@StkBolen1,@StkBolen2,@StkBolen3,@StkBolen4,@StkBolen5,@StkEn1,@StkEn2,@StkEn3,@StkEn4,@StkEn5,@StkBoy1,@StkBoy2,@StkBoy3,
		@StkBoy4,@StkBoy5,@StkYuk1,@StkYuk2,@StkYuk3,@StkYuk4,@StkYuk5,@StkAgr1,@StkAgr2,@StkAgr3,@StkAgr4,@StkAgr5,@StkHamTip,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),@StkKdvId,@StkTopKdvId,@StkPerKdvId,@StkTevkId,@StkAnaDoviz,@StkOtvTip,
		@StkTekFiyTip
		)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_StokKart SET
		StkKod=@StkKod,StkCins=@StkCins,StkKisaCins=@StkKisaCins,StkAnaBirim=@StkAnaBirim,
		StkFiyat1=@StkFiyat1,StkFiyat2=@StkFiyat2,StkFiyat3=@StkFiyat3,StkFiyat4=@StkFiyat4,StkFiyat5=@StkFiyat5,
		StkDoviz1=@StkDoviz1,StkDoviz2=@StkDoviz2,StkDoviz3=@StkDoviz3,StkDoviz4=@StkDoviz4,StkDoviz5=@StkDoviz5,
		StkDovTip1=@StkDovTip1,StkDovTip2=@StkDovTip2,StkDovTip3=@StkDovTip3,StkDovTip4=@StkDovTip4,StkDovTip5=@StkDovTip5,StkAnaDovTip=@StkAnaDovTip,
		StkOzelKod1=@StkOzelKod1,StkOzelKod2=@StkOzelKod2,StkOzelKod3=@StkOzelKod3,StkOzelKod4=@StkOzelKod4,
		StkOzelKod5=@StkOzelKod5,StkAnaKdv=@StkAnaKdv,StkAnaIskonto=@StkAnaIskonto,StkNormalSeviye=@StkNormalSeviye,
		StkKritikSeviye=@StkKritikSeviye,StkAnaGrup=@StkAnaGrup,StkBarkodTipi=@StkBarkodTipi,
		StkBarkod=@StkBarkod,StkAciklama=@StkAciklama,StkUyari=@StkUyari,StkResim=@StkResim,StkDepId=@StkDepId,
		StkMarId=@StkMarId,StkModId=@StkModId,StkKatId=@StkKatId,StkKolId=@StkKolId,StkRenId=@StkRenId,StkBeden=@StkBeden,
		StkTurId=@StkTurId,StkSezId=@StkSezId,StkYil=@StkYil,StkSekId=@StkSekId,StkHamId=@StkHamId,
		StkReyId=@StkReyId,StkCinsiyet=@StkCinsiyet,StkRaf1=@StkRaf1,StkRaf2=@StkRaf2,StkToptanKdv=@StkToptanKdv,
		StkPerakKdv=@StkPerakKdv,StkTopAlisIsk=@StkTopAlisIsk,StkPerAlisIsk=@StkPerAlisIsk,StkTopSatisIsk=@StkTopSatisIsk,
		StkPerSatisIsk=@StkPerSatisIsk,StkPrimMaxIsk=@StkPrimMaxIsk,StkPrimGun=@StkPrimGun,StkEn=@StkEn,StkBoy=@StkBoy,
		StkYukseklik=@StkYukseklik,StkAgirlik=@StkAgirlik,StkOtvTipi=@StkOtvTipi,StkOtvOranTutar=@StkOtvOranTutar,
		StkKarOran=@StkKarOran,StkFireOran=@StkFireOran,StkPrimOran=@StkPrimOran,StkGaranti=@StkGaranti,
		StkTevkifatOrani=@StkTevkifatOrani,StkPuanDegeri=@StkPuanDegeri,StkRafOmru=@StkRafOmru,StkUreticiId=@StkUreticiId,
		StkTedarikciId=@StkTedarikciId,StkUreticiTip=@StkUreticiTip,StkUrStokKodu=@StkUrStokKodu,
		StkUrStokCinsi=@StkUrStokCinsi,StkTanimlar=@StkTanimlar,StkUrunTipi=@StkUrunTipi,StkAlisFiyTip=@StkAlisFiyTip,
		StkSatisFiyTip=@StkSatisFiyTip,StkUretFiyTip=@StkUretFiyTip,StkSiprFiyTip=@StkSiprFiyTip,
		StkSiparisGun=@StkSiparisGun,StkUrunSorumluId=@StkUrunSorumluId,StkCikisDepoId=@StkCikisDepoId,StkGirisDepoId=@StkGirisDepoId,
		StkAltGrup=@StkAltGrup,StkSiparisBirim=@StkSiparisBirim,StkAciklama1=@StkAciklama1,StkAciklama2=@StkAciklama2,
		StkAciklama3=@StkAciklama3,StkEkTutar1=@StkEkTutar1,StkEkTutar2=@StkEkTutar2,StkEkTutar3=@StkEkTutar3,StkEkOran1=@StkEkOran1,
		StkEkOran2=@StkEkOran2,StkEkOran3=@StkEkOran3,StkDuzKullanici=@StkKullanici,StkBedenSeriId=@StkBedenSeriId,
		StkDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),StkOtvTip=@StkOtvTip,
		StkBirim1=@StkBirim1,StkBirim2=@StkBirim2,StkBirim3=@StkBirim3,StkBirim4=@StkBirim4,StkTekFiyTip= @StkTekFiyTip,
		StkBirim5=@StkBirim5,StkCarpan1=@StkCarpan1,StkCarpan2=@StkCarpan2,StkCarpan3=@StkCarpan3,StkCarpan4=@StkCarpan4,
		StkCarpan5=@StkCarpan5,StkBolen1=@StkBolen1,StkBolen2=@StkBolen2,StkBolen3=@StkBolen3,StkBolen4=@StkBolen4,
		StkBolen5=@StkBolen5,StkEn1=@StkEn1,StkEn2=@StkEn2,StkEn3=@StkEn3,StkEn4=@StkEn4,StkEn5=@StkEn5,StkBoy1=@StkBoy1,
		StkBoy2=@StkBoy2,StkBoy3=@StkBoy3,StkBoy4=@StkBoy4,StkBoy5=@StkBoy5,StkYuk1=@StkYuk1,StkYuk2=@StkYuk2,
		StkYuk3=@StkYuk3,StkYuk4=@StkYuk4,StkYuk5=@StkYuk5,StkAgr1=@StkAgr1,StkAgr2=@StkAgr2,StkAgr3=@StkAgr3,
		StkAgr4=@StkAgr4,StkAgr5=@StkAgr5,StkHamTip=@StkHamTip,StkDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		StkKdvId=@StkKdvId,StkTopKdvId=@StkTopKdvId,StkPerKdvId=@StkPerKdvId,StkTevkId=@StkTevkId,StkAnaDoviz=@StkAnaDoviz
		WHERE StkId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spStokKartSil]
@StkId			decimal
AS
BEGIN
	BEGIN TRANSACTION
	DELETE Tb_StokKart WHERE StkId = @StkId 
	DELETE Tb_fiyat WHERE FiyStokId = @StkId 
	DELETE Tb_Barkod WHERE BarStokId=@StkId
	DELETE Tb_StokRbSeri WHERE SrbStokId=@StkId
	IF @@ERROR <> 0
	BEGIN
		
		ROLLBACK TRANSACTION 	
		
		SELECT 1 
	
	END
	
	ELSE
	
	BEGIN
		
		COMMIT TRANSACTION
		
		SELECT 0
	END
END
GO
CREATE PROCEDURE [dbo].[spStokMaliyet]
@StkId		Decimal,
@Tarih		Date,
@Miktar		Money,
@Tipi		Tinyint
AS
IF @Tipi = 1 SELECT MalyFiyat FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi=0 AND Tarih <= @Tarih AND ViewTipi <> 2 ORDER BY Tarih DESC
IF @Tipi = 2 SELECT MalyFiyat FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi=1 AND Tarih <= @Tarih AND ViewTipi <> 2 ORDER BY Tarih DESC

DECLARE @TopTut MONEY
DECLARE @TopMik MONEY

IF @Tipi = 3 
BEGIN
	SELECT @TopTut=SUM(MalyTutar),@TopMik=SUM(BirimMiktar) FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi=0 AND Tarih <= @Tarih
	IF @TopTut > 0 AND @TopMik > 0 SELECT @TopTut / @TopMik ELSE SELECT 0  
END
IF @Tipi = 4
BEGIN
	SELECT @TopTut=SUM(MalyTutar),@TopMik=SUM(BirimMiktar) FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi=1
	IF @TopTut > 0 AND @TopMik > 0 SELECT @TopTut / @TopMik ELSE SELECT 0  
END
IF @Tipi = 6 SELECT TOP 1 MalyFiyat FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi = 0 AND ViewTipi <> 2 ORDER BY MalyFiyat ASC
IF @Tipi = 7 SELECT TOP 1 MalyFiyat FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi = 1 AND ViewTipi <> 2 ORDER BY MalyFiyat ASC
IF @Tipi = 8 SELECT TOP 1 MalyFiyat FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi = 0 AND ViewTipi <> 2 ORDER BY MalyFiyat DESC
IF @Tipi = 9 SELECT TOP 1 MalyFiyat FROM vw_StokHareketler WHERE StokId = @StkId AND Tipi = 1 AND ViewTipi <> 2 ORDER BY MalyFiyat DESC

IF @Tipi = 5
BEGIN
	DECLARE @HrMik MONEY
	DECLARE @HrMal MONEY
	DECLARE @GrCk SMALLINT
	DECLARE @YaoFiy MONEY
	
	SET @TopMik = 0
	SET @TopTut = 0
	SET @YaoFiy = 0
	
	DECLARE Deneme CURSOR FOR SELECT Miktar,MalyTutar,GirCik FROM vw_StokHareketler WHERE StokId = @StkId AND Tarih <= @Tarih AND ViewTipi <> 2 ORDER BY Tarih 
	OPEN Deneme
	FETCH NEXT FROM Deneme INTO @HrMik,@HrMal,@GrCk
	WHILE @@FETCH_STATUS=0
	BEGIN
		IF @GrCk = 0 
		BEGIN
			SET @Toptut = @Toptut + @HrMal	
			SET @TopMik = @TopMik + @HrMik
			IF @TopTut > 0 AND @TopMik > 0 SET @YaoFiy = @TopTut / @TopMik
		END
		ELSE
		BEGIN
			SET @Toptut = @Toptut - (@YaoFiy * @HrMik)	
			SET @TopMik = @TopMik - @HrMik
		END
		FETCH NEXT FROM Deneme INTO @HrMik,@HrMal,@GrCk
	END
	CLOSE Deneme
	DEALLOCATE Deneme	
	SELECT @YaoFiy 
END	
GO
CREATE PROCEDURE [dbo].[spSubeKartKaydet]
@SubKod			nvarchar(30),
@SubAd			nvarchar(100),
@SubMusteriNo	nvarchar(20),
@SubTelf1		nvarchar(20),
@SubTelf2		nvarchar(20),
@SubTelf3		nvarchar(20),
@SubTelf4		nvarchar(20),
@SubTelf5		nvarchar(20),
@SubOzelKod1	nvarchar(20),
@SubOzelKod2	nvarchar(20),
@SubOzelKod3	nvarchar(20),
@SubOzelKod4	nvarchar(20),
@SubOzelKod5	nvarchar(20),
@SubAnaGrup		nvarchar(5),
@SubAdres		nvarchar(100),
@SubSemt		nvarchar(20),
@SubIlce		nvarchar(20),
@SubIl			nvarchar(20),
@SubUlke		nvarchar(20),
@SubPostaKodu	nvarchar(10),
@SubAciklama	nvarchar(1000),
@SubUyari		nvarchar(200),
@SubBankaId		decimal,
@SubSubeId		decimal,
@SubSorumId		decimal,
@SubWebAdr		nvarchar(200),
@SubAltGrup		nvarchar(5),
@SubAciklama1	nvarchar(50),
@SubAciklama2	nvarchar(50),
@SubAciklama3	nvarchar(50),
@SubEkTutar1	money,
@SubEkTutar2	money,
@SubEkTutar3	money,
@SubEkOran1		money,
@SubEkOran2		money,
@SubEkOran3		money,
@SubKullanici	nvarchar(20),
@SubMagazaKodu	nvarchar(50),
@SubIlceId		decimal,
@SubIlId		decimal,
@SubUlkeId		decimal,
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_SubeKart(
		SubKod,SubAd,SubMusteriNo,SubOzelKod1,SubOzelKod2,SubOzelKod3,SubOzelKod4,SubOzelKod5,SubSubeId,SubWebAdres,SubAnaGrup,
		SubAdres,SubSemt,SubIlce,SubIl,SubUlke,SubPostaKodu,SubAciklama,SubUyari,SubBankaId,SubSorumId,SubWebAdr,SubAltGrup,
		SubAciklama1,SubAciklama2,SubAciklama3,SubEkTutar1,SubEkTutar2,SubEkTutar3,SubEkOran1,SubEkOran2,SubEkOran3,
		SubMagazaKodu,SubIlceId,SubIlId,SubUlkeId,SubKayKullanici,SubTelf1,SubTelf2,SubTelf3,SubTelf4,SubTelf5,SubKayitTarihi,SubKayitSaati
		) VALUES (
		@SubKod,@SubAd,@SubMusteriNo,@SubOzelKod1,@SubOzelKod2,@SubOzelKod3,@SubOzelKod4,@SubOzelKod5,@SubSubeId,@SubWebAdr,  
		@SubAnaGrup,@SubAdres,@SubSemt,@SubIlce,@SubIl,@SubUlke,@SubPostaKodu,@SubAciklama,@SubUyari,@SubBankaId,@SubSorumId,
		@SubWebAdr,@SubAltGrup,@SubAciklama1,@SubAciklama2,@SubAciklama3,@SubEkTutar1,@SubEkTutar2,@SubEkTutar3,@SubEkOran1,
		@SubEkOran2,@SubEkOran3,@SubMagazaKodu,@SubIlceId,@SubIlId,@SubUlkeId,@SubKullanici,@SubTelf1,@SubTelf2,@SubTelf3,
		@SubTelf4,@SubTelf5,(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_SubeKart SET
		SubKod=@SubKod,	SubAd=@SubAd,SubMusteriNo=@SubMusteriNo,SubOzelKod1=@SubOzelKod1,SubSubeId=@SubSubeId, 
		SubOzelKod2=@SubOzelKod2,SubOzelKod3=@SubOzelKod3,SubOzelKod4=@SubOzelKod4,SubOzelKod5=@SubOzelKod5,
		SubAnaGrup=@SubAnaGrup,SubAdres=@SubAdres,SubSemt=@SubSemt,SubIlce=@SubIlce,SubIl=@SubIl,SubUlke=@SubUlke,
		SubPostaKodu=@SubPostaKodu,SubAciklama=@SubAciklama,SubUyari=@SubUyari,SubBankaId=@SubBankaId,SubSorumId=@SubSorumId,
		SubWebAdr=@SubWebAdr,SubAltGrup=@SubAltGrup,SubAciklama1=@SubAciklama1,SubAciklama2=@SubAciklama2,
		SubAciklama3=@SubAciklama3,SubEkTutar1=@SubEkTutar1,SubEkTutar2=@SubEkTutar2,SubEkTutar3=@SubEkTutar3,
		SubEkOran1=@SubEkOran1,SubEkOran2=@SubEkOran2,SubEkOran3=@SubEkOran3,SubMagazaKodu=@SubMagazaKodu,
		SubIlceId=@SubIlceId,SubIlId=@SubIlId,SubUlkeId=@SubUlkeId,SubTelf1=@SubTelf1,SubTelf2=@SubTelf2,
		SubTelf3=@SubTelf3,SubTelf4=@SubTelf4,SubTelf5=@SubTelf5,
		SubDuzKullanici=@SubKullanici,SubDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		SubWebAdres=@SubWebAdr, SubDuzeltSaati=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5)
		WHERE SubId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spTekKalemKaydet]
@FisId			decimal,
@Tarih			date,
@Saat			nvarchar(5),
@Tipi			tinyint,
@KdvTipi		tinyint,
@OtvTipi		tinyint,
@SatirTipi		tinyint,
@StokId			decimal,
@Birim			nvarchar(10),
@Miktar			money,
@Fiyat			money,
@Doviz			nvarchar(4),
@DovizTipi		nvarchar(5),
@DovizFiyat		money,
@Kur			money,
@Tutar			money,
@BirimMiktar	money,
@BirimFiyat		money,
@MalyFiyat		money,
@MalyTutar		money,
@OtvTutar		money,
@SMalyTipi		tinyint,
@KdvOran		money,
@OtvOran		money,
@IskOrn1		money,
@IskOrn2		money,
@IskOrn3		money,
@IskOrn4		money,
@IskOrn5		money,
@IskTut1		money,
@IskTut2		money,
@IskTut3		money,
@IskTut4		money,
@IskTut5		money,
@Aciklama		nvarchar(100),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_TekKalem(
		TkKFisId,TkKTarih,TkKSaat,TkKStokId,TkKTipi,TkKKdvTipi,TkKOtvTipi,TkKBirim,TkKMiktar,TkKFiyat,TkKDoviz,
		TkKDovizTipi,TkKDovizFiyat,TkKKur,TkKBirimMiktar,TkKBirimFiyat,TkKMalyFiyat,TkKMalyTutar,
		TkKKdvOran,TkKOtvOran,TkKIskOrn1,TkKIskOrn2,TkKIskOrn3,TkKIskOrn4,TkKIskOrn5,TkKIskTut1,TkKIskTut2,TkKIskTut3,
		TkKIskTut4,TkKIskTut5,TkKTutar,TkKSatirTipi,TkKAciklama,TkKOtvTutar   
		) VALUES (
		@FisId,@Tarih,@Saat,@StokId,@Tipi,@KdvTipi,@OtvTipi,@Birim,@Miktar,@Fiyat,@Doviz,@DovizTipi,@DovizFiyat,@Kur,
		@BirimMiktar,@BirimFiyat,@MalyFiyat,@MalyTutar,@KdvOran,@OtvOran,@IskOrn1,@IskOrn2,@IskOrn3,
		@IskOrn4,@IskOrn5,@IskTut1,@IskTut2,@IskTut3,@IskTut4,@IskTut5,@Tutar,@SatirTipi,@Aciklama,@OtvTutar)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_TekKalem SET
		TkKFisId=@FisId,TkKTarih=@Tarih,TkKSaat=@Saat,TkKStokId=@StokId,TkKTipi=@Tipi,TkKKdvTipi=@KdvTipi,
		TkKOtvTipi=@OtvTipi,TkKBirim=@Birim,TkKMiktar=@Miktar,TkKFiyat=@Fiyat,TkKDoviz=@Doviz,TkKDovizTipi=@DovizTipi,
		TkKDovizFiyat=@DovizFiyat,TkKKur=@Kur,TkKBirimMiktar=@BirimMiktar,TkKBirimFiyat=@BirimFiyat,
		TkKMalyFiyat=@MalyFiyat,TkKMalyTutar=@MalyTutar,TkKKdvOran=@KdvOran,TkKOtvOran=@OtvOran,TkKIskOrn1=@IskOrn1,
		TkKIskOrn2=@IskOrn2,TkKIskOrn3=@IskOrn3,TkKIskOrn4=@IskOrn4,TkKIskOrn5=@IskOrn5,TkKIskTut1=@IskTut1,
		TkKIskTut2=@IskTut2,TkKIskTut3=@IskTut3,TkKIskTut4=@IskTut4,TkKIskTut5=@IskTut5,TkKTutar=@Tutar,
		TkKSatirTipi=@SatirTipi,TkKAciklama=@Aciklama,TkKOtvTutar=@OtvTutar WHERE TkKId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spTeklifKaydet]
@Tur			tinyint,
@Tarih			date,
@Saat			nvarchar(5),
@Vade			date,
@No				nvarchar(20),
@CariId			decimal,
@PersId			decimal,
@DepoId			decimal,
@KdvTip			tinyint,
@MsMerkId		decimal,
@OtvTip			tinyint,
@Tip			tinyint,
@OzelKod1		nvarchar(20),
@OzelKod2		nvarchar(20),
@OzelKod3		nvarchar(20),
@Aciklama		nvarchar(200),
@AdresTip		tinyint,
@IskTutar1		money,
@IskTutar2		money,
@IskTutar3		money,
@IskTutar4		money,
@IskTutar5		money,
@IskOran1		money,
@IskOran2		money,
@IskOran3		money,
@IskOran4		money,
@IskOran5		money,
@IskDvTip1		nvarchar(5),
@IskDvTip2		nvarchar(5),
@IskDvTip3		nvarchar(5),
@IskDvTip4		nvarchar(5),
@IskDvTip5		nvarchar(5),
@IskDov1		nvarchar(5),
@IskDov2		nvarchar(5),
@IskDov3		nvarchar(5),
@IskDov4		nvarchar(5),
@IskDov5		nvarchar(5),
@IskDvTut1		money,
@IskDvTut2		money,
@IskDvTut3		money,
@IskDvTut4		money,
@IskDvTut5		money,
@IskKur1		money,
@IskKur2		money,
@IskKur3		money,
@IskKur4		money,
@IskKur5		money,
@MasTutar1		money,
@MasTutar2		money,
@MasTutar3		money,
@MasTutar4		money,
@MasTutar5		money,
@MasOran1		money,
@MasOran2		money,
@MasOran3		money,
@MasOran4		money,
@MasOran5		money,
@MasDvTip1		nvarchar(5),
@MasDvTip2		nvarchar(5),
@MasDvTip3		nvarchar(5),
@MasDvTip4		nvarchar(5),
@MasDvTip5		nvarchar(5),
@MasDov1		nvarchar(5),
@MasDov2		nvarchar(5),
@MasDov3		nvarchar(5),
@MasDov4		nvarchar(5),
@MasDov5		nvarchar(5),
@MasDvTut1		money,
@MasDvTut2		money,
@MasDvTut3		money,
@MasDvTut4		money,
@MasDvTut5		money,
@MasKur1		money,
@MasKur2		money,
@MasKur3		money,
@MasKur4		money,
@MasKur5		money,
@KdvAlIn1		money,
@KdvAlIn2		money,
@KdvAlEk1		money,
@KdvAlEk2		money,
@TevkOran		money,
@KdvOran		money,
@MalToplam		money,
@KalIsk			money,
@GenIsk			money,
@TopIsk			money,
@TopMas			money,
@AraTop			money,
@OtvTop			money,
@KdvMat			money,
@KdvTut			money,
@BrtTop			money,
@KdvAIn			money,
@KdvAEk			money,
@GenTop			money,
@VerTop			money,
@TevTut			money,
@OdnVer			money,
@EkVerTut		money,
@Kullanici		nvarchar(20),
@MagazaKodu		nvarchar(20),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_Teklif(
		TekTur,TekTarih,TekSaat,TekNo,TekCariId,TekPersId,TekKdvTip,TekMsMerkId,TekOtvTip,TekOzelKod1,TekOzelKod2,
		TekOzelKod3,TekAciklama,TekAdresTip,TekIskTutar1,TekIskTutar2,TekIskTutar3,TekIskTutar4,TekIskTutar5,
		TekIskOran1,TekIskOran2,TekIskOran3,TekIskOran4,TekIskOran5,TekIskDvTip1,TekIskDvTip2,TekIskDvTip3,
		TekIskDvTip4,TekIskDvTip5,TekIskDov1,TekIskDov2,TekIskDov3,TekIskDov4,TekIskDov5,TekIskDvTut1,
		TekIskDvTut2,TekIskDvTut3,TekIskDvTut4,TekIskDvTut5,TekIskKur1,TekIskKur2,TekIskKur3,TekIskKur4,TekIskKur5,
		TekMasTutar1,TekMasTutar2,TekMasTutar3,TekMasTutar4,TekMasTutar5,TekMasOran1,TekMasOran2,TekMasOran3,
		TekMasOran4,TekMasOran5,TekMasDvTip1,TekMasDvTip2,TekMasDvTip3,TekMasDvTip4,TekMasDvTip5,TekMasDov1,
		TekMasDov2,TekMasDov3,TekMasDov4,TekMasDov5,TekMasDvTut1,TekMasDvTut2,TekMasDvTut3,TekMasDvTut4,
		TekMasDvTut5,TekMasKur1,TekMasKur2,TekMasKur3,TekMasKur4,TekMasKur5,TekKdvAlIn1,TekKdvAlIn2,TekKdvAlEk1,
		TekKdvAlEk2,TekTevkOran,TekKdvOran,TekMalToplam,TekKalIsk,TekGenIsk,TekTopIsk,TekTopMas,TekAraTop,TekOtvTop,	
		TekKdvMat,TekKdvTut,TekBrtTop,TekKdvAIn,TekKdvAEk,TekGenTop,TekVerTop,TekTevTut,TekOdnVer,TekKayKullanici,
		TekMagazaKodu,TekVade,TekTip,TekDepoId,TekEkVerTut,TekKayTarihi,TekKaySaati
		) VALUES (
		@Tur,@Tarih,@Saat,@No,@CariId,@PersId,@KdvTip,@MsMerkId,@OtvTip,@OzelKod1,@OzelKod2,@OzelKod3,@Aciklama,
		@AdresTip,@IskTutar1,@IskTutar2,@IskTutar3,@IskTutar4,@IskTutar5,@IskOran1,@IskOran2,@IskOran3,@IskOran4,
		@IskOran5,@IskDvTip1,@IskDvTip2,@IskDvTip3,@IskDvTip4,@IskDvTip5,@IskDov1,@IskDov2,@IskDov3,@IskDov4,@IskDov5,
		@IskDvTut1,@IskDvTut2,@IskDvTut3,@IskDvTut4,@IskDvTut5,@IskKur1,@IskKur2,@IskKur3,@IskKur4,@IskKur5,
		@MasTutar1,@MasTutar2,@MasTutar3,@MasTutar4,@MasTutar5,@MasOran1,@MasOran2,@MasOran3,@MasOran4,@MasOran5,
		@MasDvTip1,@MasDvTip2,@MasDvTip3,@MasDvTip4,@MasDvTip5,@MasDov1,@MasDov2,@MasDov3,@MasDov4,@MasDov5,
		@MasDvTut1,@MasDvTut2,@MasDvTut3,@MasDvTut4,@MasDvTut5,@MasKur1,@MasKur2,@MasKur3,@MasKur4,@MasKur5,@KdvAlIn1,
		@KdvAlIn2,@KdvAlEk1,@KdvAlEk2,@TevkOran,@KdvOran,@MalToplam,@KalIsk,@GenIsk,@TopIsk,@TopMas,@AraTop,@OtvTop,
		@KdvMat,@KdvTut,@BrtTop,@KdvAIn,@KdvAEk,@GenTop,@VerTop,@TevTut,@OdnVer,@Kullanici,@MagazaKodu,@Vade,@Tip, @DepoId, @EkVerTut,
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_Teklif SET
		TekTur=@Tur,TekTarih=@Tarih,TekSaat=@Saat,TekNo=@No,TekCariId=@CariId,TekPersId=@PersId,
		TekKdvTip=@KdvTip,TekMsMerkId=@MsMerkId,TekOtvTip=@OtvTip,TekOzelKod1=@OzelKod1,TekOzelKod2=@OzelKod2,
		TekOzelKod3=@OzelKod3,TekAciklama=@Aciklama,TekAdresTip=@AdresTip,TekIskTutar1=@IskTutar1,
		TekIskTutar2=@IskTutar2,TekIskTutar3=@IskTutar3,TekIskTutar4=@IskTutar4,TekIskTutar5=@IskTutar5,
		TekIskOran1=@IskOran1,TekIskOran2=@IskOran2,TekIskOran3=@IskOran3,TekIskOran4=@IskOran4,
		TekIskOran5=@IskOran5,TekIskDvTip1=@IskDvTip1,TekIskDvTip2=@IskDvTip2,TekIskDvTip3=@IskDvTip3,
		TekIskDvTip4=@IskDvTip4,TekIskDvTip5=@IskDvTip5,TekIskDov1=@IskDov1,TekIskDov2=@IskDov2,
		TekIskDov3=@IskDov3,TekIskDov4=@IskDov4,TekIskDov5=@IskDov5,TekIskDvTut1=@IskDvTut1,
		TekIskDvTut2=@IskDvTut2,TekIskDvTut3=@IskDvTut3,TekIskDvTut4=@IskDvTut4,TekIskDvTut5=@IskDvTut5,
		TekIskKur1=@IskKur1,TekIskKur2=@IskKur2,TekIskKur3=@IskKur3,TekIskKur4=@IskKur4,
		TekIskKur5=@IskKur5,TekMasTutar1=@MasTutar1,TekMasTutar2=@MasTutar2,TekMasTutar3=@MasTutar3,
		TekMasTutar4=@MasTutar4,TekMasTutar5=@MasTutar5,TekMasOran1=@MasOran1,TekMasOran2=@MasOran2,
		TekMasOran3=@MasOran3,TekMasOran4=@MasOran4,TekMasOran5=@MasOran5,TekMasDvTip1=@MasDvTip1,
		TekMasDvTip2=@MasDvTip2,TekMasDvTip3=@MasDvTip3,TekMasDvTip4=@MasDvTip4,TekMasDvTip5=@MasDvTip5,
		TekMasDov1=@MasDov1,TekMasDov2=@MasDov2,TekMasDov3=@MasDov3,TekMasDov4=@MasDov4,
		TekMasDov5=@MasDov5,TekMasDvTut1=@MasDvTut1,TekMasDvTut2=@MasDvTut2,TekMasDvTut3=@MasDvTut3,
		TekMasDvTut4=@MasDvTut4,TekMasDvTut5=@MasDvTut5,TekMasKur1=@MasKur1,TekMasKur2=@MasKur2,
		TekMasKur3=@MasKur3,TekMasKur4=@MasKur4,TekMasKur5=@MasKur5,TekKdvAlIn1=@KdvAlIn1,
		TekKdvAlIn2=@KdvAlIn2,TekKdvAlEk1=@KdvAlEk1,TekKdvAlEk2=@KdvAlEk2,TekTevkOran=@TevkOran,
		TekKdvOran=@KdvOran,TekMalToplam=@MalToplam,TekKalIsk=@KalIsk,TekGenIsk=@GenIsk,
		TekTopIsk=@TopIsk,TekTopMas=@TopMas,TekAraTop=@AraTop,TekOtvTop=@OtvTop,TekKdvMat=@KdvMat,
		TekKdvTut=@KdvTut,TekBrtTop=@BrtTop,TekKdvAIn=@KdvAIn,TekKdvAEk=@KdvAEk,TekGenTop=@GenTop,
		TekVerTop=@VerTop,TekTevTut=@TevTut,TekOdnVer=@OdnVer,TekDuzKullanici=@Kullanici,
		TekVade=@Vade,TekTip=@Tip,TekDepoId=@DepoId,TekEkVerTut=@EkVerTut,
		TekDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		TekDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		TekMagazaKodu=@MagazaKodu WHERE TekId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spTeklifSil]
@Deger			decimal,
@Type			tinyint

AS
BEGIN TRANSACTION
IF @Type = 0 
BEGIN
	DELETE FROM Tb_Teklif WHERE TekId=@Deger 
	DELETE FROM Tb_TekKalem WHERE TkKFisId = @Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 4 AND RnbBaslikId=@Deger
END
ELSE 
BEGIN
	DELETE FROM Tb_TekKalem where TkKId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 4 AND RnbSatirId=@Deger
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO
CREATE PROCEDURE [dbo].[spYzKsSatisKalemKaydet]
@FisId			decimal,
@Tarih			date,
@Saat			nvarchar(5),
@StokId			decimal,
@Birim			nvarchar(10),
@Miktar			money,
@Fiyat			money,
@Tutar			money,
@DepoId			decimal,
@PartiId		decimal,
@BirimMiktar	money,
@BirimFiyat		money,
@MalyFiyat		money,
@MalyTutar		money,
@KdvTutar		money,
@KdvMatrah		money,
@SMalyTipi		tinyint,
@KdvOran		money,
@Aciklama		nvarchar(200),
@Deger			Decimal,
@Yeni			Decimal
AS

BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_YzKKalem(
		YkKFisId,YkKTarih,YkKSaat,YkKStokId,YkKBirim,YkKMiktar,YkKFiyat, YkKDepoId,YkKPartiId,YkKBirimMiktar,
		YkKBirimFiyat,YkKMalyFiyat,YkKMalyTutar,YkKKdvOran,YkKTutar,YkKAciklama,YkKKdvTutar,YkKKdvMatrah
		) VALUES (
		@FisId,@Tarih,@Saat,@StokId,@Birim,@Miktar,@Fiyat,@DepoId,@PartiId,@BirimMiktar,@BirimFiyat,@MalyFiyat,
		@MalyTutar,@KdvOran,@Tutar,@Aciklama,@KdvTutar,@KdvMatrah)
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_YzKKalem SET
		YkKFisId=@FisId,YkKTarih=@Tarih,YkKSaat=@Saat,YkKStokId=@StokId,YkKBirim=@Birim,YkKMiktar=@Miktar,YkKFiyat=@Fiyat,
		YkKDepoId=@DepoId,YkKPartiId=@PartiId,YkKBirimMiktar=@BirimMiktar,YkKBirimFiyat=@BirimFiyat,YkKMalyFiyat=@MalyFiyat,
		YkKMalyTutar=@MalyTutar,YkKKdvOran=@KdvOran,YkKTutar=@Tutar,YkKAciklama=@Aciklama,YkKKdvTutar=@KdvTutar,
		YkKKdvMatrah=@KdvMatrah
		WHERE YkKId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[spYzKsSatisKaydet]
@Tarih			date,
@Saat			nvarchar(5),
@No				nvarchar(20),
@CariId			decimal,
@PersId			decimal,
@MsMerkId		decimal,
@OzelKod1		nvarchar(20),
@OzelKod2		nvarchar(20),
@OzelKod3		nvarchar(20),
@Aciklama		nvarchar(200),
@MalToplam		money,
@KdvMat			money,
@KdvTut			money,
@GenTop			money,
@Kullanici		nvarchar(20),
@MagazaKodu		nvarchar(20),
@Deger			Decimal,
@Yeni			Decimal
AS
BEGIN
if @Yeni = 0
	BEGIN
	INSERT Tb_YzKsSatis(
		YzKTarih,YzKSaat,YzKNo,YzKCariId,YzKPersId,YzKMsMerkId,YzKOzelKod1,YzKOzelKod2,YzKOzelKod3,YzKAciklama,
		YzKMalToplam,YzKKdvMat,YzKKdvTut,YzKGenTop,YzKKayKullanici,YzKMagazaKodu,YzKKayTarihi,YzKKaySaati
		) VALUES (
		@Tarih,@Saat,@No,@CariId,@PersId,@MsMerkId,@OzelKod1,@OzelKod2,@OzelKod3,@Aciklama,@MalToplam,
		@KdvMat,@KdvTut,@GenTop,@Kullanici,@MagazaKodu,  
		(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),substring(CONVERT([varchar],CONVERT([time],getdate())),1,5))
		SELECT @@Identity
	END
	ELSE
	BEGIN
		UPDATE Tb_YzKsSatis SET
		YzKTarih=@Tarih,YzKSaat=@Saat,YzKNo=@No,YzKCariId=@CariId,YzKPersId=@PersId,
		YzKMsMerkId=@MsMerkId,YzKOzelKod1=@OzelKod1,YzKOzelKod2=@OzelKod2,
		YzKOzelKod3=@OzelKod3,YzKAciklama=@Aciklama,YzKMalToplam=@MalToplam,
		YzKKdvMat=@KdvMat,YzKKdvTut=@KdvTut,YzKGenTop=@GenTop,YzKDuzKullanici=@Kullanici,
		YzKDuzeltTarihi=(CONVERT([date],CONVERT([varchar],getdate(),(112)),(0))),
		YzKDuzeltSaat=substring(CONVERT([varchar],CONVERT([time],getdate())),1,5),
		YzKMagazaKodu=@MagazaKodu WHERE YzKId=@Deger
	END
END
GO
CREATE PROCEDURE [dbo].[SpYzKsSatisSil]
@Deger			decimal,
@Type			tinyint,
@CariH			tinyint,
@SMalyTipi		tinyint
AS
BEGIN TRANSACTION
IF @Type = 0 
BEGIN
	DECLARE @CariId DECIMAL
	DECLARE @GenTop MONEY
	DECLARE @KarsiHs DECIMAL
	DECLARE @FisId DECIMAL
	
	SELECT @CariId = YzKCariId,@GenTop=YzKGenTop FROM Tb_YzKsSatis where YzKId = @Deger 
	DELETE FROM Tb_YzKsSatis WHERE YzKId=@Deger 
	DELETE FROM Tb_YzKKalem WHERE YkKFisId = @Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 6 AND SrnBaslikId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 6 AND RnbBaslikId=@Deger
	IF @CariH = 1 BEGIN
		DELETE Tb_CariFis WHERE CrFId IN (SELECT CrHFisId FROM Tb_CariHareket WHERE CrHEntgId = @Deger)
		DELETE Tb_CariHareket WHERE CrHEntgId = @Deger 
		DELETE Tb_HesGecme WHERE HsgModul=3 AND HsgSatisId = @Deger 
	END
	ELSE
	BEGIN
		UPDATE Tb_CariHareket SET CrHEntgTipi=0, CrHEntgId=0 WHERE CrHEntgId=@Deger AND CrHEntgTipi=4 AND CrHCariId = @CariId
		UPDATE Tb_HesGecme SET HsGModul=1,HsgSatisId = HsGCrHId WHERE HsGModul=3 AND HsGSatisId=@Deger
	END
END
ELSE 
BEGIN
	DELETE FROM Tb_YzKKalem where YkKId=@Deger 
	DELETE FROM Tb_SeriNo WHERE SrnModul = 6 AND SrnSatirId=@Deger 
	DELETE FROM Tb_RnBdHareket WHERE RnbModul = 6 AND RnbSatirId=@Deger
END
IF @@ERROR <> 0 
BEGIN 
    ROLLBACK TRANSACTION 
	SELECT @@ERROR 
END 
ELSE
BEGIN
	COMMIT TRANSACTION
	SELECT 0
END
GO