IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=162) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (162, 6, 'Ecr IPAdress', '0.0.0.0',0);
END


IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=163) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (163, 3, 'MasrafFisi NakitKasa Kodu', '',0);
END

IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=164) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (164, 3, 'MasrafFisi Firma Kredi Karti Kodu', '',0);
END

IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=165) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (165, 3, 'MasrafFisi Varsayilan Cari Kodu', '',0);
END

IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=166) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (166, 3, 'MasrafFisi Sorumluk Merkezi', '',0);
END

IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=167) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (167, 3, 'MasrafFisi Proje Kodu', '',0);
END

IF NOT EXISTS (SELECT * FROM AYARLAR WHERE AyarID=168) BEGIN
	INSERT INTO AYARLAR(AyarID, Fk_AyarGrubu, Aciklama, Deger, VeriTipi) VALUES (168, 3, 'MasrafFisi Evrak Seri', '',0);
END

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE type='U' and name = 'MASRAF_HESAPLARI') BEGIN
	CREATE TABLE MASRAF_HESAPLARI (
		[MasrafId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
		[Kod] [nvarchar](25) NOT NULL,
		[Isim] [nvarchar](50) NOT NULL,
		[VergiPntr] INT NULL DEFAULT 0,
		[VergiYuzde] FLOAT NULL DEFAULT 0,
		SonGuncellemeTarihi DATETIME NOT NULL
	);
END

GO


IF NOT EXISTS (SELECT * FROM sys.objects WHERE type='U' and name = 'MASRAF_FIS') BEGIN
	CREATE TABLE MASRAF_FIS (
		[MasrafFisId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
		[Tarih] DATETIME NOT NULL DEFAULT GETDATE(),
		[Tipi] [nvarchar](25) NOT NULL,  -- NAKIT, KREDI, ACIKHESAP
		[CariKod] [nvarchar](25) NOT NULL,
		[NakitKasa] [nvarchar](25) NOT NULL,
		[FirmaKrediKarti] [nvarchar](25) NOT NULL,
		[Toplam] FLOAT NOT NULL,
		[EvrakSeri] [nvarchar](20) NOT NULL,
		[EvrakSira] INT NOT NULL,
		[Synced] INT NOT NULL,
	);
END

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE type='U' and name = 'MASRAF_FIS_DETAY') BEGIN
	CREATE TABLE MASRAF_FIS_DETAY (
		[MasrafFisDetayId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
		[Fk_MasrafFisId] INT NOT NULL,
		[Fk_MasrafId] INT NOT NULL,
		[MasrafKod] [nvarchar](25) NOT NULL,
		[Meblag] FLOAT NOT NULL,
		[AraToplam] FLOAT NOT NULL,
		[VergiPntr] INT NOT NULL,
		[VergiYuzde] FLOAT NOT NULL,
		[Vergi] FLOAT NOT NULL,
		[Aciklama] [nvarchar](40) NOT NULL,
	);
END