CREATE DATABASE [OTELADI]  ON (NAME = N'OTELADI_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\OTELADI.mdf' , SIZE = 10, FILEGROWTH = 10%) LOG ON (NAME = N'OTELADI_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\OTELADI_log.ldf' , SIZE = 1, FILEGROWTH = 10%)
 
GO

exec sp_dboption N'OTELADI', N'autoclose', N'false'
GO

exec sp_dboption N'OTELADI', N'bulkcopy', N'false'
GO

exec sp_dboption N'OTELADI', N'trunc. log', N'true'
GO

exec sp_dboption N'OTELADI', N'torn page detection', N'true'
GO

exec sp_dboption N'OTELADI', N'read only', N'false'
GO

exec sp_dboption N'OTELADI', N'dbo use', N'false'
GO

exec sp_dboption N'OTELADI', N'single', N'false'
GO

exec sp_dboption N'OTELADI', N'autoshrink', N'true'
GO

exec sp_dboption N'OTELADI', N'ANSI null default', N'false'
GO

exec sp_dboption N'OTELADI', N'recursive triggers', N'false'
GO

exec sp_dboption N'OTELADI', N'ANSI nulls', N'false'
GO

exec sp_dboption N'OTELADI', N'concat null yields null', N'false'
GO

exec sp_dboption N'OTELADI', N'cursor close on commit', N'false'
GO

exec sp_dboption N'OTELADI', N'default to local cursor', N'false'
GO

exec sp_dboption N'OTELADI', N'quoted identifier', N'false'
GO

exec sp_dboption N'OTELADI', N'ANSI warnings', N'false'
GO

exec sp_dboption N'OTELADI', N'auto create statistics', N'true'
GO

exec sp_dboption N'OTELADI', N'auto update statistics', N'true'
GO

use [OTELADI]
GO

CREATE TABLE [dbo].[BARKOD] (
	[BARKODID] [int] NOT NULL ,
	[STOKID] [int] NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[BARKOD] [nvarchar] (30)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[BAYI] (
	[BAYIID] [int] NOT NULL ,
	[BAYI] [nvarchar] (50)   NULL ,
	[BKOMORAN] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[BUTCE] (
	[BUTCEID] [int] IDENTITY (1, 1) NOT NULL ,
	[HESAPID] [int] NOT NULL ,
	[SUBEKODU] [nvarchar] (10)   NOT NULL ,
	[AY] [int] NOT NULL ,
	[YIL] [int] NOT NULL ,
	[TLTUTAR] [float] NULL ,
	[EURTUTAR] [float] NULL ,
	[MASMERID] [int] NULL ,
	[MIKTAR] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[BUTCEDEGER] (
	[BUTCEID] [int] IDENTITY (1, 1) NOT NULL ,
	[SUBEKODU] [nvarchar] (10)   NOT NULL ,
	[AY] [int] NOT NULL ,
	[YIL] [int] NOT NULL ,
	[TL] [float] NULL ,
	[EUR] [float] NULL ,
	[EURYIL] [float] NULL ,
	[USD] [float] NULL ,
	[SATILABILIRODAGUNLUK] [int] NULL ,
	[SATILABILIRODAAYLIK] [int] NULL ,
	[SATILABILIRODAYILLIK] [int] NULL ,
	[SATILABILIRYATAKGUN] [int] NULL ,
	[SATILABILIRYATAKAYLIK] [int] NULL ,
	[SATILABILIRYATAKYILLIK] [int] NULL ,
	[SATILANODA] [int] NULL ,
	[SATILANODAYILLIK] [int] NULL ,
	[SATILANYATAK] [int] NULL ,
	[SATILANYATAKYILLIK] [int] NULL ,
	[UCRETLICCKGECE] [int] NULL ,
	[UCRETLICCKGECEYILLIK] [int] NULL ,
	[UCRETSISCCKGECE] [int] NULL ,
	[UCRETSISCCKGECEYILLIK] [int] NULL ,
	[COMPGECE] [int] NULL ,
	[COMPGECEYILLIK] [int] NULL ,
	[HUSEGECE] [int] NULL ,
	[HUSEGECEYILLIK] [int] NULL ,
	[ORTODAFIYAT] [float] NULL ,
	[ORTODAFIYATYILLIK] [float] NULL ,
	[ORTYATAKFIYAT] [float] NULL ,
	[ORTYATAKFIYATYILLIK] [float] NULL ,
	[ODADOLULUK] [float] NULL ,
	[ODADOLULUKYILLIK] [float] NULL ,
	[YATAKDOLULUK] [float] NULL ,
	[YATAKDOLULUKYILLIK] [float] NULL ,
	[ORTKNKKISIODA] [float] NULL ,
	[ORTKNKKISIODAYILLIK] [float] NULL ,
	[ORTKALIS] [float] NULL ,
	[ORTKALISYILLIK] [float] NULL ,
	[ORTCALPERSGUN] [float] NULL ,
	[ORTCALPERSGUNYILLIK] [float] NULL ,
	[TIPI] [nvarchar] (10)   NULL ,
	[ONCYILEUR] [float] NULL ,
	[ONCYILEURYIL] [float] NULL ,
	[ONCYILSATILANYATAK] [int] NULL ,
	[ONCYILSATILANYATAKYILLIK] [int] NULL ,
	[AVRGNOOFARRIVAL] [float] NULL ,
	[AVRGNOOFARRIVALYILLIK] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CARIISL] (
	[CARIISLID] [int] IDENTITY (1, 1) NOT NULL ,
	[CARIID] [int] NOT NULL ,
	[TARIH] [smalldatetime] NOT NULL ,
	[VADE] [smalldatetime] NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[EVRAKNO] [nvarchar] (20)   NULL ,
	[ISLTUR] [nvarchar] (20)   NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[DOVIZ] [nvarchar] (5)   NULL ,
	[FATCOUNTER] [int] NULL ,
	[BANKAID] [int] NULL ,
	[KASAID] [int] NULL ,
	[BORDROID] [int] NULL ,
	[KAPANAN] [float] NULL ,
	[ODEMEID] [int] NULL ,
	[CARIID2] [int] NULL ,
	[ISLEMNO] [int] NULL ,
	[DURUM] [int] NULL ,
	[KTARIH] [datetime] NULL ,
	[KYAPAN] [nvarchar] (15)   NULL ,
	[MUHFC] [int] NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[GKODU] [nvarchar] (10)   NULL ,
	[GGRUBU] [nvarchar] (5)   NULL ,
	[DEPT] [nvarchar] (5)   NULL ,
	[ADISYONID] [int] NULL ,
	[TAMAMLANDI] [int] NULL ,
	[CIHESAPID] [int] NULL ,
	[CIHESAPID2] [int] NULL ,
	[KDVTUTAR] [float] NULL ,
	[KDVHESAPID] [int] NULL ,
	[STP1TUTAR] [float] NULL ,
	[STP1HESAPID] [int] NULL ,
	[STP2TUTAR] [float] NULL ,
	[STP2HESAPID] [int] NULL ,
	[GDR1TUTAR] [float] NULL ,
	[GDR1HESAPID] [int] NULL ,
	[GDR2TUTAR] [float] NULL ,
	[GDR2HESAPID] [int] NULL ,
	[GDR3TUTAR] [float] NULL ,
	[GDR3HESAPID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CEK] (
	[CEKID] [int] IDENTITY (1, 1) NOT NULL ,
	[TUR] [nvarchar] (25)   NULL ,
	[VADE] [smalldatetime] NULL ,
	[CEKNO] [nvarchar] (20)   NULL ,
	[SAHIBI] [nvarchar] (50)   NULL ,
	[BANKA] [nvarchar] (20)   NULL ,
	[HESAPNO] [nvarchar] (20)   NULL ,
	[TARIH] [smalldatetime] NULL ,
	[CARIID] [int] NULL ,
	[TUTAR] [float] NULL ,
	[DTUTAR] [float] NULL ,
	[DURUM] [nvarchar] (15)   NULL ,
	[ODENDI] [int] NULL ,
	[CEKHESAPID] [int] NULL ,
	[BANKAID] [int] NULL ,
	[EKBILGI1] [nvarchar] (50)   NULL ,
	[EKBILGI2] [nvarchar] (50)   NULL ,
	[EKBILGI3] [nvarchar] (50)   NULL ,
	[DOVIZKODU] [nvarchar] (5)   NULL ,
	[DOVIZTUTAR] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CEKBORDRO] (
	[CEKBORDROID] [int] NULL ,
	[TARIH] [smalldatetime] NULL ,
	[VADE] [smalldatetime] NULL ,
	[TOPLAM] [float] NULL ,
	[TIP] [nvarchar] (10)   NULL ,
	[CARIID] [int] NULL ,
	[CARIID2] [int] NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[ENO] [nvarchar] (15)   NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[DURUM] [int] NULL ,
	[MUHFC] [int] NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[DOVIZKODU] [nvarchar] (5)   NULL ,
	[DOVIZTUTAR] [float] NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[FATCOUNTER] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CEKISL] (
	[CEKISLID] [int] NOT NULL ,
	[CEKID] [int] NOT NULL ,
	[CEKBORDROID] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CEKSENET] (
	[COUNTER] [int] IDENTITY (1, 1) NOT NULL ,
	[VADETAR] [smalldatetime] NULL ,
	[DURUM] [nvarchar] (25)   NULL ,
	[NO] [nvarchar] (20)   NULL ,
	[CEKSENET] [nvarchar] (5)   NULL ,
	[TURU] [nvarchar] (20)   NULL ,
	[CIROLAYAN] [nvarchar] (20)   NULL ,
	[DEVRALAN] [nvarchar] (20)   NULL ,
	[DUZENLEMETAR] [smalldatetime] NULL ,
	[CIROLAMATAR] [smalldatetime] NULL ,
	[GIRISCOUNTER] [float] NULL ,
	[CIKISCOUNTER] [float] NULL ,
	[BANKA] [nvarchar] (20)   NULL ,
	[SUBE] [nvarchar] (20)   NULL ,
	[TUTAR] [float] NULL ,
	[ALACAKLIADI] [nvarchar] (80)   NULL ,
	[BORCLUADI] [nvarchar] (80)   NULL ,
	[BORCLUEK] [nvarchar] (80)   NULL ,
	[CEKNOEK] [nvarchar] (100)   NULL ,
	[DOVTURU] [nvarchar] (10)   NULL ,
	[SKODU] [nvarchar] (15)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CONFIG] (
	[CONFIGID] [int] IDENTITY (1, 1) NOT NULL ,
	[PROGNAME] [nvarchar] (50)   NOT NULL ,
	[SECTIONSTR] [nvarchar] (200)   NOT NULL ,
	[KEYNAME] [nvarchar] (200)   NOT NULL ,
	[VALUESTR] [nvarchar] (200)   NULL ,
	[ALTERNATIVES] [nvarchar] (255)   NULL ,
	[TYPES] [smallint] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMDEPART] (
	[DEPARTID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEPARTADI] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMGECMIS] (
	[GECMISID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEMKARTID] [int] NULL ,
	[TARIHBAS] [datetime] NULL ,
	[TARIHSON] [datetime] NULL ,
	[YERID] [int] NULL ,
	[SORUMLU] [nvarchar] (20)   NULL ,
	[NOTLAR] [nvarchar] (200)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMGRUP] (
	[DEMGRUPID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEMGRUPKODU] [nvarchar] (50)   NOT NULL ,
	[DEMGRUPADI] [nvarchar] (50)   NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[TURID] [int] NULL ,
	[BRKMUHKODU] [nvarchar] (50)   NULL ,
	[MLYTMUHKODU] [nvarchar] (50)   NULL ,
	[OMRU] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMIADE] (
	[DEMIADEID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEMKARTID] [int] NULL ,
	[SATICI] [nvarchar] (100)   NULL ,
	[IADESUBE] [nvarchar] (10)   NULL ,
	[TARIH] [smalldatetime] NULL ,
	[MIKTAR] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMKART] (
	[DEMKARTID] [int] IDENTITY (1, 1) NOT NULL ,
	[GRUPID] [int] NOT NULL ,
	[KODU] [nvarchar] (20)   NOT NULL ,
	[EKKOD] [nvarchar] (10)   NOT NULL ,
	[ADI] [nvarchar] (100)   NOT NULL ,
	[BARKODU] [nvarchar] (25)   NULL ,
	[TESLIMTARIH] [datetime] NULL ,
	[FATURATARIH] [datetime] NULL ,
	[FATURANO] [nvarchar] (15)   NULL ,
	[SATICI] [nvarchar] (30)   NULL ,
	[DEGERI] [float] NULL ,
	[OMRU] [float] NULL ,
	[AMORTISMAN] [float] NULL ,
	[ACIKLAMA] [nvarchar] (250)   NULL ,
	[BIRIM] [nvarchar] (10)   NULL ,
	[ADET] [float] NULL ,
	[SIRKETID] [int] NULL ,
	[DEPARTID] [int] NULL ,
	[YERID] [int] NULL ,
	[FIRMAURUNKODU] [nvarchar] (50)   NULL ,
	[SERINO] [nvarchar] (50)   NULL ,
	[ZIMMETLENEN] [nvarchar] (80)   NULL ,
	[GVDAMORTISMAN] [float] NULL ,
	[BRKAMORTISMAN] [float] NULL ,
	[SAHIBI] [nvarchar] (80)   NULL ,
	[HTURU] [nvarchar] (20)   NOT NULL ,
	[TRFSUBEID] [int] NULL ,
	[TRFTARIH] [datetime] NULL ,
	[TRFFATNO] [nvarchar] (15)   NULL ,
	[SATFIRMAID] [int] NULL ,
	[SATTARIH] [datetime] NULL ,
	[SATTUTAR] [float] NULL ,
	[SATFATNO] [nvarchar] (15)   NULL ,
	[MARKA] [nvarchar] (50)   NULL ,
	[MODEL] [nvarchar] (50)   NULL ,
	[URETICI] [nvarchar] (50)   NULL ,
	[TESVIKLI] [bit] NULL ,
	[MIKTAR] [float] NOT NULL ,
	[FMIKTAR] [float] NULL ,
	[SONTRANS] [datetime] NULL ,
	[AITOLDUGUSUBE] [nvarchar] (10)   NOT NULL ,
	[TRFDURUMU] [int] NULL ,
	[MUHCARI] [nvarchar] (50)   NULL ,
	[MUHDEMIRBAS] [nvarchar] (50)   NULL ,
	[KDV] [float] NULL ,
	[MUH] [nvarchar] (1)   NULL ,
	[MUH1] [nvarchar] (1)   NULL ,
	[MUH2] [nvarchar] (1)   NULL ,
	[MUH3] [nvarchar] (1)   NULL ,
	[MUH4] [nvarchar] (1)   NULL ,
	[MUH5] [nvarchar] (1)   NULL ,
	[MUH6] [nvarchar] (1)   NULL ,
	[MUH7] [nvarchar] (1)   NULL ,
	[MUH8] [nvarchar] (1)   NULL ,
	[MUH9] [nvarchar] (1)   NULL ,
	[MUH10] [nvarchar] (1)   NULL ,
	[MUH11] [nvarchar] (1)   NULL ,
	[MUH12] [nvarchar] (1)   NULL ,
	[TRFONAYTARIH] [smalldatetime] NULL ,
	[TRFYERID] [int] NULL ,
	[TRFDEPARTID] [int] NULL ,
	[TRFZIMMETLENEN] [nvarchar] (50)   NULL ,
	[TRFAKTIFSUBE] [nvarchar] (10)   NULL ,
	[IADETARIH] [smalldatetime] NULL ,
	[ZAYIITARIH] [smalldatetime] NULL ,
	[ONAYBEKLIYOR] [bit] NULL ,
	[KDVTURU] [nvarchar] (1)   NULL ,
	[MUHFC] [float] NULL ,
	[MUHAMORTISMAN] [nvarchar] (50)   NULL ,
	[MUHMALIYET] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMKAYIP] (
	[DEMKAYIPID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [datetime] NULL ,
	[DEMKARTID] [int] NULL ,
	[SORUMLU] [nvarchar] (15)   NULL ,
	[YERID] [int] NULL ,
	[NOTLAR] [nvarchar] (50)   NULL ,
	[KYPSUBESI] [nvarchar] (10)   NULL ,
	[MIKTAR] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMSATICI] (
	[DEMSATICIID] [int] IDENTITY (1, 1) NOT NULL ,
	[UNVANI] [nvarchar] (100)   NULL ,
	[ADRESI] [nvarchar] (200)   NULL ,
	[TEL] [nvarchar] (20)   NULL ,
	[FAX] [nvarchar] (20)   NULL ,
	[GSM] [nvarchar] (20)   NULL ,
	[SERVISTEL] [nvarchar] (20)   NULL ,
	[WEBSITE] [nvarchar] (50)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (20)   NULL ,
	[VD] [nvarchar] (20)   NULL ,
	[VDNO] [nvarchar] (20)   NULL ,
	[NOTLAR] [nvarchar] (100)   NULL ,
	[MUHSATICI] [nvarchar] (50)   NULL ,
	[MUHALICI] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMSOZ] (
	[SOZID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIHBAS] [datetime] NULL ,
	[TARIHSON] [datetime] NULL ,
	[SATICIID] [int] NULL ,
	[TURU] [nvarchar] (15)   NULL ,
	[BEDELI] [float] NULL ,
	[ODEMESEKLI] [nvarchar] (15)   NULL ,
	[YETKILI] [nvarchar] (20)   NULL ,
	[KAPSAMI] [nvarchar] (200)   NULL ,
	[NOTLAR] [nvarchar] (200)   NULL ,
	[NOTU] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMSOZKALEM] (
	[SOZKALEMID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEMKARTID] [int] NULL ,
	[SOZID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMSTS] (
	[DEMSATISID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEMKARTID] [int] NULL ,
	[SATICIID] [int] NULL ,
	[TUTAR] [float] NULL ,
	[TARIH] [smalldatetime] NULL ,
	[FATNO] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[ACIKLAMA] [nvarchar] (255)   NULL ,
	[SATANSUBE] [nvarchar] (10)   NULL ,
	[ESKISUBESI] [nvarchar] (10)   NULL ,
	[ONAY] [bit] NULL ,
	[MIKTAR] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMSUBE] (
	[SUBEID] [int] IDENTITY (1, 1) NOT NULL ,
	[SUBEADI] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[TEL] [nvarchar] (20)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMTRANS] (
	[DEMTRANSID] [int] NOT NULL ,
	[DEMKARTID] [int] NOT NULL ,
	[MIKTAR] [numeric](9, 2) NOT NULL ,
	[SIRKETID1] [int] NULL ,
	[DEPARTID1] [int] NULL ,
	[YERID1] [int] NULL ,
	[ZIMMETLENEN1] [nvarchar] (80)   NULL ,
	[SIRKETID2] [int] NULL ,
	[DEPARTID2] [int] NULL ,
	[YERID2] [int] NULL ,
	[ZIMMETLENEN2] [nvarchar] (80)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[KTARIH] [datetime] NULL ,
	[TARIH] [datetime] NOT NULL ,
	[ACIKLAMA] [nvarchar] (255)   NULL ,
	[FIYAT] [float] NULL ,
	[TRFSUBESI] [nvarchar] (10)   NULL ,
	[ESKISUBESI] [nvarchar] (10)   NULL ,
	[ONAY] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMTUR] (
	[TURID] [int] IDENTITY (1, 1) NOT NULL ,
	[TURKODU] [nvarchar] (50)   NULL ,
	[TURADI] [nvarchar] (150)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEMYER] (
	[YERID] [int] IDENTITY (1, 1) NOT NULL ,
	[YERADI] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEPART] (
	[KODU] [nvarchar] (5)   NOT NULL ,
	[ADI] [nvarchar] (15)   NULL ,
	[TUR] [nvarchar] (1)   NULL ,
	[DEPOY] [nvarchar] (15)   NULL ,
	[DEPOI] [nvarchar] (15)   NULL ,
	[KDV] [smallint] NULL ,
	[MUHKODU] [nvarchar] (40)   NULL ,
	[MUHKODUYIYECEK] [nvarchar] (40)   NULL ,
	[MUHKODUICECEK] [nvarchar] (40)   NULL ,
	[GRUBU] [nvarchar] (20)   NULL ,
	[AI] [bit] NOT NULL ,
	[IND] [bit] NOT NULL ,
	[Y1S] [smallint] NULL ,
	[Y1D] [smallint] NULL ,
	[Y2S] [smallint] NULL ,
	[Y2D] [smallint] NULL ,
	[I1S] [smallint] NULL ,
	[I1D] [smallint] NULL ,
	[I2S] [smallint] NULL ,
	[I2D] [smallint] NULL ,
	[D1S] [smallint] NULL ,
	[D1D] [smallint] NULL ,
	[D2S] [smallint] NULL ,
	[D2D] [smallint] NULL ,
	[YI] [bit] NOT NULL ,
	[AskTableNo] [real] NULL ,
	[AskCover] [real] NULL ,
	[AskCheckId] [real] NULL ,
	[AskCardNo] [real] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEPGGMUH] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEPT] [nvarchar] (5)   NULL ,
	[GELIRGRUBU] [nvarchar] (5)   NULL ,
	[HESAPID] [int] NULL ,
	[INDHESAPID] [int] NULL ,
	[IADEHESAPID] [int] NULL ,
	[SKODU] [nvarchar] (15)   NULL ,
	[MASMERID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEPO] (
	[DEPOID] [int] NOT NULL ,
	[DEPOADI] [nvarchar] (15)   NULL ,
	[ANADEPO] [bit] NULL ,
	[DEPOMUH] [int] NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[KODU] [nvarchar] (5)   NULL ,
	[ADI] [nvarchar] (25)   NULL ,
	[MUHKODU] [nvarchar] (25)   NULL ,
	[MUHKODUSARF] [nvarchar] (25)   NULL ,
	[MASMERID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEPOFIS] (
	[DEPOFISID] [int] NOT NULL ,
	[TARIH] [datetime] NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ISLEM] [nvarchar] (10)   NULL ,
	[ENO] [nvarchar] (10)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[GDEPOID] [int] NULL ,
	[CDEPOID] [int] NULL ,
	[TADET] [float] NULL ,
	[TTUTAR] [float] NULL ,
	[GSKODU] [nvarchar] (10)   NULL ,
	[CSKODU] [nvarchar] (10)   NULL ,
	[URUNFISID] [int] NULL ,
	[URETILDI] [bit] NULL ,
	[LOGOAKTAR] [int] NULL ,
	[LOGODANGELDI] [bit] NULL ,
	[ISLEMDETAY] [nvarchar] (15)   NULL ,
	[SDEPART] [nvarchar] (15)   NULL ,
	[ONAY] [bit] NULL ,
	[MUHFISID] [int] NULL ,
	[DURUMU] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEPOFISISL] (
	[DEPOFISISLID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEPOFISID] [int] NULL ,
	[STOKID] [int] NULL ,
	[MIKTAR] [float] NULL ,
	[FBIRIM] [nvarchar] (50)   NULL ,
	[FMIKTAR] [float] NULL ,
	[BFIYAT] [float] NULL ,
	[SFIYAT] [float] NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ACIKLAMA] [nvarchar] (200)   NULL ,
	[ISLREFID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DEPOMUH] (
	[DEPOMUHID] [int] IDENTITY (1, 1) NOT NULL ,
	[KODU] [nvarchar] (5)   NULL ,
	[GRUPKODU] [nvarchar] (18)   NOT NULL ,
	[MUHKODUCIKIS] [nvarchar] (40)   NULL ,
	[MUHKODUSARF] [nvarchar] (40)   NULL ,
	[DEPOID] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DOVIZ] (
	[KODU] [nvarchar] (5)   NOT NULL ,
	[ADI] [nvarchar] (25)   NULL ,
	[TCMBKODU] [nvarchar] (5)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DOVIZBOZISL] (
	[DOVIZBOZID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NOT NULL ,
	[SAAT] [datetime] NULL ,
	[ADOVIZKODU] [nvarchar] (5)   NULL ,
	[ADOVIZTUTAR] [float] NULL ,
	[VDOVIZKODU] [nvarchar] (5)   NULL ,
	[VDOVIZTUTAR] [float] NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ENO] [nvarchar] (50)   NULL ,
	[ODANO] [nvarchar] (15)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[TLTUTAR] [float] NULL ,
	[SIRANO] [int] NULL ,
	[KUR] [float] NULL ,
	[DEPT] [nvarchar] (5)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DOVIZISL] (
	[DOVIZISLID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[KODU] [nvarchar] (5)   NULL ,
	[KUR1] [float] NULL ,
	[KUR2] [float] NULL ,
	[KUR3] [float] NULL ,
	[KUR4] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ETIKET] (
	[ETIKETNO] [smallint] NOT NULL ,
	[TANIMI] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ETS_CARI] (
	[CARIID] [int] NOT NULL ,
	[KODU] [nvarchar] (20)   NULL ,
	[UNVANI] [nvarchar] (100)   NULL ,
	[ADRES1] [nvarchar] (100)   NULL ,
	[ADRES2] [nvarchar] (100)   NULL ,
	[SEHIR] [nvarchar] (20)   NULL ,
	[PKODU] [nvarchar] (20)   NULL ,
	[ULKE] [nvarchar] (20)   NULL ,
	[VD] [nvarchar] (20)   NULL ,
	[VDNO] [nvarchar] (20)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[WEB] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[TEL1] [nvarchar] (30)   NULL ,
	[TEL2] [nvarchar] (30)   NULL ,
	[FAX] [nvarchar] (20)   NULL ,
	[GSM] [nvarchar] (20)   NULL ,
	[AFIYATNO] [smallint] NULL ,
	[STDIND] [float] NULL ,
	[VADEGUN] [int] NULL ,
	[GFAIZ] [float] NULL ,
	[FKODU] [int] NULL ,
	[EK1] [nvarchar] (50)   NULL ,
	[EK2] [nvarchar] (50)   NULL ,
	[EK3] [nvarchar] (50)   NULL ,
	[EK4] [nvarchar] (50)   NULL ,
	[EK5] [nvarchar] (50)   NULL ,
	[DDEVIR] [float] NULL ,
	[YDEVIR] [float] NULL ,
	[ALISIND] [float] NULL ,
	[TIP] [nvarchar] (15)   NULL ,
	[ADISOYADI] [nvarchar] (25)   NULL ,
	[DYERI] [nvarchar] (15)   NULL ,
	[BABAADI] [nvarchar] (15)   NULL ,
	[DTARIHI] [smalldatetime] NULL ,
	[TCKIMLIKNO] [nvarchar] (12)   NULL ,
	[CINSIYETI] [nvarchar] (1)   NULL ,
	[YAZISMA] [nvarchar] (2)   NULL ,
	[UYENOT] [nvarchar] (15)   NULL ,
	[FIRMA] [nvarchar] (15)   NULL ,
	[ISADRES] [nvarchar] (55)   NULL ,
	[ISADRES2] [nvarchar] (40)   NULL ,
	[ISADRES3] [nvarchar] (20)   NULL ,
	[ISPKODU] [nvarchar] (7)   NULL ,
	[ISTEL] [nvarchar] (14)   NULL ,
	[ISTEL2] [nvarchar] (14)   NULL ,
	[ISTEL3] [nvarchar] (14)   NULL ,
	[ISFAXNO] [nvarchar] (14)   NULL ,
	[CEPTEL] [nvarchar] (14)   NULL ,
	[EVADRES] [nvarchar] (40)   NULL ,
	[EVADRES2] [nvarchar] (40)   NULL ,
	[EVADRES3] [nvarchar] (20)   NULL ,
	[EVPKODU] [nvarchar] (50)   NULL ,
	[EVTEL] [nvarchar] (14)   NULL ,
	[EVFAX] [nvarchar] (14)   NULL ,
	[GRUBU] [nvarchar] (10)   NULL ,
	[MESLEK] [nvarchar] (20)   NULL ,
	[GOREVI] [nvarchar] (15)   NULL ,
	[ARACTEL] [nvarchar] (14)   NULL ,
	[ESIADI] [nvarchar] (25)   NULL ,
	[COCUK1] [nvarchar] (15)   NULL ,
	[COCUK2] [nvarchar] (15)   NULL ,
	[EVLILIKT] [smalldatetime] NULL ,
	[SAC] [nvarchar] (10)   NULL ,
	[BOY] [int] NULL ,
	[KILO] [int] NULL ,
	[HASTALIKLAR] [nvarchar] (100)   NULL ,
	[KANGRUBU] [nvarchar] (7)   NULL ,
	[KREDIKARTNO] [nvarchar] (50)   NULL ,
	[UYENO] [nvarchar] (15)   NULL ,
	[UYEBASLAMA] [smalldatetime] NULL ,
	[UYEBITIS] [smalldatetime] NULL ,
	[UYELIKTIPI] [nvarchar] (15)   NULL ,
	[UYEKISITIPI] [nvarchar] (10)   NULL ,
	[ACILDURUM] [nvarchar] (100)   NULL ,
	[REF1] [nvarchar] (50)   NULL ,
	[REF2] [nvarchar] (50)   NULL ,
	[SATISTEMSIL] [nvarchar] (15)   NULL ,
	[SATISTID] [int] NULL ,
	[KARTNO] [nvarchar] (25)   NULL ,
	[STATUSU] [nvarchar] (15)   NULL ,
	[HESAPID] [int] NULL ,
	[NOTLAR] [nvarchar] (250)   NULL ,
	[DOVIZ] [nvarchar] (5)   NULL ,
	[CGRUBU] [nvarchar] (15)   NULL ,
	[KKSAHIBI] [nvarchar] (50)   NULL ,
	[KKSGECTRHAY] [char] (2)   NULL ,
	[KKSGECTRHYIL] [char] (2)   NULL ,
	[KKCV2] [char] (3)   NULL ,
	[KLIMITI] [float] NULL ,
	[EKTUTAR1] [float] NULL ,
	[EKTUTAR2] [float] NULL ,
	[EKTUTAR3] [float] NULL ,
	[EKTUTAR4] [float] NULL ,
	[EKTARIH1] [smalldatetime] NULL ,
	[EKTARIH2] [smalldatetime] NULL ,
	[EKTARIH3] [smalldatetime] NULL ,
	[GKODU] [nvarchar] (10)   NULL ,
	[DDDEVIR] [float] NULL ,
	[DYDEVIR] [float] NULL ,
	[KARTTURU] [nvarchar] (10)   NULL ,
	[INDORAN] [float] NULL ,
	[ASIMORAN] [float] NULL ,
	[KSKODU] [nvarchar] (10)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ETS_HESAPISL] (
	[COUNTER] [int] IDENTITY (1, 1) NOT NULL ,
	[FISCOUNTER] [float] NULL ,
	[HESAPID] [int] NOT NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[BORC] [float] NOT NULL ,
	[ALACAK] [float] NOT NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[MBORC] [float] NULL ,
	[MALACAK] [float] NULL ,
	[MASMER] [nvarchar] (40)   NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[KAPANAN] [float] NULL ,
	[VADE] [smalldatetime] NULL ,
	[KUR] [float] NULL ,
	[YEVNO] [nvarchar] (10)   NULL ,
	[TLBORC] [float] NULL ,
	[TLALACAK] [float] NULL ,
	[KAYITID] [int] NULL ,
	[KODU] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[DEGISTIREN] [nvarchar] (50)   NULL ,
	[FSGDYR] [smallint] NULL ,
	[FSGCKD] [smallint] NULL ,
	[FSYHKD] [char] (2)   NULL ,
	[FSYHNO] [char] (16)   NULL ,
	[FSBGNO] [char] (15)   NULL ,
	[FSBGTR] [int] NULL ,
	[MASMERID] [int] NULL ,
	[BUTCEID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FATGRUP] (
	[GRUPADI] [nvarchar] (15)   NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FATISL] (
	[FATISLID] [int] IDENTITY (1, 1) NOT FOR REPLICATION  NOT NULL ,
	[FATID] [int] NOT NULL ,
	[STOKID] [int] NOT NULL ,
	[ACIKLAMA] [nvarchar] (150)   NULL ,
	[ADET] [float] NULL ,
	[BFIYAT] [float] NULL ,
	[SATIRIND] [float] NULL ,
	[SATIRIND2] [float] NULL ,
	[BARKOD] [nvarchar] (20)   NULL ,
	[KODU] [nvarchar] (20)   NULL ,
	[SATISTID] [int] NULL ,
	[FBIRIM] [nvarchar] (50)   NULL ,
	[FADET] [float] NULL ,
	[VADE] [smalldatetime] NULL ,
	[HESAPID] [int] NULL ,
	[KDV] [float] NULL ,
	[SRMMRKID] [int] NULL ,
	[GKODU] [nvarchar] (10)   NULL ,
	[IRSCOUNTER] [int] NULL ,
	[IRSCOUNTERILK] [int] NULL ,
	[SATIRINDT] [float] NULL ,
	[DEPT] [nvarchar] (5)   NULL ,
	[GELIRGRUP] [nvarchar] (5)   NULL ,
	[FBFIYAT] [float] NULL ,
	[FBTOPLAM] [float] NULL ,
	[ARATOPLAM] [float] NOT NULL ,
	[TOPLAM] [float] NOT NULL ,
	[SATINALMAISLID] [int] NULL ,
	[SGRUPLA] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FATISL2] (
	[FATISL2ID] [int] NOT NULL ,
	[FATID] [int] NOT NULL ,
	[FITEMKODU] [nvarchar] (15)   NULL ,
	[FITEMADI] [nvarchar] (100)   NOT NULL ,
	[ADET] [float] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FATSAYAC] (
	[FATSAYACID] [int] NOT NULL ,
	[FATSAYACSERI] [nvarchar] (6)   NOT NULL ,
	[FATSAYACNO] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FATTUR] (
	[FATTURID] [int] IDENTITY (1, 1) NOT NULL ,
	[TURADI] [nvarchar] (15)   NULL ,
	[KATSAYI] [real] NULL ,
	[MUHKODU] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FATURA] (
	[FATID] [int] NOT NULL ,
	[SUBEID] [int] NULL ,
	[FIPTAL] [smallint] NOT NULL ,
	[TARIH] [datetime] NOT NULL ,
	[SAAT] [datetime] NULL ,
	[TUR] [smallint] NOT NULL ,
	[FATGRUP] [nvarchar] (15)   NULL ,
	[FATNO] [nvarchar] (20)   NULL ,
	[VADE] [datetime] NULL ,
	[ACIKLAMA] [nvarchar] (250)   NULL ,
	[CARIID] [int] NULL ,
	[SIND] [float] NULL ,
	[TOPLAM] [float] NULL ,
	[KDV] [float] NULL ,
	[GTOPLAM] [float] NULL ,
	[ADRES1] [nvarchar] (100)   NULL ,
	[ADRES2] [nvarchar] (100)   NULL ,
	[ADRES3] [nvarchar] (100)   NULL ,
	[VD] [nvarchar] (20)   NULL ,
	[VDNO] [nvarchar] (20)   NULL ,
	[UNVANI] [nvarchar] (100)   NULL ,
	[SATISTID] [int] NULL ,
	[BAYIID] [int] NULL ,
	[OZELKOD1] [nvarchar] (20)   NULL ,
	[OZELKOD2] [nvarchar] (20)   NULL ,
	[OZELKOD3] [nvarchar] (20)   NULL ,
	[OZELKOD4] [nvarchar] (20)   NULL ,
	[OZELKOD5] [nvarchar] (20)   NULL ,
	[OZELKOD6] [nvarchar] (100)   NULL ,
	[OZELKOD7] [nvarchar] (100)   NULL ,
	[OZELKOD8] [nvarchar] (100)   NULL ,
	[OZELKOD9] [nvarchar] (50)   NULL ,
	[OZELKOD10] [nvarchar] (50)   NULL ,
	[BARKODYAZ] [smallint] NULL ,
	[ODEMES] [nvarchar] (20)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[USER] [nvarchar] (20)   NULL ,
	[ONAKIT] [float] NULL ,
	[OKK] [float] NULL ,
	[OTICKET] [float] NULL ,
	[OACIK] [float] NULL ,
	[VPARA] [float] NULL ,
	[FI] [smallint] NULL ,
	[IRSALIYE] [bit] NOT NULL ,
	[TURADI] [nvarchar] (15)   NULL ,
	[STUTAR] [float] NULL ,
	[KASAID] [int] NULL ,
	[BANKAID] [int] NULL ,
	[IND1] [float] NULL ,
	[IND2] [float] NULL ,
	[IND3] [float] NULL ,
	[EK1] [float] NULL ,
	[EK2] [float] NULL ,
	[EK3] [float] NULL ,
	[INDORAN1] [float] NULL ,
	[INDORAN2] [float] NULL ,
	[INDORAN3] [float] NULL ,
	[EKORAN1] [float] NULL ,
	[EKORAN2] [float] NULL ,
	[EKORAN3] [float] NULL ,
	[DURUM] [tinyint] NULL ,
	[DOVIZKODU] [nvarchar] (5)   NULL ,
	[DOVIZKURU] [float] NULL ,
	[DEPOID] [int] NULL ,
	[GTARIH] [datetime] NULL ,
	[SEC] [bit] NULL ,
	[MUHASEBE] [nvarchar] (1)   NULL ,
	[MUHENTSAYAC] [int] NULL ,
	[MUHASEBER] [nvarchar] (1)   NULL ,
	[MUHENTSAYACR] [int] NULL ,
	[ODENDI] [bit] NOT NULL ,
	[KESINTIVAR] [bit] NOT NULL ,
	[MUHFC] [int] NULL ,
	[TUTAR1] [float] NULL ,
	[TUTAR2] [float] NULL ,
	[TUTAR3] [float] NULL ,
	[YAZONAY] [bit] NOT NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[KNO] [int] NULL ,
	[DOVIZTUTAR] [float] NULL ,
	[COUNTER] [int] NULL ,
	[HESAPID] [int] NULL ,
	[KODU] [nvarchar] (15)   NULL ,
	[ADI] [nvarchar] (100)   NULL ,
	[FTURU] [nvarchar] (10)   NULL ,
	[FTARIHI] [datetime] NULL ,
	[FNO] [nvarchar] (15)   NULL ,
	[OTARIHI] [datetime] NULL ,
	[KDVORAN] [int] NULL ,
	[DTURU] [nvarchar] (15)   NULL ,
	[DKURU] [float] NULL ,
	[INDORAN] [float] NULL ,
	[STOPLAM] [float] NULL ,
	[INDTUTAR] [float] NULL ,
	[MATRAH] [float] NULL ,
	[ODENEN] [float] NULL ,
	[PROFORMA] [bit] NULL ,
	[OSEKLI] [nvarchar] (50)   NULL ,
	[SEHIR] [nvarchar] (25)   NULL ,
	[ALANK] [nvarchar] (25)   NULL ,
	[KDVSEKLI] [nvarchar] (5)   NULL ,
	[DTOPLAM] [float] NULL ,
	[T1] [float] NULL ,
	[T2] [float] NULL ,
	[T3] [float] NULL ,
	[LOGODANGELDI] [bit] NULL ,
	[FIPTALACIKLAMA] [nvarchar] (200)   NULL ,
	[FIPTALKULLANICI] [nvarchar] (20)   NULL ,
	[FIPTALTARIH] [datetime] NULL ,
	[KAPAMATARIH] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FIS] (
	[COUNTER] [float] NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[FISNO] [nvarchar] (10)   NULL ,
	[FISTURU] [nvarchar] (7)   NULL ,
	[KASAID] [int] NULL ,
	[ACIKLAMA] [nvarchar] (80)   NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[BELGENO] [nvarchar] (10)   NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[YETKILI] [nvarchar] (25)   NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[KULLANAN] [nvarchar] (10)   NULL ,
	[YEVNO] [nvarchar] (10)   NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[AKTCOUNTER] [int] NULL ,
	[DEGISTIREN] [nvarchar] (50)   NULL ,
	[LOGOREF] [int] NULL ,
	[ABAKIYE] [float] NULL ,
	[BBAKIYE] [float] NULL ,
	[ADBAKIYE] [float] NULL ,
	[BDBAKIYE] [float] NULL ,
	[AMBAKIYE] [float] NULL ,
	[BMBAKIYE] [float] NULL ,
	[DURUM] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FISSIL] (
	[COUNTER] [float] NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[FISNO] [nvarchar] (10)   NULL ,
	[FISTURU] [nvarchar] (7)   NULL ,
	[KASAID] [int] NULL ,
	[ACIKLAMA] [nvarchar] (80)   NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[BELGENO] [nvarchar] (10)   NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[YETKILI] [nvarchar] (25)   NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[KULLANAN] [nvarchar] (10)   NULL ,
	[YEVNO] [nvarchar] (10)   NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[AKTCOUNTER] [int] NULL ,
	[DEGISTIREN] [nvarchar] (50)   NULL ,
	[LOGOREF] [int] NULL ,
	[ABAKIYE] [float] NULL ,
	[BBAKIYE] [float] NULL ,
	[ADBAKIYE] [float] NULL ,
	[BDBAKIYE] [float] NULL ,
	[AMBAKIYE] [float] NULL ,
	[BMBAKIYE] [float] NULL ,
	[DURUM] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FORMDETAY] (
	[FORMDETAYID] [int] NOT NULL ,
	[FORMADI] [nvarchar] (50)   NOT NULL ,
	[SAHIBI] [nvarchar] (50)   NULL ,
	[TABLOADI] [nvarchar] (50)   NULL ,
	[ALANADI] [nvarchar] (50)   NULL ,
	[ALANTIPI] [nvarchar] (25)   NULL ,
	[ALANUZUNLUK] [int] NULL ,
	[ALANETIKETI] [nvarchar] (100)   NULL ,
	[ETIKETUZAKLIGI] [int] NULL ,
	[UST] [int] NULL ,
	[SOL] [int] NULL ,
	[YUKSEKLIK] [int] NULL ,
	[GENISLIK] [int] NULL ,
	[GORUNUR] [bit] NULL ,
	[SIRALAMA] [int] NULL ,
	[LTABLOSQL] [nvarchar] (255)   NULL ,
	[LLISTEALANI] [nvarchar] (50)   NULL ,
	[LKEYALANI] [nvarchar] (50)   NULL ,
	[SECIMLISTESI] [nvarchar] (255)   NULL ,
	[OBJEADI] [nvarchar] (100)   NULL ,
	[CLASSNAME] [nvarchar] (100)   NULL ,
	[PARENT] [nvarchar] (100)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FORMLAR] (
	[FORMADI] [nvarchar] (50)   NOT NULL ,
	[CAPTION] [nvarchar] (50)   NULL ,
	[WSTATE] [tinyint] NULL ,
	[MAXKAYIT] [int] NULL ,
	[LBASLIK] [nvarchar] (50)   NULL ,
	[KBASLIK] [nvarchar] (50)   NULL ,
	[DBASLIK] [nvarchar] (50)   NULL ,
	[WIDTH] [int] NULL ,
	[HEIGHT] [int] NULL ,
	[LGIRIS] [tinyint] NULL ,
	[DGIRIS] [tinyint] NULL ,
	[TARIHALANI] [nvarchar] (15)   NULL ,
	[TABALAN] [nvarchar] (15)   NULL ,
	[TABGENISLIK] [int] NULL ,
	[TABSQL] [nvarchar] (100)   NULL ,
	[ETIKETLER] [nvarchar] (255)   NULL ,
	[TABS] [nvarchar] (150)   NULL ,
	[ETABLENAME] [nvarchar] (50)   NULL ,
	[EFILTER] [nvarchar] (50)   NULL ,
	[ECOLUMNS] [nvarchar] (100)   NULL ,
	[EORDER] [nvarchar] (15)   NULL ,
	[ZORUNLUALAN] [nvarchar] (100)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GECICIDONEM] (
	[DONEMID] [int] IDENTITY (1, 1) NOT NULL ,
	[KODU] [nvarchar] (40)   NOT NULL ,
	[GRUPKODU] [smallint] NULL ,
	[MIZAN] [nvarchar] (1)   NULL ,
	[BA] [nvarchar] (1)   NULL ,
	[BTUTAR] [float] NULL ,
	[ATUTAR] [float] NULL ,
	[SKODU] [nvarchar] (20)   NULL ,
	[HESAPID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GELENTEL] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[SAAT] [smalldatetime] NULL ,
	[ARAYAN] [nvarchar] (25)   NULL ,
	[FIRMA] [nvarchar] (15)   NULL ,
	[TEL] [nvarchar] (14)   NULL ,
	[KIMI] [nvarchar] (50)   NULL ,
	[USER] [nvarchar] (50)   NULL ,
	[NOTU] [nvarchar] (255)   NULL ,
	[CEVABI] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GELIRGRUP] (
	[KODU] [nvarchar] (5)   NOT NULL ,
	[ADI] [nvarchar] (50)   NOT NULL ,
	[KDV] [smallint] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[HESAP] (
	[HESAPID] [int] NOT NULL ,
	[KODU] [nvarchar] (40)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[ACIKLAMA2] [nvarchar] (50)   NULL ,
	[ACIKLAMA3] [nvarchar] (50)   NULL ,
	[TIP] [nvarchar] (10)   NULL ,
	[CSEKLI] [nvarchar] (7)   NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[OZELKOD2] [nvarchar] (15)   NULL ,
	[MASMERID] [int] NULL ,
	[MIKBIRIM] [nvarchar] (15)   NULL ,
	[DOVTURU] [nvarchar] (5)   NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[MBORC] [float] NULL ,
	[MALACAK] [float] NULL ,
	[SEVIYE] [smallint] NULL ,
	[EK1] [nvarchar] (30)   NULL ,
	[EK2] [nvarchar] (30)   NULL ,
	[EK3] [nvarchar] (30)   NULL ,
	[EK4] [nvarchar] (30)   NULL ,
	[KEBIR] [nvarchar] (3)   NULL ,
	[MGOSTERME] [int] NULL ,
	[UCHESAP] [smallint] NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[SMASRAF] [int] NULL ,
	[VADEGUN] [int] NULL ,
	[MMZORUNLU] [smallint] NULL ,
	[FAALIYETICI] [smallint] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[HESAPBUTCE] (
	[BUTCEID] [int] NOT NULL ,
	[BUTCEKODU] [nvarchar] (40)   NULL ,
	[BUTCEADI] [nvarchar] (100)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[HESAPISLSIL] (
	[COUNTER] [int] IDENTITY (1, 1) NOT NULL ,
	[FISCOUNTER] [float] NULL ,
	[HESAPID] [int] NOT NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[BORC] [float] NOT NULL ,
	[ALACAK] [float] NOT NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[MBORC] [float] NULL ,
	[MALACAK] [float] NULL ,
	[MASMER] [nvarchar] (40)   NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[KAPANAN] [float] NULL ,
	[VADE] [smalldatetime] NULL ,
	[KUR] [float] NULL ,
	[YEVNO] [nvarchar] (10)   NULL ,
	[TLBORC] [float] NULL ,
	[TLALACAK] [float] NULL ,
	[KAYITID] [int] NULL ,
	[KODU] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[DEGISTIREN] [nvarchar] (50)   NULL ,
	[FSGDYR] [smallint] NULL ,
	[FSGCKD] [smallint] NULL ,
	[FSYHKD] [char] (2)   NULL ,
	[FSYHNO] [char] (16)   NULL ,
	[FSBGNO] [char] (15)   NULL ,
	[FSBGTR] [int] NULL ,
	[MASMERID] [int] NULL ,
	[BUTCEID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[HESISLSIL] (
	[COUNTER] [int] IDENTITY (1, 1) NOT NULL ,
	[FISCOUNTER] [float] NULL ,
	[HESAPID] [int] NOT NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[BORC] [float] NOT NULL ,
	[ALACAK] [float] NOT NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[MBORC] [float] NULL ,
	[MALACAK] [float] NULL ,
	[MASMER] [nvarchar] (40)   NULL ,
	[OZELKOD] [nvarchar] (15)   NULL ,
	[KAPANAN] [float] NULL ,
	[VADE] [smalldatetime] NULL ,
	[KUR] [float] NULL ,
	[YEVNO] [nvarchar] (10)   NULL ,
	[TLBORC] [float] NULL ,
	[TLALACAK] [float] NULL ,
	[KAYITID] [int] NULL ,
	[KODU] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[DEGISTIREN] [nvarchar] (50)   NULL ,
	[FSGDYR] [smallint] NULL ,
	[FSGCKD] [smallint] NULL ,
	[FSYHKD] [char] (2)   NULL ,
	[FSYHNO] [char] (16)   NULL ,
	[FSBGNO] [char] (15)   NULL ,
	[FSBGTR] [int] NULL ,
	[MASMERID] [int] NULL ,
	[BUTCEID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[HSPKILIT] (
	[HSPKILITID] [int] NOT NULL ,
	[HSPKODUBAS] [nvarchar] (40)   NOT NULL ,
	[HSPKODUSON] [nvarchar] (40)   NOT NULL ,
	[KILITTARIHI] [datetime] NOT NULL ,
	[KAYDEDEN] [nvarchar] (15)   NOT NULL ,
	[KAYITTARIHI] [datetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[IRSALIYE] (
	[IRSCOUNTER] [int] NULL ,
	[IRSID] [int] IDENTITY (1, 1) NOT NULL ,
	[IRSALIYENO] [nvarchar] (30)   NULL ,
	[TUR] [nvarchar] (10)   NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[DEPOID] [int] NULL ,
	[CARIID] [int] NULL ,
	[UNVANI] [nvarchar] (200)   NULL ,
	[DOVIZ] [nvarchar] (10)   NULL ,
	[DOVIZKURU] [float] NULL ,
	[SAAT] [datetime] NULL ,
	[IRSTARIH] [datetime] NULL ,
	[SEVKTARIH] [datetime] NULL ,
	[VADEGUN] [int] NULL ,
	[VADETARIH] [datetime] NULL ,
	[ACIKLAMA] [nvarchar] (255)   NULL ,
	[ADRES1] [nvarchar] (100)   NULL ,
	[ADRES2] [nvarchar] (100)   NULL ,
	[ADRES3] [nvarchar] (100)   NULL ,
	[VD] [nvarchar] (30)   NULL ,
	[VDNO] [nvarchar] (20)   NULL ,
	[YETKILI] [nvarchar] (60)   NULL ,
	[TOPLAM] [float] NULL ,
	[KDV] [float] NULL ,
	[SIND] [float] NULL ,
	[GTOPLAM] [float] NULL ,
	[EK1] [float] NULL ,
	[EK2] [float] NULL ,
	[EK3] [float] NULL ,
	[EKORAN1] [float] NULL ,
	[EKORAN2] [float] NULL ,
	[EKORAN3] [float] NULL ,
	[IND1] [float] NULL ,
	[IND2] [float] NULL ,
	[IND3] [float] NULL ,
	[INDORAN1] [float] NULL ,
	[INDORAN2] [float] NULL ,
	[INDORAN3] [float] NULL ,
	[FATCOUNTER] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[IRSDETAY] (
	[FATSTRID] [int] IDENTITY (1, 1) NOT NULL ,
	[IRSCOUNTER] [int] NULL ,
	[STOKID] [int] NULL ,
	[KODU] [nvarchar] (50)   NULL ,
	[ACIKLAMA] [nvarchar] (150)   NULL ,
	[ADET] [float] NULL ,
	[BFIYAT] [float] NULL ,
	[KDV] [float] NULL ,
	[SATIRIND] [float] NULL ,
	[SATIRIND2] [float] NULL ,
	[HESAPID] [int] NULL ,
	[IRSBIRIM] [nvarchar] (20)   NULL ,
	[IRSADET] [float] NULL ,
	[IRSBFIYAT] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[LANG] (
	[LANG] [nvarchar] (15)   NULL ,
	[SENTENCE] [nvarchar] (100)   NULL ,
	[TRANSLATION] [nvarchar] (100)   NULL ,
	[LANGID] [int] IDENTITY (1, 1) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[LOG] (
	[LOGID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[SAAT] [nvarchar] (11)   NULL ,
	[USER] [nvarchar] (15)   NULL ,
	[ISLEM] [nvarchar] (10)   NULL ,
	[TABLE] [nvarchar] (20)   NULL ,
	[ICERIK1] [ntext]   NULL ,
	[KAYITNO] [nvarchar] (25)   NULL ,
	[DEGISIKLIK] [nvarchar] (100)   NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[MALITABLO] (
	[MALIID] [int] NOT NULL ,
	[HESAPID] [int] NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[ONCEKIDONEMBAS] [float] NULL ,
	[CARIDONEMBAS] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MALITABLOLAR] (
	[TABLOID] [int] IDENTITY (1, 1) NOT NULL ,
	[TUR] [nvarchar] (100)   NULL ,
	[ACIKLAMA] [nvarchar] (255)   NULL ,
	[KODU] [nvarchar] (40)   NULL ,
	[GRUPKODU] [smallint] NOT NULL ,
	[MIZAN] [nvarchar] (1)   NULL ,
	[BA] [nvarchar] (1)   NULL ,
	[BTUTAR] [float] NULL ,
	[ATUTAR] [float] NULL ,
	[SKODU] [nvarchar] (20)   NULL ,
	[HESAPID] [int] NULL ,
	[CDBTUTAR] [float] NULL ,
	[CDATUTAR] [float] NULL ,
	[SIRANO] [nvarchar] (5)   NULL ,
	[SATIRNO] [nvarchar] (5)   NULL ,
	[USTGRUP] [nvarchar] (5)   NULL ,
	[BOLUMNO] [nvarchar] (5)   NULL ,
	[GRTOP1] [float] NULL ,
	[GRTOP2] [float] NULL ,
	[EORDER] [int] NULL ,
	[ACIKLAING] [nvarchar] (255)   NULL ,
	[ACIKLABOS] [nvarchar] (255)   NULL ,
	[FMIS] [nvarchar] (1)   NULL ,
	[FORMUL] [nvarchar] (30)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MALITABLOSABLON] (
	[TABLOID] [int] IDENTITY (1, 1) NOT NULL ,
	[TUR] [nvarchar] (100)   NULL ,
	[ACIKLAMA] [nvarchar] (255)   NULL ,
	[KODU] [nvarchar] (40)   NULL ,
	[GRUPKODU] [smallint] NOT NULL ,
	[MIZAN] [nvarchar] (1)   NULL ,
	[BA] [nvarchar] (1)   NULL ,
	[BTUTAR] [float] NULL ,
	[ATUTAR] [float] NULL ,
	[SKODU] [nvarchar] (20)   NULL ,
	[HESAPID] [int] NULL ,
	[CDBTUTAR] [float] NULL ,
	[CDATUTAR] [float] NULL ,
	[SIRANO] [nvarchar] (5)   NULL ,
	[SATIRNO] [nvarchar] (5)   NULL ,
	[USTGRUP] [nvarchar] (5)   NULL ,
	[BOLUMNO] [nvarchar] (5)   NULL ,
	[GRTOP1] [float] NULL ,
	[GRTOP2] [float] NULL ,
	[EORDER] [int] NULL ,
	[ACIKLAING] [nvarchar] (255)   NULL ,
	[ACIKLABOS] [nvarchar] (255)   NULL ,
	[FMIS] [nvarchar] (1)   NULL ,
	[FORMUL] [nvarchar] (30)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MANUAL] (
	[KONUID] [int] IDENTITY (1, 1) NOT NULL ,
	[KONUNO] [nvarchar] (15)   NULL ,
	[KONU] [nvarchar] (255)   NULL ,
	[SAYFANO] [numeric](18, 0) NULL ,
	[METIN] [ntext]   NULL ,
	[RESIM] [image] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[MASMER] (
	[MASMERID] [int] NOT NULL ,
	[KODU] [nvarchar] (40)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[GRUBU] [varchar] (25)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MESAJ] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[OKUNDU] [bit] NOT NULL ,
	[GONDEREN] [nvarchar] (5)   NULL ,
	[ALAN] [nvarchar] (5)   NULL ,
	[MESAJ] [ntext]   NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[MTABLOAD] (
	[MTID] [int] IDENTITY (1, 1) NOT NULL ,
	[TABLOADI] [nvarchar] (255)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MUST] (
	[MUSTID] [int] NOT NULL ,
	[ADISOYADI] [nvarchar] (25)   NULL ,
	[DYERI] [nvarchar] (15)   NULL ,
	[BABAADI] [nvarchar] (15)   NULL ,
	[DTARIHI] [smalldatetime] NULL ,
	[CINSIYETI] [nvarchar] (1)   NULL ,
	[YAZISMA] [nvarchar] (2)   NULL ,
	[NOT] [nvarchar] (15)   NULL ,
	[FIRMA] [nvarchar] (15)   NULL ,
	[ISADRES] [nvarchar] (55)   NULL ,
	[ISADRES2] [nvarchar] (40)   NULL ,
	[ISADRES3] [nvarchar] (20)   NULL ,
	[ISPKODU] [nvarchar] (7)   NULL ,
	[VD] [nvarchar] (25)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[ISTEL] [nvarchar] (14)   NULL ,
	[ISTEL2] [nvarchar] (14)   NULL ,
	[ISTEL3] [nvarchar] (14)   NULL ,
	[ISFAXNO] [nvarchar] (14)   NULL ,
	[CEPTEL] [nvarchar] (14)   NULL ,
	[EVADRES] [nvarchar] (40)   NULL ,
	[EVADRES2] [nvarchar] (40)   NULL ,
	[EVADRES3] [nvarchar] (20)   NULL ,
	[EVPKODU] [nvarchar] (50)   NULL ,
	[EVTEL] [nvarchar] (14)   NULL ,
	[EVFAX] [nvarchar] (14)   NULL ,
	[GRUBU] [nvarchar] (10)   NULL ,
	[GOREVI] [nvarchar] (15)   NULL ,
	[ARACTEL] [nvarchar] (14)   NULL ,
	[VDNO] [nvarchar] (15)   NULL ,
	[ESIADI] [nvarchar] (15)   NULL ,
	[COCUK1] [nvarchar] (15)   NULL ,
	[COCUK2] [nvarchar] (15)   NULL ,
	[EVLILIKT] [smalldatetime] NULL ,
	[SAC] [nvarchar] (10)   NULL ,
	[BOY] [int] NULL ,
	[KILO] [int] NULL ,
	[HASTALIKLAR] [nvarchar] (50)   NULL ,
	[KANGRUBU] [nvarchar] (7)   NULL ,
	[KODU] [nvarchar] (10)   NULL ,
	[KREDIKARTNO] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MUSTISL] (
	[MUTSISLID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[ACOUNTER] [float] NULL ,
	[DEPT] [nvarchar] (25)   NULL ,
	[ENO] [nvarchar] (25)   NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[MUSTID] [int] NULL ,
	[SAAT] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[PANDEPTGG] (
	[PANTYPE] [nvarchar] (10)   NOT NULL ,
	[DEPT] [nvarchar] (10)   NOT NULL ,
	[GELIRGRUBU] [nvarchar] (10)   NOT NULL ,
	[ORAN] [float] NULL ,
	[PANDEPTGGID] [int] NOT NULL ,
	[HESAPID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[PLAN] (
	[PLANID] [int] IDENTITY (1, 1) NOT NULL ,
	[VADE] [smalldatetime] NULL ,
	[KKODU] [nvarchar] (25)   NULL ,
	[CARIID] [int] NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[ACIKLAMA2] [nvarchar] (100)   NULL ,
	[ACIKLAMA3] [nvarchar] (100)   NULL ,
	[TARIH] [smalldatetime] NULL ,
	[EK1] [nvarchar] (50)   NULL ,
	[EK2] [nvarchar] (50)   NULL ,
	[EK3] [nvarchar] (50)   NULL ,
	[GRUP] [nvarchar] (20)   NULL ,
	[ENO] [nvarchar] (15)   NULL ,
	[CEKID] [int] NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[ODENDI] [bit] NULL ,
	[CEKSENETID] [int] NULL ,
	[FATID] [int] NULL ,
	[TAMAMLANDI] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[RECETE] (
	[RECETEID] [int] IDENTITY (1, 1) NOT NULL ,
	[URUNID] [int] NOT NULL ,
	[STOKID] [int] NOT NULL ,
	[ORAN] [float] NULL ,
	[FIRE] [float] NULL ,
	[AKTARID] [int] NULL ,
	[XBIRIM] [nvarchar] (10)   NULL ,
	[STOKKODU] [nvarchar] (10)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[REHBER] (
	[COUNTER] [int] IDENTITY (1, 1) NOT NULL ,
	[ADISOYADI] [nvarchar] (25)   NULL ,
	[DYERI] [nvarchar] (15)   NULL ,
	[BABAADI] [nvarchar] (15)   NULL ,
	[DTARIHI] [smalldatetime] NULL ,
	[CINSIYETI] [nvarchar] (1)   NULL ,
	[YAZISMA] [nvarchar] (2)   NULL ,
	[NOT] [nvarchar] (15)   NULL ,
	[FIRMA] [nvarchar] (15)   NULL ,
	[ISADRES] [nvarchar] (55)   NULL ,
	[ISADRES2] [nvarchar] (40)   NULL ,
	[ISADRES3] [nvarchar] (20)   NULL ,
	[ISPKODU] [nvarchar] (7)   NULL ,
	[VD] [nvarchar] (25)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[ISTEL] [nvarchar] (14)   NULL ,
	[ISTEL2] [nvarchar] (14)   NULL ,
	[ISTEL3] [nvarchar] (14)   NULL ,
	[ISFAXNO] [nvarchar] (14)   NULL ,
	[CEPTEL] [nvarchar] (14)   NULL ,
	[EVADRES] [nvarchar] (40)   NULL ,
	[EVADRES2] [nvarchar] (40)   NULL ,
	[EVADRES3] [nvarchar] (20)   NULL ,
	[EVPKODU] [nvarchar] (50)   NULL ,
	[EVTEL] [nvarchar] (14)   NULL ,
	[EVFAX] [nvarchar] (14)   NULL ,
	[GRUBU] [nvarchar] (10)   NULL ,
	[GOREVI] [nvarchar] (15)   NULL ,
	[ARACTEL] [nvarchar] (14)   NULL ,
	[VDNO] [nvarchar] (15)   NULL ,
	[ESIADI] [nvarchar] (15)   NULL ,
	[COCUK1] [nvarchar] (15)   NULL ,
	[COCUK2] [nvarchar] (15)   NULL ,
	[EVLILIKT] [smalldatetime] NULL ,
	[SAC] [nvarchar] (10)   NULL ,
	[BOY] [int] NULL ,
	[KILO] [int] NULL ,
	[HASTALIKLAR] [nvarchar] (50)   NULL ,
	[KANGRUBU] [nvarchar] (7)   NULL ,
	[KODU] [nvarchar] (10)   NULL ,
	[KREDIKARTNO] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[REHBERISL] (
	[ISLEMID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[ACOUNTER] [float] NULL ,
	[DEPT] [nvarchar] (25)   NULL ,
	[ENO] [nvarchar] (25)   NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[REHBERID] [int] NULL ,
	[SAAT] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SATICI] (
	[KODU] [nvarchar] (15)   NOT NULL ,
	[UNVANI] [nvarchar] (50)   NULL ,
	[ADRES1] [nvarchar] (80)   NULL ,
	[ADRES2] [nvarchar] (80)   NULL ,
	[TEL] [nvarchar] (15)   NULL ,
	[FAX] [nvarchar] (15)   NULL ,
	[YETKILI] [nvarchar] (25)   NULL ,
	[VD] [nvarchar] (15)   NULL ,
	[VDNO] [nvarchar] (15)   NULL ,
	[MUHKODU] [nvarchar] (40)   NULL ,
	[VADE] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SATICISL] (
	[COUNTER] [int] IDENTITY (1, 1) NOT NULL ,
	[KODU] [nvarchar] (15)   NOT NULL ,
	[TARIH] [smalldatetime] NOT NULL ,
	[ENO] [nvarchar] (15)   NULL ,
	[USERK] [nvarchar] (15)   NULL ,
	[NOT] [nvarchar] (80)   NULL ,
	[DBORC] [float] NULL ,
	[DALACAK] [float] NULL ,
	[BORC] [float] NULL ,
	[ALACAK] [float] NULL ,
	[FISCOUNTER] [float] NULL ,
	[VADE] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SATINALMA] (
	[SATINALMAID] [int] NOT NULL ,
	[DURUM] [nvarchar] (15)   NULL ,
	[ISTEKTARIH] [datetime] NULL ,
	[ISTEYEN] [nvarchar] (50)   NULL ,
	[ONAYTARIH] [datetime] NULL ,
	[ONAYLAYAN] [nvarchar] (50)   NULL ,
	[SATINALMATARIH] [datetime] NULL ,
	[IPTALTARIH] [datetime] NULL ,
	[DEPOYETKILISI] [nvarchar] (15)   NULL ,
	[SATINALMACI] [nvarchar] (15)   NULL ,
	[DEPARTMANSEFI] [nvarchar] (15)   NULL ,
	[DEPARTMAN] [nvarchar] (15)   NULL ,
	[TOPLAM] [float] NULL ,
	[ACIKLAMA] [nvarchar] (250)   NULL ,
	[OZELKOD1] [nvarchar] (50)   NULL ,
	[OZELKOD2] [nvarchar] (50)   NULL ,
	[OZELKOD3] [nvarchar] (50)   NULL ,
	[FIRMAKODU] [nvarchar] (15)   NULL ,
	[ENO] [nvarchar] (15)   NULL ,
	[ONAYLAYAN1] [nvarchar] (50)   NULL ,
	[ONAYTARIH1] [datetime] NULL ,
	[ONAYLAYAN2] [nvarchar] (50)   NULL ,
	[ONAYTARIH2] [datetime] NULL ,
	[ONAYLAYAN3] [nvarchar] (50)   NULL ,
	[ONAYTARIH3] [datetime] NULL ,
	[ONAYLAYAN4] [nvarchar] (50)   NULL ,
	[ONAYTARIH4] [datetime] NULL ,
	[ONAYLAYAN5] [nvarchar] (50)   NULL ,
	[ONAYTARIH5] [datetime] NULL ,
	[SATSTATU] [int] NULL ,
	[NOTLAR1] [nvarchar] (50)   NULL ,
	[NOTLAR2] [nvarchar] (50)   NULL ,
	[NOTLAR3] [nvarchar] (50)   NULL ,
	[NOTLAR4] [nvarchar] (50)   NULL ,
	[NOTLAR5] [nvarchar] (50)   NULL ,
	[SIPARISTARIH] [datetime] NULL ,
	[SKODU] [varchar] (10)   NULL ,
	[FIRMAID] [int] NULL ,
	[DEPOID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SATINALMAISL] (
	[TT] [char] (10)   NULL ,
	[SATISLID] [int] IDENTITY (1, 1) NOT NULL ,
	[SKODU] [nvarchar] (50)   NULL ,
	[SADI] [nvarchar] (50)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[SONSATAN] [nvarchar] (50)   NULL ,
	[SONTARIH] [datetime] NULL ,
	[SATINALMAID] [int] NULL ,
	[FIRMAKODU] [nvarchar] (15)   NULL ,
	[BIRIM] [nvarchar] (15)   NULL ,
	[MIKTAR] [float] NULL ,
	[BFIYAT] [float] NULL ,
	[DEPOMEVCUT] [float] NULL ,
	[SONFIYAT] [float] NULL ,
	[SONADET] [float] NULL ,
	[SNO] [nvarchar] (50)   NULL ,
	[FIRMA1] [nvarchar] (20)   NULL ,
	[FIYAT1] [float] NULL ,
	[FIRMA2] [nvarchar] (20)   NULL ,
	[FIYAT2] [float] NULL ,
	[FIRMA3] [nvarchar] (20)   NULL ,
	[FIYAT3] [float] NULL ,
	[TEMIKTAR] [int] NULL ,
	[ANLASMANO] [nvarchar] (50)   NULL ,
	[STOKID] [int] NULL ,
	[S_MIKTAR] [float] NULL ,
	[S_TEMIKTAR] [float] NULL ,
	[S_DEPOMEVCUT] [float] NULL ,
	[FIRMAID] [int] NULL ,
	[S_BEKLENENFIYAT] [float] NULL ,
	[TAMAMLANDI] [smallint] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SATIST] (
	[SATISID] [int] IDENTITY (1, 1) NOT NULL ,
	[SATIST] [nvarchar] (50)   NULL ,
	[SKOMORAN] [float] NULL ,
	[SKOMORAN2] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SAYACLAR] (
	[TABLENAME] [nvarchar] (50)   NOT NULL ,
	[SIRANO] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SBIRIM] (
	[BIRIMID] [int] IDENTITY (1, 1) NOT NULL ,
	[BIRIM] [nvarchar] (15)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SDEPO] (
	[SDEPOID] [int] NULL ,
	[DEPOID] [int] NULL ,
	[STOKID] [int] NULL ,
	[STOKADI] [nvarchar] (100)   NULL ,
	[DEPOADI] [nvarchar] (50)   NULL ,
	[ASGARI] [float] NULL ,
	[OPTIMAL] [float] NULL ,
	[DEVIR] [float] NULL ,
	[GIREN] [float] NULL ,
	[CIKAN] [float] NULL ,
	[BAKIYE] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SFIYATIND] (
	[SFIYATINDID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIHB] [datetime] NULL ,
	[TARIHS] [datetime] NULL ,
	[SGRUP] [nvarchar] (10)   NULL ,
	[INDY] [float] NULL ,
	[CARIID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SIPNOT] (
	[SIPID] [int] IDENTITY (1, 1) NOT NULL ,
	[TARIH] [smalldatetime] NULL ,
	[SAAT] [smalldatetime] NULL ,
	[BILDIREN] [nvarchar] (15)   NULL ,
	[MUSTERI] [nvarchar] (50)   NULL ,
	[ADRES] [nvarchar] (50)   NULL ,
	[TEL] [nvarchar] (20)   NULL ,
	[SIPARIS] [nvarchar] (255)   NULL ,
	[ODEME] [nvarchar] (10)   NULL ,
	[STATU] [nvarchar] (10)   NULL ,
	[TTARIH] [smalldatetime] NULL ,
	[TSAAT] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SMMAKBUZ] (
	[SMMAKBUZID] [int] NOT NULL ,
	[CARIID] [int] NOT NULL ,
	[BELGENO] [nvarchar] (50)   NULL ,
	[TARIH] [smalldatetime] NOT NULL ,
	[CARIADI] [nvarchar] (50)   NULL ,
	[CARIADRES] [nvarchar] (255)   NULL ,
	[STOPAJYUZDE] [decimal](5, 2) NOT NULL ,
	[KDVYUZDE] [decimal](5, 2) NOT NULL ,
	[STOPAJTUTAR] [decimal](19, 2) NOT NULL ,
	[BRUTUCRET] [decimal](19, 2) NOT NULL ,
	[NETUCRET] [decimal](19, 2) NOT NULL ,
	[ALINANTOPLAM] [decimal](19, 2) NOT NULL ,
	[DOVIZKODU] [nvarchar] (20)   NULL ,
	[ACIKLAMA] [nvarchar] (255)   NULL ,
	[KDVTUTAR] [decimal](19, 2) NOT NULL ,
	[DURUM] [int] NOT NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[HIZMETTURU] [nvarchar] (30)   NULL ,
	[MLYTHESAPID] [int] NOT NULL ,
	[KAYDEDEN] [nvarchar] (15)   NOT NULL ,
	[MUHFC] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SSAYIM] (
	[SAYIMID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEPOID] [int] NOT NULL ,
	[STOKID] [int] NOT NULL ,
	[BASTARIH] [smalldatetime] NULL ,
	[TARIH] [smalldatetime] NULL ,
	[GADET] [float] NULL ,
	[CADET] [float] NULL ,
	[ORTFIYAT] [float] NULL ,
	[DEVIR] [float] NULL ,
	[ALIS] [float] NULL ,
	[IADE] [float] NULL ,
	[GIREN] [float] NULL ,
	[CIKAN] [float] NULL ,
	[ATRANS] [float] NULL ,
	[ETRANS] [float] NULL ,
	[TUKETIM] [float] NULL ,
	[ARTIFARK] [float] NULL ,
	[EKSIFARK] [float] NULL ,
	[ZAYI] [float] NULL ,
	[SAYIM] [float] NULL ,
	[DEVIRT] [float] NULL ,
	[ALIST] [float] NULL ,
	[IADET] [float] NULL ,
	[GIRENT] [float] NULL ,
	[CIKANT] [float] NULL ,
	[ATRANST] [float] NULL ,
	[ETRANST] [float] NULL ,
	[ARTIFARKT] [float] NULL ,
	[EKSIFARKT] [float] NULL ,
	[TUKETIMT] [float] NULL ,
	[ZAYIT] [float] NULL ,
	[SKODU] [nvarchar] (10)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SSAYIMARV] (
	[BASTARIH] [smalldatetime] NOT NULL ,
	[TARIH] [smalldatetime] NOT NULL ,
	[DEVIRT] [float] NULL ,
	[MALIYETT] [float] NULL ,
	[SAYIMT] [float] NULL ,
	[DURUM] [smallint] NOT NULL ,
	[KAPANDI] [smallint] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SSAYIMLAR] (
	[SAYIMID] [int] IDENTITY (1, 1) NOT NULL ,
	[DEPOID] [int] NULL ,
	[STOKID] [int] NULL ,
	[BASTARIH] [smalldatetime] NULL ,
	[TARIH] [smalldatetime] NULL ,
	[GADET] [float] NULL ,
	[CADET] [float] NULL ,
	[ORTFIYAT] [float] NULL ,
	[DEVIR] [float] NULL ,
	[ALIS] [float] NULL ,
	[IADE] [float] NULL ,
	[GIREN] [float] NULL ,
	[CIKAN] [float] NULL ,
	[ATRANS] [float] NULL ,
	[ETRANS] [float] NULL ,
	[TUKETIM] [float] NULL ,
	[ARTIFARK] [float] NULL ,
	[EKSIFARK] [float] NULL ,
	[ZAYI] [float] NULL ,
	[SAYIM] [float] NULL ,
	[DEVIRT] [float] NULL ,
	[ALIST] [float] NULL ,
	[IADET] [float] NULL ,
	[GIRENT] [float] NULL ,
	[CIKANT] [float] NULL ,
	[ATRANST] [float] NULL ,
	[ETRANST] [float] NULL ,
	[ARTIFARKT] [float] NULL ,
	[EKSIFARKT] [float] NULL ,
	[TUKETIMT] [float] NULL ,
	[ZAYIT] [float] NULL ,
	[SKODU] [nvarchar] (10)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STANAFIRMA] (
	[ANAFIRMAID] [int] NOT NULL ,
	[UNVANI] [nvarchar] (100)   NULL ,
	[ADRES] [nvarchar] (250)   NULL ,
	[SEHIR] [nvarchar] (20)   NULL ,
	[ULKE] [nvarchar] (20)   NULL ,
	[TEL1] [nvarchar] (25)   NULL ,
	[TEL2] [nvarchar] (25)   NULL ,
	[FAX] [nvarchar] (25)   NULL ,
	[GSM] [nvarchar] (25)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[WEB] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STFIRMA] (
	[FIRMAID] [int] NOT NULL ,
	[UNVANI] [nvarchar] (100)   NULL ,
	[ADRES] [nvarchar] (250)   NULL ,
	[SEHIR] [nvarchar] (20)   NULL ,
	[BOLGE] [nvarchar] (50)   NULL ,
	[ULKE] [nvarchar] (20)   NULL ,
	[TEL1] [nvarchar] (25)   NULL ,
	[TEL2] [nvarchar] (25)   NULL ,
	[FAX] [nvarchar] (25)   NULL ,
	[GSM] [nvarchar] (25)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[WEB] [nvarchar] (50)   NULL ,
	[MARKET] [nvarchar] (50)   NULL ,
	[HCIRO] [float] NULL ,
	[CSARTLARI] [nvarchar] (250)   NULL ,
	[TDURUM] [bit] NULL ,
	[GRUPKODU] [nvarchar] (25)   NULL ,
	[INDURUN] [float] NULL ,
	[INDODA] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STGORUSME] (
	[GORUSMEID] [int] NOT NULL ,
	[TARIH] [datetime] NULL ,
	[SAAT] [datetime] NULL ,
	[STEMSILCIID] [int] NULL ,
	[YETKILIID] [int] NULL ,
	[STAKIPID] [int] NULL ,
	[YER] [nvarchar] (50)   NULL ,
	[TUR] [nvarchar] (50)   NULL ,
	[OZET] [ntext]   NULL ,
	[DURUM] [nvarchar] (10)   NULL ,
	[RANDEVU] [bit] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[STKAYNAK] (
	[KAYNAK] [nvarchar] (15)   NOT NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STKONTRAT] (
	[KONTRATID] [int] NOT NULL ,
	[TARIH] [datetime] NULL ,
	[YETKILIID] [int] NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[TUTAR] [float] NULL ,
	[ENO] [nvarchar] (50)   NULL ,
	[DOSYAADI] [nvarchar] (255)   NULL ,
	[STAKIPID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STMARKET] (
	[MARKET] [nvarchar] (15)   NOT NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STMETIN] (
	[METINKODU] [nvarchar] (50)   NOT NULL ,
	[TURU] [nvarchar] (50)   NULL ,
	[ICERIK] [ntext]   NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[STOK] (
	[STOKID] [int] NOT NULL ,
	[GRUP] [nvarchar] (10)   NULL ,
	[BARKOD] [nvarchar] (20)   NULL ,
	[KODU] [nvarchar] (20)   NULL ,
	[ADI] [nvarchar] (50)   NULL ,
	[SSATICI] [int] NULL ,
	[SALISFIYAT] [float] NULL ,
	[SFATURANO] [nvarchar] (20)   NULL ,
	[SFATTARIHI] [smalldatetime] NULL ,
	[SFIYAT1] [float] NULL ,
	[SFIYAT2] [float] NULL ,
	[SFIYAT3] [float] NULL ,
	[SFIYAT4] [float] NULL ,
	[SFIYAT5] [float] NULL ,
	[SDOVIZ] [nvarchar] (10)   NULL ,
	[AMIKTAR] [float] NULL ,
	[OPTMIKTAR] [float] NULL ,
	[ROMRU] [nvarchar] (20)   NULL ,
	[RNO] [nvarchar] (20)   NULL ,
	[EK1] [nvarchar] (50)   NULL ,
	[EK2] [nvarchar] (50)   NULL ,
	[EK3] [nvarchar] (50)   NULL ,
	[EK4] [nvarchar] (50)   NULL ,
	[EK5] [nvarchar] (50)   NULL ,
	[ALISKDV] [float] NULL ,
	[SATISKDV] [float] NULL ,
	[ETIKETTIPI] [smallint] NULL ,
	[BIRIM] [nvarchar] (15)   NULL ,
	[BIRIM2] [nvarchar] (15)   NULL ,
	[KATSAYI2] [float] NULL ,
	[BIRIM3] [nvarchar] (15)   NULL ,
	[KATSAYI3] [float] NULL ,
	[BIRIM4] [nvarchar] (15)   NULL ,
	[KATSAYI4] [float] NULL ,
	[SAKLA] [int] NULL ,
	[SKOMORAN] [float] NULL ,
	[BKOMORAN] [float] NULL ,
	[ALISIND] [float] NULL ,
	[SATISIND] [float] NULL ,
	[NAKLIYE] [float] NULL ,
	[SKARY] [float] NULL ,
	[BARKOD2] [nvarchar] (20)   NULL ,
	[BARKOD3] [nvarchar] (20)   NULL ,
	[BARKOD4] [nvarchar] (20)   NULL ,
	[TURU] [nvarchar] (10)   NULL ,
	[URETDEPOID] [int] NULL ,
	[BEKLALISFIYAT] [float] NULL ,
	[SFIYAT1KDV] [bit] NULL ,
	[SFIYAT2KDV] [bit] NULL ,
	[SFIYAT3KDV] [bit] NULL ,
	[SFIYAT4KDV] [bit] NULL ,
	[SFIYAT5KDV] [bit] NULL ,
	[MALIYET] [float] NULL ,
	[HYERI] [smallint] NULL ,
	[AI] [bit] NULL ,
	[INDGRUP] [smallint] NULL ,
	[SDEPART] [nvarchar] (255)   NULL ,
	[UAI] [bit] NULL ,
	[GGRUP] [nvarchar] (5)   NULL ,
	[ODENMEZ] [bit] NULL ,
	[HLISTE] [bit] NULL ,
	[GADET] [float] NULL ,
	[HEDEFCOST] [float] NULL ,
	[POSTURU] [nvarchar] (1)   NULL ,
	[KDV] [int] NULL ,
	[OPTIMAL] [float] NULL ,
	[ASGARI] [float] NULL ,
	[RAFNO] [nvarchar] (15)   NULL ,
	[RAFOMRU] [nvarchar] (15)   NULL ,
	[OZELKOD1] [nvarchar] (30)   NULL ,
	[OZELKOD2] [nvarchar] (30)   NULL ,
	[OZELKOD3] [nvarchar] (30)   NULL ,
	[EKKOD] [nvarchar] (15)   NULL ,
	[SONALISF] [float] NULL ,
	[SONSATICI] [nvarchar] (30)   NULL ,
	[ALISTARIH] [datetime] NULL ,
	[SFIYAT] [float] NULL ,
	[SONKULLANMA] [datetime] NULL ,
	[ABUFE] [bit] NULL ,
	[KISISAYISI] [float] NULL ,
	[RECETEBIRIMI] [nvarchar] (15)   NULL ,
	[RECETEKATSAYISI] [float] NULL ,
	[SAYIMDURUMU] [int] NULL ,
	[UHHOUR] [bit] NULL ,
	[EKBILGI] [nvarchar] (1000)   NULL ,
	[COSTFACTOR] [float] NULL ,
	[VARSAYILANBIRIM] [smallint] NULL ,
	[ALISBIRIMNO] [tinyint] NULL ,
	[SATISBIRIMNO] [tinyint] NULL ,
	[SONKT] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STOKGRUP] (
	[KODU] [nvarchar] (10)   NOT NULL ,
	[ADI] [nvarchar] (100)   NULL ,
	[MUHKODU] [nvarchar] (50)   NULL ,
	[OZELKOD1] [nvarchar] (50)   NULL ,
	[SAKLA] [int] NULL ,
	[MUHNHESAPID] [int] NULL ,
	[MUHSHESAPID] [int] NULL ,
	[MUHGHESAPID] [int] NULL ,
	[TURU] [nvarchar] (10)   NULL ,
	[ANAGRUPUZUNLUGU] [tinyint] NULL ,
	[ALTGRUPUZUNLUGU] [tinyint] NULL ,
	[ALT2GRUPUZUNLUGU] [tinyint] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STOKTURU] (
	[TURID] [int] IDENTITY (1, 1) NOT NULL ,
	[TUR] [nvarchar] (10)   NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STRAKIP] (
	[RAKIPKODU] [nvarchar] (15)   NULL ,
	[UNVANI] [nvarchar] (50)   NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STSTAKIP] (
	[STAKIPID] [int] NOT NULL ,
	[URUNGRUBU] [nvarchar] (50)   NULL ,
	[ANAFIRMAID] [int] NULL ,
	[FIRMAID] [int] NULL ,
	[YETKILIID] [int] NULL ,
	[STEMSILCIID] [int] NULL ,
	[BTARIH] [datetime] NULL ,
	[STARIH] [datetime] NULL ,
	[KAYNAK] [nvarchar] (50)   NULL ,
	[SGERC] [int] NULL ,
	[DOVIZ] [nvarchar] (15)   NULL ,
	[PSTUTAR] [float] NULL ,
	[DURUM] [nvarchar] (10)   NULL ,
	[ACIKLAMA] [ntext]   NULL ,
	[PROJEADI] [nvarchar] (50)   NULL ,
	[KARARTARIHI] [datetime] NULL ,
	[ENGECTARIH] [datetime] NULL ,
	[SONGORUSME] [datetime] NULL ,
	[TEKRARARA] [datetime] NULL ,
	[MARKET] [nvarchar] (50)   NULL ,
	[ULKE] [nvarchar] (15)   NULL ,
	[TKNO] [int] NULL ,
	[ODA] [char] (10)   NULL ,
	[KISI] [char] (10)   NULL ,
	[REZBAS] [datetime] NULL ,
	[REZSON] [datetime] NULL ,
	[ACIKLAMA2] [ntext]   NULL ,
	[RAKIPLER] [nvarchar] (50)   NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[STSTEMSILCI] (
	[STEMSILCIID] [int] NOT NULL ,
	[ADSOYAD] [nvarchar] (100)   NULL ,
	[ADRES] [nvarchar] (250)   NULL ,
	[SEHIR] [nvarchar] (20)   NULL ,
	[ULKE] [nvarchar] (20)   NULL ,
	[TEL1] [nvarchar] (25)   NULL ,
	[TEL2] [nvarchar] (25)   NULL ,
	[FAX] [nvarchar] (25)   NULL ,
	[GSM] [nvarchar] (25)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[WEB] [nvarchar] (50)   NULL ,
	[TAHSIL] [nvarchar] (50)   NULL ,
	[TECRUBE] [nvarchar] (150)   NULL ,
	[POZISYON] [nvarchar] (50)   NULL ,
	[KOMORAN] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STTEKLIF] (
	[TEKLIFID] [int] NOT NULL ,
	[TARIH] [datetime] NULL ,
	[YETKILIID] [int] NULL ,
	[ACIKLAMA] [nvarchar] (100)   NULL ,
	[TUTAR] [float] NULL ,
	[SONUC] [nvarchar] (50)   NULL ,
	[ENO] [nvarchar] (50)   NULL ,
	[DOSYAADI] [nvarchar] (255)   NULL ,
	[DURUM] [nvarchar] (10)   NULL ,
	[STAKIPID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STURUN] (
	[URUNKODU] [nvarchar] (10)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[STYETKILI] (
	[YETKILIID] [int] NOT NULL ,
	[ADI] [nvarchar] (50)   NULL ,
	[SOYADI] [nvarchar] (50)   NULL ,
	[FIRMAID] [int] NULL ,
	[DEPARTMAN] [nvarchar] (15)   NULL ,
	[UNVANI] [nvarchar] (15)   NULL ,
	[GOREVI] [nvarchar] (50)   NULL ,
	[HITAP] [nvarchar] (15)   NULL ,
	[ADRES] [nvarchar] (250)   NULL ,
	[SEHIR] [nvarchar] (20)   NULL ,
	[ULKE] [nvarchar] (20)   NULL ,
	[TEL1] [nvarchar] (25)   NULL ,
	[TEL2] [nvarchar] (25)   NULL ,
	[DAHILI] [nvarchar] (8)   NULL ,
	[FAX] [nvarchar] (25)   NULL ,
	[GSM] [nvarchar] (25)   NULL ,
	[EMAIL] [nvarchar] (50)   NULL ,
	[EMAIL2] [nvarchar] (50)   NULL ,
	[AKTIF] [int] NULL ,
	[KARARGUCU] [int] NULL ,
	[URUNILGISI] [nvarchar] (50)   NULL ,
	[ACTIONCODE] [nvarchar] (50)   NULL ,
	[YASGUNU] [datetime] NULL ,
	[MARKET] [nvarchar] (50)   NULL ,
	[EK1] [nvarchar] (50)   NULL ,
	[EK2] [nvarchar] (50)   NULL ,
	[EK3] [nvarchar] (50)   NULL ,
	[EK4] [nvarchar] (50)   NULL ,
	[EK5] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SUBELER] (
	[SUBEID] [int] IDENTITY (1, 1) NOT NULL ,
	[SUBEKODU] [nvarchar] (10)   NULL ,
	[SUBEADI] [nvarchar] (50)   NULL ,
	[TEL] [nvarchar] (20)   NULL ,
	[FAX] [nvarchar] (20)   NULL ,
	[ADRES1] [nvarchar] (50)   NULL ,
	[ADRES2] [nvarchar] (50)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TAKVIM] (
	[TARIH] [smalldatetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TALEPFIS] (
	[TALEPFISID] [int] NOT NULL ,
	[TARIH] [datetime] NOT NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ISLEM] [nvarchar] (10)   NOT NULL ,
	[ENO] [nvarchar] (10)   NULL ,
	[ACIKLAMA] [nvarchar] (50)   NULL ,
	[GDEPOID] [int] NOT NULL ,
	[CDEPOID] [int] NOT NULL ,
	[DURUM] [nvarchar] (15)   NOT NULL ,
	[SKODU] [nvarchar] (10)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TALEPFISISL] (
	[TALEPFISISLID] [int] NOT NULL ,
	[TALEPFISID] [int] NOT NULL ,
	[STOKID] [int] NOT NULL ,
	[TMIKTAR] [float] NOT NULL ,
	[SMIKTAR] [float] NOT NULL ,
	[VMIKTAR] [float] NULL ,
	[YETKILI] [nvarchar] (15)   NULL ,
	[ADMIKTAR] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TASKS] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[PARENTID] [int] NULL ,
	[TYPE] [int] NULL ,
	[ACTUALFINISH] [int] NULL ,
	[ACTUALSTART] [int] NULL ,
	[START] [datetime] NULL ,
	[FINISH] [datetime] NULL ,
	[OPTIONS] [int] NULL ,
	[CAPTION] [nvarchar] (255)   NULL ,
	[RECURRENCEINDEX] [int] NULL ,
	[RECURRENCEINFO] [ntext]   NULL ,
	[RESOURCEID] [ntext]   NULL ,
	[LOCATION] [nvarchar] (255)   NULL ,
	[MESSAGE] [nvarchar] (255)   NULL ,
	[REMINDERDATE] [datetime] NULL ,
	[REMINDERMINUTES] [int] NULL ,
	[STATE] [int] NULL ,
	[LABELCOLOR] [int] NULL ,
	[USERKOD] [nvarchar] (15)   NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[TASKS_CON] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[TASKSID] [int] NULL ,
	[USERKOD] [nvarchar] (15)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TEKLIF] (
	[TEKLIFID] [int] NOT NULL ,
	[CARIID] [int] NULL ,
	[UNVANI] [nvarchar] (100)   NULL ,
	[ADRES] [nvarchar] (100)   NULL ,
	[TEL] [nvarchar] (20)   NULL ,
	[FAX] [nvarchar] (20)   NULL ,
	[EMAIL] [nvarchar] (30)   NULL ,
	[YETKILI] [nvarchar] (50)   NULL ,
	[ONSOZ] [ntext]   NULL ,
	[BAYI] [nvarchar] (20)   NULL ,
	[BOLGE] [nvarchar] (20)   NULL ,
	[TARIH] [datetime] NULL ,
	[OPSIYON] [datetime] NULL ,
	[TOPLAM] [float] NULL ,
	[INDORAN] [float] NULL ,
	[INDTUTAR] [float] NULL ,
	[KDVORAN] [float] NULL ,
	[DOVIZ] [nvarchar] (5)   NULL ,
	[ODEMES] [nvarchar] (80)   NULL ,
	[GARANTIS] [nvarchar] (80)   NULL ,
	[KURULUMS] [nvarchar] (80)   NULL ,
	[EKSARTLAR] [ntext]   NULL ,
	[HAZIRLAYAN] [nvarchar] (50)   NULL ,
	[ONAYLAYAN] [nvarchar] (50)   NULL ,
	[SUBEKODU] [nvarchar] (15)   NULL ,
	[BASLIK] [nvarchar] (100)   NULL ,
	[DURUMU] [bit] NULL ,
	[TAKIPNOTU] [nvarchar] (255)   NULL ,
	[TEKRARARA] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[TEKLIFISL] (
	[TEKLIFISLID] [int] NOT NULL ,
	[TEKLIFID] [int] NULL ,
	[STOKID] [int] NULL ,
	[ACIKLAMA] [nvarchar] (250)   NULL ,
	[ADET] [float] NULL ,
	[BFIYAT] [float] NULL ,
	[INDORAN] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[USER] (
	[KODU] [nvarchar] (15)   NOT NULL ,
	[ADI] [nvarchar] (30)   NULL ,
	[GOREVI] [nvarchar] (15)   NULL ,
	[DEPT] [nvarchar] (15)   NULL ,
	[SIFRESI] [nvarchar] (15)   NULL ,
	[YETKISI] [smallint] NULL ,
	[DIL] [nvarchar] (15)   NULL ,
	[GRUBU] [nvarchar] (15)   NULL ,
	[SKODU] [nvarchar] (10)   NULL ,
	[ONBURO] [smallint] NULL ,
	[STOK] [smallint] NULL ,
	[SANTRAL] [smallint] NULL ,
	[POS] [smallint] NULL ,
	[WINTOM] [smallint] NULL ,
	[MUHASEBE] [smallint] NULL ,
	[PERSONEL] [smallint] NULL ,
	[YGRUBU] [bit] NULL ,
	[RAPORLAR] [smallint] NULL ,
	[DEPOKODU] [nvarchar] (10)   NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[USERD] (
	[USERDID] [int] IDENTITY (1, 1) NOT NULL ,
	[KODU] [nvarchar] (15)   NULL ,
	[FGRUBU] [nvarchar] (15)   NULL ,
	[FORM] [nvarchar] (50)   NULL ,
	[LISTE] [bit] NOT NULL ,
	[EKLE] [bit] NOT NULL ,
	[YENILE] [bit] NOT NULL ,
	[SIL] [bit] NOT NULL ,
	[SEC] [bit] NOT NULL ,
	[COGALT] [bit] NOT NULL ,
	[YAZDIR] [bit] NOT NULL ,
	[DETAY] [bit] NOT NULL ,
	[RAPOR] [bit] NOT NULL 
) ON [PRIMARY]
GO



ALTER TABLE [dbo].[BUTCE] WITH NOCHECK ADD 
	CONSTRAINT [PK_BUTCE] PRIMARY KEY  CLUSTERED 
	(
		[BUTCEID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FORMDETAY] WITH NOCHECK ADD 
	CONSTRAINT [PK_FORMDETAY] PRIMARY KEY  CLUSTERED 
	(
		[FORMDETAYID]
	)  ON [PRIMARY] 
GO


ALTER TABLE [dbo].[FORMLAR] ADD 
	CONSTRAINT [IX_FORMLAR] UNIQUE  NONCLUSTERED 
	(
		[FORMADI]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[BUTCEDEGER] WITH NOCHECK ADD 
	CONSTRAINT [PK_BUTCEDEGER] PRIMARY KEY  CLUSTERED 
	(
		[SUBEKODU],
		[AY],
		[YIL]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CARIISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_CARIISL] PRIMARY KEY  CLUSTERED 
	(
		[CARIISLID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CEK] WITH NOCHECK ADD 
	CONSTRAINT [PK_CEK] PRIMARY KEY  CLUSTERED 
	(
		[CEKID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CEKISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_CEKISL] PRIMARY KEY  CLUSTERED 
	(
		[CEKISLID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CEKSENET] WITH NOCHECK ADD 
	CONSTRAINT [PK_CEKSENET] PRIMARY KEY  CLUSTERED 
	(
		[COUNTER]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CONFIG] WITH NOCHECK ADD 
	CONSTRAINT [PK_CONFIG] PRIMARY KEY  CLUSTERED 
	(
		[CONFIGID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMDEPART] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMDEPART] PRIMARY KEY  CLUSTERED 
	(
		[DEPARTID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMGECMIS] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMGECMIS] PRIMARY KEY  CLUSTERED 
	(
		[GECMISID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMGRUP] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMGRUP] PRIMARY KEY  CLUSTERED 
	(
		[DEMGRUPKODU]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMIADE] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMIADE] PRIMARY KEY  CLUSTERED 
	(
		[DEMIADEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMKART] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMKART] PRIMARY KEY  CLUSTERED 
	(
		[DEMKARTID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMKAYIP] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMKAYIP] PRIMARY KEY  CLUSTERED 
	(
		[DEMKAYIPID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMSATICI] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMSATICI] PRIMARY KEY  CLUSTERED 
	(
		[DEMSATICIID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMSOZ] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMSOZ] PRIMARY KEY  CLUSTERED 
	(
		[SOZID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMSOZKALEM] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMSOZKALEM] PRIMARY KEY  CLUSTERED 
	(
		[SOZKALEMID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMSTS] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMSATIS] PRIMARY KEY  CLUSTERED 
	(
		[DEMSATISID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMSUBE] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMSUBE] PRIMARY KEY  CLUSTERED 
	(
		[SUBEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMTRANS] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMTRANS] PRIMARY KEY  CLUSTERED 
	(
		[DEMTRANSID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMTUR] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMTUR] PRIMARY KEY  CLUSTERED 
	(
		[TURID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEMYER] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEMYER] PRIMARY KEY  CLUSTERED 
	(
		[YERID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEPO] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEPO] PRIMARY KEY  CLUSTERED 
	(
		[DEPOID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEPOFIS] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEPOFIS] PRIMARY KEY  CLUSTERED 
	(
		[DEPOFISID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEPOFISISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEPOFISISL] PRIMARY KEY  CLUSTERED 
	(
		[DEPOFISISLID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DEPOMUH] WITH NOCHECK ADD 
	CONSTRAINT [PK_DEPOMUH] PRIMARY KEY  CLUSTERED 
	(
		[DEPOMUHID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DOVIZ] WITH NOCHECK ADD 
	CONSTRAINT [PK_DOVIZ] PRIMARY KEY  CLUSTERED 
	(
		[KODU]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DOVIZBOZISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_DOVIZBOZISL] PRIMARY KEY  CLUSTERED 
	(
		[DOVIZBOZID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DOVIZISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_DOVIZISL] PRIMARY KEY  CLUSTERED 
	(
		[DOVIZISLID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[ETIKET] WITH NOCHECK ADD 
	CONSTRAINT [PK_ETIKET] PRIMARY KEY  CLUSTERED 
	(
		[ETIKETNO]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[ETS_CARI] WITH NOCHECK ADD 
	CONSTRAINT [CARI_pk] PRIMARY KEY  CLUSTERED 
	(
		[CARIID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[ETS_HESAPISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_ETS_HESAPISL] PRIMARY KEY  CLUSTERED 
	(
		[COUNTER]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATGRUP] WITH NOCHECK ADD 
	CONSTRAINT [PK_FATGRUP] PRIMARY KEY  CLUSTERED 
	(
		[GRUPADI]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_FATISL] PRIMARY KEY  CLUSTERED 
	(
		[FATISLID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATISL2] WITH NOCHECK ADD 
	CONSTRAINT [PK_FATISL2] PRIMARY KEY  CLUSTERED 
	(
		[FATISL2ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATTUR] WITH NOCHECK ADD 
	CONSTRAINT [PK_FATTUR] PRIMARY KEY  CLUSTERED 
	(
		[FATTURID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATURA] WITH NOCHECK ADD 
	CONSTRAINT [PK_FATURA] PRIMARY KEY  CLUSTERED 
	(
		[FATID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FIS] WITH NOCHECK ADD 
	CONSTRAINT [PK_FIS] PRIMARY KEY  CLUSTERED 
	(
		[COUNTER]
	)  ON [PRIMARY] 
GO


ALTER TABLE [dbo].[FORMLAR] WITH NOCHECK ADD 
	CONSTRAINT [PK_FORMLAR] PRIMARY KEY  CLUSTERED 
	(
		[FORMADI]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[GECICIDONEM] WITH NOCHECK ADD 
	CONSTRAINT [PK_GECICIDONEM] PRIMARY KEY  CLUSTERED 
	(
		[DONEMID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[GELENTEL] WITH NOCHECK ADD 
	CONSTRAINT [PK_GELENTEL] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[GELIRGRUP] WITH NOCHECK ADD 
	CONSTRAINT [PK_GELIRGRUP] PRIMARY KEY  CLUSTERED 
	(
		[KODU]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[HESAP] WITH NOCHECK ADD 
	CONSTRAINT [PK_HESAP] PRIMARY KEY  CLUSTERED 
	(
		[HESAPID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[HESAPBUTCE] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[BUTCEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[HESISLSIL] WITH NOCHECK ADD 
	CONSTRAINT [PK_HESISLSIL] PRIMARY KEY  CLUSTERED 
	(
		[COUNTER]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[HSPKILIT] WITH NOCHECK ADD 
	CONSTRAINT [PK_HSPKILIT] PRIMARY KEY  CLUSTERED 
	(
		[HSPKILITID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[IRSALIYE] WITH NOCHECK ADD 
	CONSTRAINT [PK_IRSALIYE] PRIMARY KEY  CLUSTERED 
	(
		[IRSID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[IRSDETAY] WITH NOCHECK ADD 
	CONSTRAINT [PK_IRSDETAY] PRIMARY KEY  CLUSTERED 
	(
		[FATSTRID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[LOG] WITH NOCHECK ADD 
	CONSTRAINT [PK_LOG] PRIMARY KEY  CLUSTERED 
	(
		[LOGID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MANUAL] WITH NOCHECK ADD 
	CONSTRAINT [PK_MANUAL] PRIMARY KEY  CLUSTERED 
	(
		[KONUID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MASMER] WITH NOCHECK ADD 
	CONSTRAINT [PK_MASMER] PRIMARY KEY  CLUSTERED 
	(
		[MASMERID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MESAJ] WITH NOCHECK ADD 
	CONSTRAINT [PK_MESAJ] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MTABLOAD] WITH NOCHECK ADD 
	CONSTRAINT [PK_MTABLOAD] PRIMARY KEY  CLUSTERED 
	(
		[MTID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MUST] WITH NOCHECK ADD 
	CONSTRAINT [PK_MUST] PRIMARY KEY  CLUSTERED 
	(
		[MUSTID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MUSTISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_MUSTISL] PRIMARY KEY  CLUSTERED 
	(
		[MUTSISLID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PANDEPTGG] WITH NOCHECK ADD 
	CONSTRAINT [PANDEPTGG_pk] PRIMARY KEY  CLUSTERED 
	(
		[PANDEPTGGID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PLAN] WITH NOCHECK ADD 
	CONSTRAINT [PK_PLAN] PRIMARY KEY  CLUSTERED 
	(
		[PLANID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[RECETE] WITH NOCHECK ADD 
	CONSTRAINT [PK_RECETE] PRIMARY KEY  CLUSTERED 
	(
		[RECETEID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[REHBER] WITH NOCHECK ADD 
	CONSTRAINT [PK_REHBER] PRIMARY KEY  CLUSTERED 
	(
		[COUNTER]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[REHBERISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_REHBERISL] PRIMARY KEY  CLUSTERED 
	(
		[ISLEMID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SATICI] WITH NOCHECK ADD 
	CONSTRAINT [PK_SATICI] PRIMARY KEY  CLUSTERED 
	(
		[KODU]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SATICISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_SATICISL] PRIMARY KEY  CLUSTERED 
	(
		[COUNTER]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SATINALMA] WITH NOCHECK ADD 
	CONSTRAINT [PK_SATINALMA] PRIMARY KEY  CLUSTERED 
	(
		[SATINALMAID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SATINALMAISL] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[SATISLID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SATIST] WITH NOCHECK ADD 
	CONSTRAINT [PK_SATIST] PRIMARY KEY  CLUSTERED 
	(
		[SATISID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SAYACLAR] WITH NOCHECK ADD 
	CONSTRAINT [PK_SAYACLAR] PRIMARY KEY  CLUSTERED 
	(
		[TABLENAME]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SBIRIM] WITH NOCHECK ADD 
	CONSTRAINT [PK_SBIRIM] PRIMARY KEY  CLUSTERED 
	(
		[BIRIMID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SIPNOT] WITH NOCHECK ADD 
	CONSTRAINT [PK_SIPNOT] PRIMARY KEY  CLUSTERED 
	(
		[SIPID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SSAYIM] WITH NOCHECK ADD 
	CONSTRAINT [PK_SSAYIM] PRIMARY KEY  CLUSTERED 
	(
		[SAYIMID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SSAYIMARV] WITH NOCHECK ADD 
	CONSTRAINT [SSAYIMARV_pk] PRIMARY KEY  CLUSTERED 
	(
		[BASTARIH],
		[TARIH]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SSAYIMLAR] WITH NOCHECK ADD 
	CONSTRAINT [PK_SSAYIM_1] PRIMARY KEY  CLUSTERED 
	(
		[SAYIMID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[STOK] WITH NOCHECK ADD 
	CONSTRAINT [PK_STOK] PRIMARY KEY  CLUSTERED 
	(
		[STOKID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[STOKGRUP] WITH NOCHECK ADD 
	CONSTRAINT [STOKGRUP_pk] PRIMARY KEY  CLUSTERED 
	(
		[KODU]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[STOKTURU] WITH NOCHECK ADD 
	CONSTRAINT [PK_STOKTURU] PRIMARY KEY  CLUSTERED 
	(
		[TUR]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SUBELER] WITH NOCHECK ADD 
	CONSTRAINT [PK_SUBELER] PRIMARY KEY  CLUSTERED 
	(
		[SUBEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TAKVIM] WITH NOCHECK ADD 
	CONSTRAINT [PK_TAKVIM] PRIMARY KEY  CLUSTERED 
	(
		[TARIH]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TALEPFIS] WITH NOCHECK ADD 
	CONSTRAINT [PK_TALEPFIS] PRIMARY KEY  CLUSTERED 
	(
		[TALEPFISID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TALEPFISISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_TALEPFISISL] PRIMARY KEY  CLUSTERED 
	(
		[TALEPFISISLID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TASKS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TASKS_CON] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TEKLIF] WITH NOCHECK ADD 
	CONSTRAINT [PK_TEKLIF] PRIMARY KEY  CLUSTERED 
	(
		[TEKLIFID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TEKLIFISL] WITH NOCHECK ADD 
	CONSTRAINT [PK_TEKLIFISL] PRIMARY KEY  CLUSTERED 
	(
		[TEKLIFISLID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[USER] WITH NOCHECK ADD 
	CONSTRAINT [PK_USER] PRIMARY KEY  CLUSTERED 
	(
		[KODU]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[USERD] WITH NOCHECK ADD 
	CONSTRAINT [PK_USERD] PRIMARY KEY  CLUSTERED 
	(
		[USERDID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

 CREATE  INDEX [IX_CARIISL] ON [dbo].[CARIISL]([CARIID]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_CARIISL_1] ON [dbo].[CARIISL]([TARIH]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_CARIISL_2] ON [dbo].[CARIISL]([CARIID2]) WITH  FILLFACTOR = 90 ON [PRIMARY]
GO

 CREATE  INDEX [IX_CARIISL_3] ON [dbo].[CARIISL]([CARIISLID]) WITH  FILLFACTOR = 90 ON [PRIMARY]
GO

 CREATE  INDEX [IX_CEKSENET] ON [dbo].[CEKSENET]([VADETAR]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_CEKSENET_1] ON [dbo].[CEKSENET]([DURUM]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[CONFIG] ADD 
	CONSTRAINT [IX_CONFIG] UNIQUE  NONCLUSTERED 
	(
		[PROGNAME],
		[SECTIONSTR],
		[KEYNAME]
	)  ON [PRIMARY] 
GO

 CREATE  INDEX [IX_CONFIG_1] ON [dbo].[CONFIG]([PROGNAME]) WITH  FILLFACTOR = 90 ON [PRIMARY]
GO

ALTER TABLE [dbo].[DEMGRUP] ADD 
	CONSTRAINT [DF_DEMGRUP_SEVIYE] DEFAULT (0) FOR [OMRU]
GO

ALTER TABLE [dbo].[DEMKART] ADD 
	CONSTRAINT [DF_DEMKART_AMORTISMAN] DEFAULT (0) FOR [AMORTISMAN],
	CONSTRAINT [DF_DEMKART_GVDAMORTISMAN] DEFAULT (0) FOR [GVDAMORTISMAN],
	CONSTRAINT [DF_DEMKART_BRKAMORTISMAN] DEFAULT (0) FOR [BRKAMORTISMAN],
	CONSTRAINT [DF_DEMKART_TRFDURUMU] DEFAULT (0) FOR [TRFDURUMU],
	CONSTRAINT [DF_DEMKART_ONAYBEKLIYOR] DEFAULT (0) FOR [ONAYBEKLIYOR]
GO

ALTER TABLE [dbo].[DEMTRANS] ADD 
	CONSTRAINT [DF_DEMTRANS_ONAY] DEFAULT (0) FOR [ONAY]
GO

ALTER TABLE [dbo].[DEPOFIS] ADD 
	CONSTRAINT [DF_DEPOFIS_URETILDI] DEFAULT (0) FOR [URETILDI],
	CONSTRAINT [DF_DEPOFIS_LOGOAKTAR] DEFAULT (0) FOR [LOGOAKTAR],
	CONSTRAINT [DF_DEPOFIS_LOGODANGELDI] DEFAULT (0) FOR [LOGODANGELDI],
	CONSTRAINT [DF_DEPOFIS_ONAY] DEFAULT (0) FOR [ONAY],
	CONSTRAINT [DF__DEPOFIS__MUHFISI__117F9D94] DEFAULT (0) FOR [MUHFISID],
	CONSTRAINT [DF__DEPOFIS__DURUMU__1273C1CD] DEFAULT (0) FOR [DURUMU]
GO

 CREATE  INDEX [DEPOFIS_idx] ON [dbo].[DEPOFIS]([TARIH]) ON [PRIMARY]
GO

 CREATE  INDEX [DEPOFIS_idx2] ON [dbo].[DEPOFIS]([TARIH] DESC ) ON [PRIMARY]
GO

ALTER TABLE [dbo].[DEPOMUH] ADD 
	CONSTRAINT [IX_DEPOMUH] UNIQUE  NONCLUSTERED 
	(
		[DEPOID],
		[GRUPKODU]
	)  ON [PRIMARY] 
GO

 CREATE  INDEX [CARI_IDX] ON [dbo].[ETS_CARI]([CARIID]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX2] ON [dbo].[ETS_CARI]([KODU]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX3] ON [dbo].[ETS_CARI]([KODU]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX4] ON [dbo].[ETS_CARI]([UNVANI]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX5] ON [dbo].[ETS_CARI]([UNVANI]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX6] ON [dbo].[ETS_CARI]([TIP]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX7] ON [dbo].[ETS_CARI]([KSKODU]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_IDX8] ON [dbo].[ETS_CARI]([TIP], [UNVANI]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx] ON [dbo].[ETS_CARI]([CARIID] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx2] ON [dbo].[ETS_CARI]([KODU]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx3] ON [dbo].[ETS_CARI]([KODU] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx4] ON [dbo].[ETS_CARI]([UNVANI]) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx5] ON [dbo].[ETS_CARI]([UNVANI] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx6] ON [dbo].[ETS_CARI]([TIP] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [CARI_idx7] ON [dbo].[ETS_CARI]([KSKODU]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_CARI] ON [dbo].[ETS_CARI]([TIP]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[FATISL] ADD 
	CONSTRAINT [DF__FATISL__FBTOPLAM__1A14E395] DEFAULT (0) FOR [FBTOPLAM],
	CONSTRAINT [DF__FATISL__ARATOPLA__1B0907CE] DEFAULT (0) FOR [ARATOPLAM],
	CONSTRAINT [DF__FATISL__TOPLAM__1BFD2C07] DEFAULT (0) FOR [TOPLAM]
GO

ALTER TABLE [dbo].[FATISL2] ADD 
	CONSTRAINT [DF_FATISL2_ADET] DEFAULT (1) FOR [ADET]
GO

ALTER TABLE [dbo].[FATSAYAC] ADD 
	CONSTRAINT [DF_FATSAYAC_FATSAYACNO] DEFAULT (1) FOR [FATSAYACNO],
	CONSTRAINT [IX_FATSAYAC] UNIQUE  NONCLUSTERED 
	(
		[FATSAYACSERI]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATTUR] ADD 
	CONSTRAINT [FATTUR_uq] UNIQUE  NONCLUSTERED 
	(
		[TURADI]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[FATURA] ADD 
	CONSTRAINT [DF_FATURA_FIPTAL] DEFAULT (0) FOR [FIPTAL],
	CONSTRAINT [DF_FATURA_IRSALIYE] DEFAULT (0) FOR [IRSALIYE],
	CONSTRAINT [DF_FATURA_DOVIZKODU] DEFAULT (N'YTL') FOR [DOVIZKODU],
	CONSTRAINT [DF_FATURA_SEC] DEFAULT (0) FOR [SEC],
	CONSTRAINT [DF_FATURA_ODENDI] DEFAULT (0) FOR [ODENDI],
	CONSTRAINT [DF_FATURA_KESINTIVAR] DEFAULT (0) FOR [KESINTIVAR],
	CONSTRAINT [DF_FATURA_YAZONAY] DEFAULT (0) FOR [YAZONAY]
GO

 CREATE  INDEX [FATURA_idx] ON [dbo].[FATURA]([TARIH]) ON [PRIMARY]
GO

 CREATE  INDEX [FATURA_idx2] ON [dbo].[FATURA]([FATID] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FATURA] ON [dbo].[FATURA]([TARIH] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FATURA_1] ON [dbo].[FATURA]([FATID], [FIPTAL]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FATURA_2] ON [dbo].[FATURA]([FIPTAL]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[FIS] ADD 
	CONSTRAINT [DF__FIS__ADBAKIYE__2A4B4B5E] DEFAULT (0) FOR [ADBAKIYE],
	CONSTRAINT [DF__FIS__BDBAKIYE__2B3F6F97] DEFAULT (0) FOR [BDBAKIYE],
	CONSTRAINT [DF__FIS__AMBAKIYE__2C3393D0] DEFAULT (0) FOR [AMBAKIYE],
	CONSTRAINT [DF__FIS__BMBAKIYE__2D27B809] DEFAULT (0) FOR [BMBAKIYE]
GO

 CREATE  INDEX [FIS_idx] ON [dbo].[FIS]([SKODU]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS] ON [dbo].[FIS]([TARIH]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_1] ON [dbo].[FIS]([FISTURU]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_2] ON [dbo].[FIS]([COUNTER]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_3] ON [dbo].[FIS]([SKODU]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_4] ON [dbo].[FIS]([COUNTER]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_5] ON [dbo].[FIS]([FISNO]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_6] ON [dbo].[FIS]([SKODU]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_FIS_7] ON [dbo].[FIS]([COUNTER]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[FISSIL] ADD 
	CONSTRAINT [DF__FISSIL__ADBAKIYE__2F10007B] DEFAULT (0) FOR [ADBAKIYE],
	CONSTRAINT [DF__FISSIL__BDBAKIYE__300424B4] DEFAULT (0) FOR [BDBAKIYE],
	CONSTRAINT [DF__FISSIL__AMBAKIYE__30F848ED] DEFAULT (0) FOR [AMBAKIYE],
	CONSTRAINT [DF__FISSIL__BMBAKIYE__31EC6D26] DEFAULT (0) FOR [BMBAKIYE]
GO

ALTER TABLE [dbo].[HESAP] ADD 
	CONSTRAINT [DF__HESAP__MMZORUNLU__34C8D9D1] DEFAULT (0) FOR [MMZORUNLU],
	CONSTRAINT [DF__HESAP__FAALIYETI__35BCFE0A] DEFAULT (0) FOR [FAALIYETICI],
	CONSTRAINT [IX_HESAP] UNIQUE  NONCLUSTERED 
	(
		[KODU]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[HESAPBUTCE] ADD 
	CONSTRAINT [ETS_HESAPBUTCE_uq] UNIQUE  NONCLUSTERED 
	(
		[BUTCEKODU]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[HESAPISLSIL] ADD 
	CONSTRAINT [DF__HESAPISLSI__BORC__55B597A7] DEFAULT (0) FOR [BORC],
	CONSTRAINT [DF__HESAPISLS__ALACA__56A9BBE0] DEFAULT (0) FOR [ALACAK],
	CONSTRAINT [DF__HESAPISLS__DBORC__579DE019] DEFAULT (0) FOR [DBORC],
	CONSTRAINT [DF__HESAPISLS__DALAC__58920452] DEFAULT (0) FOR [DALACAK],
	CONSTRAINT [DF__HESAPISLS__MBORC__5986288B] DEFAULT (0) FOR [MBORC],
	CONSTRAINT [DF__HESAPISLS__MALAC__5A7A4CC4] DEFAULT (0) FOR [MALACAK]
GO

ALTER TABLE [dbo].[IRSALIYE] ADD 
	CONSTRAINT [DF_IRSALIYE_EK1] DEFAULT (0) FOR [EK1],
	CONSTRAINT [DF_IRSALIYE_EK2] DEFAULT (0) FOR [EK2],
	CONSTRAINT [DF_IRSALIYE_EK3] DEFAULT (0) FOR [EK3],
	CONSTRAINT [DF_IRSALIYE_IND1] DEFAULT (0) FOR [IND1],
	CONSTRAINT [DF_IRSALIYE_IND2] DEFAULT (0) FOR [IND2],
	CONSTRAINT [DF_IRSALIYE_IND3] DEFAULT (0) FOR [IND3],
	CONSTRAINT [DF_IRSALIYE_FATCOUNTER] DEFAULT (0) FOR [FATCOUNTER]
GO

 CREATE  INDEX [ALAN] ON [dbo].[MESAJ]([ALAN]) ON [PRIMARY]
GO

 CREATE  INDEX [GONDEREN] ON [dbo].[MESAJ]([GONDEREN]) ON [PRIMARY]
GO

 CREATE  INDEX [TARIH] ON [dbo].[MESAJ]([TARIH]) ON [PRIMARY]
GO

 CREATE  INDEX [RECETE_IDX] ON [dbo].[RECETE]([URUNID]) ON [PRIMARY]
GO

 CREATE  INDEX [RECETE_IDX2] ON [dbo].[RECETE]([STOKID]) ON [PRIMARY]
GO

 CREATE  INDEX [ADIINDEX] ON [dbo].[SATICI]([UNVANI]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_SATICISL] ON [dbo].[SATICISL]([KODU], [TARIH]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_SATICISL_1] ON [dbo].[SATICISL]([VADE]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SATINALMAISL] ADD 
	CONSTRAINT [DF__SATINALMA__S_MIK__4F089A18] DEFAULT (0) FOR [S_MIKTAR],
	CONSTRAINT [DF__SATINALMA__S_TEM__4FFCBE51] DEFAULT (1) FOR [S_TEMIKTAR],
	CONSTRAINT [DF__SATINALMA__S_DEP__50F0E28A] DEFAULT (0) FOR [S_DEPOMEVCUT],
	CONSTRAINT [DF__SATINALMA__TAMAM__55167929] DEFAULT (0) FOR [TAMAMLANDI]
GO

 CREATE  INDEX [ETS_SATINALMAISL_idx] ON [dbo].[SATINALMAISL]([SATINALMAID]) ON [PRIMARY]
GO

 CREATE  INDEX [ETS_SBIRIM_idx] ON [dbo].[SBIRIM]([BIRIM]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SSAYIM] ADD 
	CONSTRAINT [UNQ_DEPOSTOK] UNIQUE  NONCLUSTERED 
	(
		[SKODU],
		[DEPOID],
		[STOKID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[STOK] ADD 
	CONSTRAINT [DF_STOK_TURU] DEFAULT (N'Mamul') FOR [TURU],
	CONSTRAINT [DF__STOK__COSTFACTOR__5BE2A6F2] DEFAULT (1) FOR [COSTFACTOR],
	CONSTRAINT [DF__STOK__VARSAYILAN__5CD6CB2B] DEFAULT (0) FOR [VARSAYILANBIRIM],
	CONSTRAINT [DF_STOK_ALISBIRIMNO] DEFAULT (1) FOR [ALISBIRIMNO],
	CONSTRAINT [DF_STOK_SATISBIRIMNO] DEFAULT (1) FOR [SATISBIRIMNO]
GO

 CREATE  INDEX [ETS_STOK_idx] ON [dbo].[STOK]([SAYIMDURUMU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX] ON [dbo].[STOK]([ADI]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX1] ON [dbo].[STOK]([ADI]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX2] ON [dbo].[STOK]([KODU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX3] ON [dbo].[STOK]([ADI]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX4] ON [dbo].[STOK]([TURU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX5] ON [dbo].[STOK]([KODU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_IDX6] ON [dbo].[STOK]([KODU], [TURU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_idx] ON [dbo].[STOK]([ADI]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_idx2] ON [dbo].[STOK]([KODU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_idx3] ON [dbo].[STOK]([ADI] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_idx4] ON [dbo].[STOK]([TURU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_idx5] ON [dbo].[STOK]([KODU] DESC ) ON [PRIMARY]
GO

 CREATE  INDEX [STOK_idx6] ON [dbo].[STOK]([KODU], [TURU]) ON [PRIMARY]
GO

 CREATE  INDEX [ETS_STOKGRUP_idx] ON [dbo].[STOKGRUP]([TURU]) ON [PRIMARY]
GO

 CREATE  INDEX [STOKGRUP_IDX] ON [dbo].[STOKGRUP]([ADI]) ON [PRIMARY]
GO

 CREATE  INDEX [STOKGRUP_idx] ON [dbo].[STOKGRUP]([ADI]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TALEPFISISL] ADD 
	CONSTRAINT [DF_TALEPFISISL_SMIKTAR] DEFAULT (0) FOR [SMIKTAR]
GO

 CREATE  INDEX [TASKS_idx] ON [dbo].[TASKS]([PARENTID]) ON [PRIMARY]
GO

 CREATE  INDEX [TASKS_idx2] ON [dbo].[TASKS]([START], [FINISH]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[USER] ADD 
	CONSTRAINT [DF__USER__RAPORLAR__6477ECF3] DEFAULT (1) FOR [RAPORLAR]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.CARIISLEM AS
SELECT     dbo.ETS_CARI.CARIID AS CARIID, dbo.ETS_CARI.UNVANI AS CARIUNVANI, CARI_1.CARIID AS CARIID2, CARI_1.UNVANI AS CARIUNVANI2, dbo.ETS_CARI.TIP CARITIP,
                      dbo.CARIISL.TARIH, dbo.CARIISL.CARIISLID, dbo.CARIISL.VADE, dbo.CARIISL.ACIKLAMA, dbo.CARIISL.EVRAKNO, dbo.CARIISL.ISLTUR,
                      dbo.CARIISL.BORC, dbo.CARIISL.ALACAK, dbo.CARIISL.DBORC, dbo.CARIISL.DALACAK, dbo.CARIISL.DOVIZ, dbo.CARIISL.FATCOUNTER,
                      dbo.CARIISL.BORDROID, dbo.CARIISL.KAPANAN, dbo.CARIISL.ODEMEID, SKODU,dbo.CARIISL.OZELKOD, dbo.CARIISL.DURUM,0 AS ODENEN,MUHFC,FISNO
 FROM         dbo.CARIISL LEFT OUTER JOIN
                      dbo.ETS_CARI ON dbo.CARIISL.CARIID = dbo.ETS_CARI.CARIID LEFT OUTER JOIN
                      dbo.ETS_CARI CARI_1 ON dbo.CARIISL.CARIID2 = CARI_1.CARIID
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
 WHERE     (dbo.ETS_CARI.CARIID IS NOT NULL AND dbo.ETS_CARI.CARIID <> 0) AND ISLTUR NOT IN ('FATURA','CEK') --AND YEAR(TARIH)=2007
 UNION ALL
 SELECT     dbo.ETS_CARI.CARIID AS CARIID, dbo.ETS_CARI.UNVANI AS CARIUNVANI, CARI_1.CARIID AS CARIID2, CARI_1.UNVANI AS CARIUNVANI2, dbo.ETS_CARI.TIP CARITIP,
                      dbo.CARIISL.TARIH, dbo.CARIISL.CARIISLID, dbo.CARIISL.VADE, dbo.CARIISL.ACIKLAMA, dbo.CARIISL.EVRAKNO, dbo.CARIISL.ISLTUR,
                      dbo.CARIISL.ALACAK, dbo.CARIISL.BORC, dbo.CARIISL.DALACAK, dbo.CARIISL.DBORC, dbo.CARIISL.DOVIZ, dbo.CARIISL.FATCOUNTER,
                      dbo.CARIISL.BORDROID, dbo.CARIISL.KAPANAN, dbo.CARIISL.ODEMEID,SKODU, dbo.CARIISL.OZELKOD, dbo.CARIISL.DURUM,0 AS ODENEN,MUHFC,FISNO
 FROM         dbo.CARIISL LEFT OUTER JOIN
                      dbo.ETS_CARI ON dbo.CARIISL.CARIID2 = dbo.ETS_CARI.CARIID LEFT OUTER JOIN
                      dbo.ETS_CARI CARI_1 ON dbo.CARIISL.CARIID = CARI_1.CARIID
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
 WHERE     (dbo.CARIISL.CARIID2 IS NOT NULL AND dbo.CARIISL.CARIID2 <> 0) AND ISLTUR NOT IN ('FATURA','CEK') --AND YEAR(TARIH)=2007
 UNION ALL
 SELECT     FATURA.CARIID AS CARIID, FATURA.UNVANI AS CARIUNVANI, CASE WHEN FATURA.TUR = 1 THEN '-2' ELSE '-3' END AS CARIID2,
                      CASE WHEN FATURA.TUR = 1 THEN 'G~DER' ELSE 'GEL~R' END AS CARIUNVANI2, 'ETS_CARI' AS CARITIP, FATURA.TARIH AS TARIH, FATURA.FATID AS CARIISLID,
                      FATURA.VADE AS VADE, FATURA.ACIKLAMA, FATURA.FATNO AS EVRAKNO, 'FATURA' AS ISLTUR,
                      CASE WHEN FATURA.TUR = 1 THEN 0 ELSE FATURA.GTOPLAM END AS BORC,
                      CASE WHEN FATURA.TUR = 1 THEN FATURA.GTOPLAM ELSE 0 END AS ALACAK,
                      CASE WHEN FATURA.TUR = 1 THEN 0 ELSE CASE WHEN FATURA.DOVIZKURU > 0 THEN FATURA.GTOPLAM / FATURA.DOVIZKURU ELSE FATURA.GTOPLAM
                       END END AS DBORC,
                      CASE WHEN FATURA.TUR = 1 THEN CASE WHEN FATURA.DOVIZKURU > 0 THEN FATURA.GTOPLAM / FATURA.DOVIZKURU ELSE FATURA.GTOPLAM END
                       ELSE 0 END AS DALACAK, FATURA.DOVIZKODU AS DOVIZ, FATURA.FATID AS FATCOUNTER, NULL AS BORDROID, NULL AS KAPANAN, NULL
                      AS ODEMEID,SKODU, FATGRUP AS OZELKOD, 0 AS DURUM, ONAKIT,MUHFC,FISNO
 FROM         FATURA
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
 WHERE FIPTAL=0 -- AND YEAR(TARIH)=2007
 UNION ALL
 SELECT      CASE WHEN FATURA.TUR = 1 THEN '-2' ELSE '-3' END AS CARIID2,  CASE WHEN FATURA.TUR = 1 THEN 'G~DER' ELSE 'GEL~R' END AS CARIUNVANI2,
	   FATURA.CARIID AS CARIID, FATURA.UNVANI AS CARIUNVANI, 'ETS_CARI' AS CARITIP, FATURA.TARIH AS TARIH, FATURA.FATID AS CARIISLID,
                      FATURA.VADE AS VADE, FATURA.ACIKLAMA, FATURA.FATNO AS EVRAKNO, 'FATURA' AS ISLTUR,
                      CASE WHEN FATURA.TUR = 1 THEN FATURA.GTOPLAM ELSE 0 END AS BORC,
                      CASE WHEN FATURA.TUR = 1 THEN 0 ELSE FATURA.GTOPLAM END AS ALACAK,
                      CASE WHEN FATURA.TUR = 1 THEN CASE WHEN FATURA.DOVIZKURU > 0 THEN FATURA.GTOPLAM / FATURA.DOVIZKURU ELSE FATURA.GTOPLAM END
                       ELSE 0 END AS DBORC,
                      CASE WHEN FATURA.TUR = 1 THEN 0 ELSE CASE WHEN FATURA.DOVIZKURU > 0 THEN FATURA.GTOPLAM / FATURA.DOVIZKURU ELSE FATURA.GTOPLAM
                       END END AS DALACAK,
                    FATURA.DOVIZKODU AS DOVIZ, FATURA.FATID AS FATCOUNTER, NULL AS BORDROID, NULL AS KAPANAN, NULL
                      AS ODEMEID,SKODU, FATGRUP AS OZELKOD, 0 AS DURUM,ONAKIT,MUHFC,FISNO
 FROM         FATURA
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
 WHERE FIPTAL=0 --AND YEAR(TARIH)=2007
 UNION ALL
 SELECT     CEKBORDRO.CARIID, NULL AS UNVANI, CARIID2, NULL AS CARIUNVANI2, 'ETS_CARI' AS CARITIP, TARIH, CEKBORDRO.CEKBORDROID AS CARIISLID, VADE, ACIKLAMA,
                       ENO AS EVRAKNO, 'CEK' AS ISLTUR, CASE WHEN TIP = 'GIRIS' THEN 0 WHEN TIP = 'CIKIS' THEN TOPLAM WHEN TIP = 'TAHSILAT'
                       THEN TOPLAM ELSE 0 END AS BORC, CASE WHEN TIP = 'GIRIS' THEN TOPLAM WHEN TIP = 'CIKIS' THEN 0 WHEN TIP = 'TAHSILAT'
                       THEN 0 ELSE TOPLAM END AS ALACAK,CASE WHEN TIP = 'GIRIS' THEN 0 WHEN TIP = 'CIKIS' THEN DOVIZTUTAR WHEN TIP = 'TAHSILAT'
                       THEN DOVIZTUTAR ELSE 0 END AS DBORC, CASE WHEN TIP = 'GIRIS' THEN DOVIZTUTAR WHEN TIP = 'CIKIS' THEN 0 WHEN TIP = 'TAHSILAT'
                       THEN 0 ELSE DOVIZTUTAR END AS DALACAK, DOVIZKODU AS DOVIZ, FATCOUNTER,
                       CEKBORDROID AS BORDROID, NULL AS KAPANAN, NULL AS ODEMEID,SKODU, OZELKOD, 0 AS DURUM, 0,MUHFC,FISNO
 FROM         CEKBORDRO
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
 --WHERE YEAR(TARIH)=2007
 UNION ALL
 SELECT      CARIID2, NULL AS CARIUNVANI2,CEKBORDRO.CARIID, NULL AS UNVANI, 'ETS_CARI' AS CARITIP, TARIH, CEKBORDRO.CEKBORDROID AS CARIISLID, VADE, ACIKLAMA,
                       ENO AS EVRAKNO, 'CEK' AS ISLTUR,
                  CASE WHEN TIP = 'GIRIS' THEN TOPLAM WHEN TIP = 'CIKIS' THEN 0 WHEN TIP = 'TAHSILAT'
                       THEN 0 ELSE TOPLAM END AS BORC,
 	    CASE WHEN TIP = 'GIRIS' THEN 0 WHEN TIP = 'CIKIS' THEN TOPLAM WHEN TIP = 'TAHSILAT'
                       THEN TOPLAM ELSE 0 END AS ALACAK,
                     CASE WHEN TIP = 'GIRIS' THEN DOVIZTUTAR WHEN TIP = 'CIKIS' THEN 0 WHEN TIP = 'TAHSILAT'
                       THEN 0 ELSE DOVIZTUTAR END AS DBORC,
                    CASE WHEN TIP = 'GIRIS' THEN 0 WHEN TIP = 'CIKIS' THEN DOVIZTUTAR WHEN TIP = 'TAHSILAT'
                       THEN DOVIZTUTAR ELSE 0 END AS DALACAK,
                   DOVIZKODU AS DOVIZ, FATCOUNTER,
                       CEKBORDROID AS BORDROID, NULL AS KAPANAN, NULL AS ODEMEID,SKODU, OZELKOD, 0 AS DURUM,0,MUHFC,FISNO
 FROM         CEKBORDRO
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
-- WHERE YEAR(TARIH)=2007
 UNION ALL
 SELECT     SMMAKBUZ.CARIID AS CARIID, SMMAKBUZ.CARIADI AS CARIUNVANI, '-2' AS CARIID2,
                      'G~DER', 'ETS_CARI' AS CARITIP, SMMAKBUZ.TARIH, SMMAKBUZ.SMMAKBUZID AS CARIISLID,
                      SMMAKBUZ.TARIH AS VADE, SMMAKBUZ.ACIKLAMA, SMMAKBUZ.BELGENO AS EVRAKNO, 'SMMAKBUZ' AS ISLTUR,
                      0 AS BORC,
                      SMMAKBUZ.ALINANTOPLAM AS ALACAK,
                      0 AS DBORC,
                      SMMAKBUZ.ALINANTOPLAM AS DALACAK, SMMAKBUZ.DOVIZKODU AS DOVIZ, NULL AS FATCOUNTER, NULL AS BORDROID, NULL AS KAPANAN, NULL
                      AS ODEMEID,SKODU, NULL AS OZELKOD, 0 AS DURUM,0 AS ODENEN,MUHFC,FISNO
 FROM         SMMAKBUZ
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
-- WHERE YEAR(TARIH)=2007
 UNION ALL
 SELECT      '-2'  CARIID2,  'G~DER' AS CARIUNVANI2,
	   SMMAKBUZ.CARIID AS CARIID, SMMAKBUZ.CARIADI AS CARIUNVANI, 'ETS_CARI' AS CARITIP, SMMAKBUZ.TARIH, SMMAKBUZ.SMMAKBUZID AS CARIISLID,
                      SMMAKBUZ.TARIH AS VADE, SMMAKBUZ.ACIKLAMA, SMMAKBUZ.BELGENO AS EVRAKNO, 'SMMAKBUZ' AS ISLTUR,
                      (SMMAKBUZ.BRUTUCRET + SMMAKBUZ.KDVTUTAR) AS BORC,
                      0 AS ALACAK,
                      (SMMAKBUZ.BRUTUCRET + SMMAKBUZ.KDVTUTAR) AS DBORC,
                      0 AS DALACAK,
                    SMMAKBUZ.DOVIZKODU AS DOVIZ, NULL AS FATCOUNTER, NULL AS BORDROID, NULL AS KAPANAN, NULL
                      AS ODEMEID,SKODU, NULL AS OZELKOD, 0 AS DURUM,0 AS ODENEN,MUHFC,FISNO
 FROM         SMMAKBUZ
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
-- WHERE YEAR(TARIH)=2007
 UNION ALL
 SELECT      '-5'  CARIID2,  'STOPAJ' AS CARIUNVANI2,
	   SMMAKBUZ.CARIID AS CARIID, SMMAKBUZ.CARIADI AS CARIUNVANI, 'ETS_CARI' AS CARITIP, SMMAKBUZ.TARIH AS TARIH, SMMAKBUZ.SMMAKBUZID AS CARIISLID,
                      SMMAKBUZ.TARIH AS VADE, SMMAKBUZ.ACIKLAMA, SMMAKBUZ.BELGENO AS EVRAKNO, 'SMMAKBUZ' AS ISLTUR,
                      0 AS BORC,
                      SMMAKBUZ.STOPAJTUTAR AS ALACAK,
                      0  AS DBORC,
                      SMMAKBUZ.STOPAJTUTAR AS DALACAK,
                    SMMAKBUZ.DOVIZKODU AS DOVIZ, NULL AS FATCOUNTER, NULL AS BORDROID, NULL AS KAPANAN, NULL
                      AS ODEMEID,SKODU, NULL AS OZELKOD, 0 AS DURUM,0 AS ODENEN ,MUHFC,FISNO
 FROM         SMMAKBUZ
                      LEFT OUTER JOIN (SELECT COUNTER,FISNO FROM dbo.FIS) AS FIS ON MUHFC=FIS.COUNTER
-- WHERE YEAR(TARIH)=2007



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO





/* Create view: HESAPISL2 (ViwData.CreateDependDef) */
CREATE VIEW HESAPISL2
 AS
SELECT     dbo.HESAP.KODU AS KODU, dbo.HESAP.ACIKLAMA AS ACIKLAMA, dbo.HESAP.ACIKLAMA2 AS ACIKLAMA2, dbo.HESAP.ACIKLAMA3 AS ACIKLAMA3,
                      dbo.HESAP.EK1 AS EK1, dbo.HESAP.EK2 AS EK2, dbo.HESAP.EK3 AS EK3, dbo.HESAP.EK4 AS EK4, dbo.HESAP.DOVTURU AS DOVTURU,
                      dbo.FIS.FISNO AS FISNO, dbo.FIS.TARIH AS TARIH, dbo.FIS.BORC AS FBORC, dbo.FIS.ALACAK AS FALACAK, dbo.FIS.DBORC AS FDBORC,
                      dbo.FIS.DALACAK AS FDALACAK, HESAPISL.VADE AS VADE, HESAPISL.BORC AS BORC, HESAPISL.ALACAK AS ALACAK,
                      HESAPISL.DBORC AS DBORC, HESAPISL.DALACAK AS DALACAK, HESAPISL.KAPANAN,HESAPISL.OZELKOD,HESAPISL.FISCOUNTER,FIS.SKODU,HESAPISL.MASMER,FIS.COUNTER
FROM         dbo.FIS INNER JOIN
                      dbo.ETS_HESAPISL AS HESAPISL ON dbo.FIS.COUNTER = HESAPISL.FISCOUNTER INNER JOIN
                      dbo.HESAP ON HESAPISL.HESAPID = dbo.HESAP.HESAPID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW HESAPISL3
AS
SELECT

dbo.HESAP.KODU, dbo.HESAP.ACIKLAMA,
CASE WHEN (ISNULL(dbo.HESAP.DOVTURU,'YTL')='YTL') OR (LTRIM(RTRIM(dbo.HESAP.DOVTURU))='') THEN 'YTL' ELSE dbo.HESAP.DOVTURU END AS DOVTURU,
dbo.FIS.TARIH, ISNULL(HESAPISL.VADE,dbo.FIS.TARIH) AS VADE,
HESAPISL.BORC, HESAPISL.ALACAK,
CASE WHEN (ISNULL(dbo.HESAP.DOVTURU,'YTL')='YTL') OR (LTRIM(RTRIM(dbo.HESAP.DOVTURU))='') THEN HESAPISL.BORC   ELSE HESAPISL.DBORC   END AS DBORC,
CASE WHEN (ISNULL(dbo.HESAP.DOVTURU,'YTL')='YTL') OR (LTRIM(RTRIM(dbo.HESAP.DOVTURU))='') THEN HESAPISL.ALACAK ELSE HESAPISL.DALACAK END AS DALACAK,
HESAPISL.KAPANAN,
HESAPISL.FISCOUNTER AS FCOUNTER,
FIS.SKODU,
HESAPISL.[COUNTER] AS HCOUNTER

FROM         dbo.FIS INNER JOIN
                      dbo.ETS_HESAPISL AS HESAPISL ON dbo.FIS.COUNTER = HESAPISL.FISCOUNTER INNER JOIN
                      dbo.HESAP ON HESAPISL.HESAPID = dbo.HESAP.HESAPID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW [dbo].[STOKFIYAT]
AS
SELECT     dbo.STOK.STOKID, dbo.STOKGRUP.ADI AS GADI, dbo.STOK.GRUP, dbo.STOK.KODU, dbo.STOK.ADI, dbo.STOK.SSATICI, dbo.STOK.SALISFIYAT, 
                      dbo.STOK.SFATURANO, dbo.STOK.SFATTARIHI, dbo.STOK.SFIYAT1 * (100 - dbo.STOK.ALISIND) / 100 AS ALIS, (dbo.STOK.SFIYAT1 + dbo.STOK.NAKLIYE)
                       * (100 - dbo.STOK.SATISIND) / 100 AS SATIS, ((dbo.STOK.SFIYAT1 + dbo.STOK.NAKLIYE) * (100 - dbo.STOK.SATISIND) / 100) 
                      * ((100 + dbo.STOK.SATISKDV) / 100) AS KDVLISATIS, dbo.STOK.SDOVIZ,
                          (SELECT     TOP 1 KUR2
                            FROM          DOVIZISL
                            WHERE      DOVIZISL.KODU = STOK.SDOVIZ
                            ORDER BY TARIH DESC) AS SATISKUR, ((dbo.STOK.SFIYAT1 + dbo.STOK.NAKLIYE) * (100 - dbo.STOK.SATISIND) / 100) * ((100 + dbo.STOK.SATISKDV)
                       / 100) *
                          ((SELECT     TOP 1 KUR2
                              FROM         DOVIZISL
                              WHERE     DOVIZISL.KODU = STOK.SDOVIZ
                              ORDER BY TARIH DESC)) AS SATISTL,
                          (SELECT     SUM(ADET)
                            FROM          FATISL
                            WHERE      FATISL.STOKID = STOK.STOKID) AS BAKIYE, dbo.STOK.BIRIM AS ABIRIM,
                          (SELECT     SUM(ADET)
                            FROM          FATISL
                            WHERE      FATISL.STOKID = STOK.STOKID) * dbo.STOK.KATSAYI2 AS BAKIYE2, dbo.STOK.BIRIM2, dbo.STOK.KATSAYI2 AS KATSAYI, 
                      ((dbo.STOK.SFIYAT1 + dbo.STOK.NAKLIYE) * (100 - dbo.STOK.SATISIND) / 100 - dbo.STOK.SFIYAT1 * (100 - dbo.STOK.ALISIND) / 100) *
                          (SELECT     SUM(ADET)
                            FROM          FATISL
                            WHERE      FATISL.STOKID = STOK.STOKID) AS KAR,
                          (SELECT     TOP 1 KUR2
                            FROM          DOVIZISL
                            WHERE      DOVIZISL.KODU = STOK.SDOVIZ
                            ORDER BY TARIH DESC) AS MBKUR --, dbo.CARI.KODU AS SATICI
FROM         dbo.STOKGRUP RIGHT OUTER JOIN
                      dbo.STOK ON dbo.STOKGRUP.KODU = dbo.STOK.GRUP LEFT OUTER JOIN
                      dbo.ETS_CARI AS CARI ON dbo.STOK.SSATICI = CARI.CARIID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW [dbo].[STOKISL]
AS
SELECT     'FATURA' AS FISTIPI, DEPOID, FATURA.TURADI AS ISLEM, FATISL.STOKID, FATISL.ACIKLAMA, FATISL.ADET * FATURA.TUR AS GCADET, FATISL.BFIYAT,
                       FATISL.SATIRIND, FATISL.SATIRIND2, FATURA.FATNO, ETS_CARI.KODU, ETS_CARI.UNVANI AS CARIUNVANI, FATISL.BFIYAT * (100 - FATISL.SATIRIND)
                      / 100 * (100 - FATISL.SATIRIND2) / 100 * (100 - FATURA.INDORAN1) / 100 * (100 + FATURA.EKORAN1) / 100 * (100 - FATURA.INDORAN2)
                      / 100 * (100 + FATURA.EKORAN2) / 100 * (100 - FATURA.INDORAN3) / 100 * (100 + FATURA.EKORAN3) / 100 AS NFIYAT, STOK.ADI,
                      FATISL.BFIYAT * (100 - FATISL.SATIRIND) / 100 * (100 - FATISL.SATIRIND2) / 100 * (100 - FATURA.INDORAN1) / 100 * (100 + FATURA.EKORAN1)
                      / 100 * (100 - FATURA.INDORAN2) / 100 * (100 + FATURA.EKORAN2) / 100 * (100 - FATURA.INDORAN3) / 100 * (100 + FATURA.EKORAN3)
                      / 100 * FATISL.ADET * FATURA.TUR AS TOPLAM, FATURA.INDORAN1, FATURA.EKORAN1, FATURA.INDORAN2, FATURA.EKORAN2, FATURA.INDORAN3,
                      FATURA.EKORAN3, FATURA.BAYIID, FATURA.SATISTID, STOK.SALISFIYAT, BAYI.BAYI, SATIST.SATIST, STOK.KODU AS STOKKODU, FATURA.TARIH,
                      FATURA.VADE, FATURA.FATID, SATIST.SKOMORAN AS SATICIKOMORAN, STOK.SKOMORAN AS STKOMORAN, STOK.BKOMORAN, FATURA.IRSALIYE,
                      FATURA.FATGRUP, NULL AS KDEPOID, STOK.GRUP AS SGRUPKODU, FATURA.SKODU,CAST(TUR AS NVARCHAR(15)) AS ISLEMDETAY, FATISL.FATISLID SATIRKNO
FROM         ((((FATISL INNER JOIN
                      FATURA ON FATISL.FATID = FATURA.FATID) LEFT JOIN
                      ETS_CARI ON FATURA.CARIID = ETS_CARI.CARIID) INNER JOIN
                      STOK ON FATISL.STOKID = STOK.STOKID) LEFT JOIN
                      BAYI ON FATURA.BAYIID = BAYI.BAYIID) LEFT JOIN
                      SATIST ON FATISL.SATISTID = SATIST.SATISID
UNION ALL
SELECT     'IRSALIYE' AS FISTIPI, DEPOID, IRSALIYE.TUR AS ISLEM, IRSDETAY.STOKID, IRSDETAY.ACIKLAMA, CASE WHEN IRSALIYE.TUR='ALIS' THEN 1*IRSDETAY.ADET
                   ELSE -1*IRSDETAY.ADET END AS GCADET, IRSDETAY.BFIYAT,
                       IRSDETAY.SATIRIND, IRSDETAY.SATIRIND2, IRSALIYE.IRSALIYENO, ETS_CARI.KODU, ETS_CARI.UNVANI AS CARIUNVANI, IRSDETAY.BFIYAT * (100 -IRSDETAY.SATIRIND)
                      / 100 * (100 - IRSDETAY.SATIRIND2) / 100 * (100 -IRSALIYE.INDORAN1) / 100 * (100 + IRSALIYE.EKORAN1) / 100 * (100 -IRSALIYE.INDORAN2)
                      / 100 * (100 + IRSALIYE.EKORAN2) / 100 * (100 - IRSALIYE.INDORAN3) / 100 * (100 + IRSALIYE.EKORAN3) / 100 AS NFIYAT, STOK.ADI,
                      IRSDETAY.BFIYAT * (100 - IRSDETAY.SATIRIND) / 100 * (100 - IRSDETAY.SATIRIND2) / 100 * (100 - IRSALIYE.INDORAN1) / 100 * (100 + IRSALIYE.EKORAN1)
                      / 100 * (100 - IRSALIYE.INDORAN2) / 100 * (100 + IRSALIYE.EKORAN2) / 100 * (100 - IRSALIYE.INDORAN3) / 100 * (100 + IRSALIYE.EKORAN3)
                      / 100 * IRSDETAY.ADET * CASE WHEN IRSALIYE.TUR='ALIS' THEN 1 ELSE -1 END  AS TOPLAM, IRSALIYE.INDORAN1, IRSALIYE.EKORAN1, IRSALIYE.INDORAN2, IRSALIYE.EKORAN2,
                      IRSALIYE.INDORAN3, IRSALIYE.EKORAN3, NULL AS BAYIID,NULL AS SATISTID, STOK.SALISFIYAT, NULL AS BAYI,NULL AS SATIST,STOK.KODU AS STOKKODU, IRSALIYE.IRSTARIH,
                      IRSALIYE.VADETARIH, IRSALIYE.IRSCOUNTER,0 AS SATICIKOMORAN, STOK.SKOMORAN AS STKOMORAN, STOK.BKOMORAN,
                     0 AS IRSALIYE,'' AS FATGRUP, NULL AS KDEPOID, STOK.GRUP AS SGRUPKODU, IRSALIYE.SKODU,'' AS ISLEMDETAY, IRSDETAY.FATSTRID SATIRKNO
FROM         ((IRSDETAY INNER JOIN
                      IRSALIYE ON IRSDETAY.IRSCOUNTER = IRSALIYE.IRSCOUNTER) LEFT JOIN
                      ETS_CARI ON IRSALIYE.CARIID = ETS_CARI.CARIID) INNER JOIN
                      STOK ON IRSDETAY.STOKID = STOK.STOKID
WHERE ((FATCOUNTER IS NULL) OR (FATCOUNTER=0))
UNION ALL
SELECT     'DEPOFIS' AS FISTIPI, GDEPOID AS DEPOID, DEPOFIS.ISLEM, DEPOFISISL.STOKID, DEPOFISISL.ACIKLAMA, DEPOFISISL.MIKTAR AS GCADET,
                      DEPOFISISL.BFIYAT, 0 AS SATIRIND, 0 AS SATIRIND2, ENO AS FATNO, '' AS KODU, '' AS CARIUNVANI, DEPOFISISL.BFIYAT AS NFIYAT, STOK.ADI,
                      DEPOFISISL.BFIYAT * DEPOFISISL.MIKTAR AS TOPLAM, 0 AS INDORAN1, 0 AS EKORAN1, 0 AS INDORAN2, 0 AS EKORAN2, 0 AS INDORAN3,
                      0 AS EKORAN3, NULL AS BAYIID, NULL AS SATISTID, STOK.SALISFIYAT, NULL AS BAYI, NULL AS SATIST, STOK.KODU AS STOKKODU,
                      DEPOFIS.TARIH, NULL AS VADE, DEPOFISISL.DEPOFISID AS FATID, 0 AS SATICIKOMORAN, 0 AS STKOMORAN, 0 AS BKOMORAN, 0 AS IRSALIYE, '' AS FATGRUP,
                      CDEPOID AS KDEPOID, STOK.GRUP AS SGRUPKODU, DEPOFIS.GSKODU,ISLEMDETAY,DEPOFISISL.DEPOFISISLID SATIRKNO
FROM         (STOK INNER JOIN
                      DEPOFISISL ON STOK.STOKID = DEPOFISISL.STOKID) INNER JOIN
                      DEPOFIS ON DEPOFISISL.DEPOFISID = DEPOFIS.DEPOFISID
WHERE     (((DEPOFIS.GDEPOID) > 0))
UNION ALL
SELECT     'DEPOFIS' AS FISTIPI, CDEPOID AS DEPOID, DEPOFIS.ISLEM, DEPOFISISL.STOKID, DEPOFISISL.ACIKLAMA, DEPOFISISL.MIKTAR * - 1 AS GCADET,
                      DEPOFISISL.BFIYAT, 0 AS SATIRIND, 0 AS SATIRIND2, ENO AS FATNO, '' AS KODU, '' AS CARIUNVANI, BFIYAT AS NFIYAT, STOK.ADI,
                      BFIYAT * MIKTAR * - 1 AS TOPLAM, 0 AS INDORAN1, 0 AS EKORAN1, 0 AS INDORAN2, 0 AS EKORAN2, 0 AS INDORAN3, 0 AS EKORAN3, NULL
                      AS BAYIID, NULL AS SATISTID, STOK.SALISFIYAT, NULL AS BAYI, NULL AS SATIST, STOK.KODU AS STOKKODU, DEPOFIS.TARIH, NULL AS VADE,
                      DEPOFISISL.DEPOFISID AS FATID, NULL AS SATICIKOMORAN, 0 AS STKOMORAN, 0 AS BKOMORAN, 0 AS IRSALIYE, '' AS FATGRUP, GDEPOID AS KDEPOID,
                      STOK.GRUP AS SGRUPKODU, DEPOFIS.CSKODU,ISLEMDETAY,DEPOFISISL.DEPOFISISLID SATIRKNO
FROM         (STOK INNER JOIN
                      DEPOFISISL ON STOK.STOKID = DEPOFISISL.STOKID) INNER JOIN
                      DEPOFIS ON DEPOFISISL.DEPOFISID = DEPOFIS.DEPOFISID
WHERE     (((DEPOFIS.CDEPOID) > 0))




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW [dbo].[UCHESAP]
AS
SELECT     TOP 100 PERCENT HESAPID, KODU, ACIKLAMA, DOVTURU, SKODU
FROM         dbo.HESAP
WHERE     (UCHESAP = 1)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW VETS_CARI AS
SELECT     ETS_CARI.CARIID, ETS_CARI.KODU, ETS_CARI.UNVANI, ETS_CARI.ADRES1, ETS_CARI.ADRES2, ETS_CARI.SEHIR, ETS_CARI.PKODU, ETS_CARI.ULKE,
                      ETS_CARI.VD, ETS_CARI.VDNO, ETS_CARI.EMAIL, ETS_CARI.WEB, ETS_CARI.YETKILI, ETS_CARI.TEL1, ETS_CARI.TEL2, ETS_CARI.FAX, ETS_CARI.GSM,
                      ETS_CARI.AFIYATNO, ETS_CARI.STDIND, ETS_CARI.VADEGUN, ETS_CARI.FKODU, ETS_CARI.ALISIND, ETS_CARI.TIP, ETS_CARI.KARTNO,
                      ETS_CARI.STATUSU, ETS_CARI.DOVIZ, ETS_CARI.CGRUBU, ETS_CARI.KLIMITI, ETS_CARI.GKODU, ETS_CARI.KARTTURU, ETS_CARI.INDORAN,
                      ETS_CARI.ASIMORAN, ETS_CARI.HESAPID, HESAP.KODU AS HESAPKODU, HESAP.ACIKLAMA AS HESAPADI,
                      HESAP.DOVTURU AS HESAPDOVIZ
FROM         ETS_CARI LEFT OUTER JOIN
                      HESAP ON ETS_CARI.HESAPID = HESAP.HESAPID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_DEPO AS
SELECT     dbo.DEPO.DEPOID, dbo.DEPO.DEPOADI, dbo.DEPO.ANADEPO, dbo.DEPO.SKODU, dbo.SUBELER.SUBEADI, dbo.DEPO.KODU,dbo.DEPO.MASMERID, MM.KODU MASMERKODU,MM.ACIKLAMA MASMERADI
FROM         dbo.DEPO LEFT OUTER JOIN
                      dbo.SUBELER ON dbo.DEPO.SKODU  = dbo.SUBELER.SUBEKODU  
                         LEFT OUTER JOIN MASMER MM ON MM.MASMERID = dbo.DEPO.MASMERID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_FIS
AS
SELECT     dbo.FIS.COUNTER, dbo.FIS.TARIH, dbo.FIS.FISNO, dbo.FIS.FISTURU, dbo.FIS.KASAID, dbo.HESAP.KODU AS KASAKODU,
                      dbo.HESAP.ACIKLAMA AS KASAADI, dbo.FIS.ACIKLAMA, dbo.FIS.BORC, dbo.FIS.ALACAK, dbo.FIS.BELGENO, dbo.FIS.OZELKOD, dbo.FIS.YETKILI,
                      dbo.FIS.DBORC, dbo.FIS.DALACAK, dbo.FIS.YEVNO, dbo.FIS.SKODU, dbo.SUBELER.SUBEADI, dbo.FIS.AKTCOUNTER, dbo.FIS.DEGISTIREN,
                      dbo.FIS.DURUM
FROM         dbo.FIS LEFT OUTER JOIN
                      dbo.SUBELER ON dbo.FIS.SKODU  = dbo.SUBELER.SUBEKODU   LEFT OUTER JOIN
                      dbo.HESAP ON dbo.FIS.KASAID = dbo.HESAP.HESAPID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_HESAP
AS
SELECT     dbo.HESAP.HESAPID, dbo.HESAP.KODU, dbo.HESAP.ACIKLAMA, dbo.HESAP.ACIKLAMA2, dbo.HESAP.ACIKLAMA3, dbo.HESAP.TIP, dbo.HESAP.CSEKLI, 
                      dbo.HESAP.OZELKOD, dbo.HESAP.OZELKOD2, dbo.HESAP.MASMERID, dbo.MASMER.KODU AS MASMERKODU, 
                      dbo.MASMER.ACIKLAMA AS MASMERACIKLAMA, dbo.HESAP.MIKBIRIM, dbo.HESAP.DOVTURU, dbo.HESAP.SEVIYE, dbo.HESAP.KEBIR, 
                      dbo.HESAP.MGOSTERME, dbo.HESAP.UCHESAP, dbo.HESAP.SKODU, dbo.HESAP.SMASRAF, dbo.MASMER.GRUBU AS MMGRUBU, 
                      dbo.HESAP.FAALIYETICI
FROM         dbo.HESAP LEFT OUTER JOIN
                      dbo.MASMER ON dbo.HESAP.MASMERID = dbo.MASMER.MASMERID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_SSAYIM_TUMU AS
SELECT SAYIMID,
DEPOID, STOKID, BASTARIH, TARIH, GADET, CADET, ORTFIYAT, DEVIR, ALIS, IADE, GIREN, CIKAN, ATRANS, ETRANS, TUKETIM, ZAYI, ARTIFARK,
EKSIFARK, DEVIR+ALIS+IADE+GIREN+CIKAN+ATRANS+ETRANS+TUKETIM+ZAYI+ARTIFARK+EKSIFARK AS KALAN, SAYIM,
SAYIM - (DEVIR+ALIS+IADE+GIREN+CIKAN+ATRANS+ETRANS+TUKETIM+ZAYI+ARTIFARK+EKSIFARK) AS FARK,
DEVIR+ALIS+IADE+GIREN+CIKAN+ATRANS+ETRANS AS DONEMTOPLAM, (DEVIR+ALIS+IADE+GIREN+CIKAN+ATRANS+ETRANS)-SAYIM AS DONEMTUKETIM,
DEVIRT, ALIST, IADET, GIRENT, CIKANT, ATRANST, ETRANST, TUKETIMT, ZAYIT, ARTIFARKT, EKSIFARKT,
(DEVIRT+ ALIST+ IADET+ GIRENT+ CIKANT+ ATRANST+ ETRANST+ TUKETIMT+ ZAYIT+ ARTIFARKT+ EKSIFARKT) AS KALANT,
SAYIM * ORTFIYAT AS SAYIMT,
(SAYIM - (DEVIR+ALIS+IADE+GIREN+CIKAN+ATRANS+ETRANS+TUKETIM+ZAYI+ARTIFARK+EKSIFARK))*ORTFIYAT AS FARKT,
DEVIRT+ALIST+IADET+GIRENT+CIKANT+ATRANST+ETRANST AS DONEMTOPLAMT,
((DEVIR+ALIS+IADE+GIREN+CIKAN+ATRANS+ETRANS)-SAYIM)*ORTFIYAT AS DONEMTUKETIMT,
((DEVIRT+ALIST+IADET+GIRENT+CIKANT+ATRANST+ETRANST)-(SAYIM*ORTFIYAT)) AS DONEMTUKETIMT2,
'SSAYIM' AS TABLO
FROM         dbo.SSAYIM



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_STOKGRUP
AS
SELECT     TOP 100 PERCENT dbo.STOKGRUP.KODU, dbo.STOKGRUP.ADI, dbo.STOKGRUP.TURU, SUBSTRING(dbo.STOKGRUP.KODU, 1,
                      ISNULL(dbo.STOKGRUP.ANAGRUPUZUNLUGU, 2)) AS ANAGRUPKODU, ANASTOKGRUP.ADI AS ANAGRUPADI, SUBSTRING(dbo.STOKGRUP.KODU, 1,
                      ISNULL(dbo.STOKGRUP.ALTGRUPUZUNLUGU, 4)) AS ALTGRUPKODU, ALTSTOKGRUP.ADI AS ALTGRUPADI, SUBSTRING(dbo.STOKGRUP.KODU, 1,
                      ISNULL(dbo.STOKGRUP.ALT2GRUPUZUNLUGU, 6)) AS ALT2GRUPKODU, ALT2STOKGRUP.ADI AS ALT2GRUPADI, dbo.STOKGRUP.OZELKOD1,
                      dbo.STOKGRUP.SAKLA, dbo.STOKGRUP.MUHNHESAPID AS STOKHESAPID, HESAPSTOK.KODU AS STOKHESAPKODU,
                      HESAPSTOK.ACIKLAMA AS STOKHESAPADI, dbo.STOKGRUP.MUHSHESAPID AS SARFHESAPID, HESAPSARF.KODU AS SARFHESAPKODU,
                      HESAPGELIR.ACIKLAMA AS SARFHESAPADI, dbo.STOKGRUP.MUHGHESAPID AS GELIRHESAPID, HESAPGELIR.KODU AS GELIRHESAPKODU,
                      HESAPGELIR.ACIKLAMA AS GELIRHESAPADI
FROM         dbo.STOKGRUP LEFT OUTER JOIN
                      dbo.STOKGRUP AS ALT2STOKGRUP ON SUBSTRING(dbo.STOKGRUP.KODU, 1, ISNULL(dbo.STOKGRUP.ALT2GRUPUZUNLUGU, 6))
                      = ALT2STOKGRUP.KODU LEFT OUTER JOIN
                      dbo.STOKGRUP AS ALTSTOKGRUP ON SUBSTRING(dbo.STOKGRUP.KODU, 1, ISNULL(dbo.STOKGRUP.ALTGRUPUZUNLUGU, 4))
                      = ALTSTOKGRUP.KODU LEFT OUTER JOIN
                      dbo.STOKGRUP AS ANASTOKGRUP ON SUBSTRING(dbo.STOKGRUP.KODU, 1, ISNULL(dbo.STOKGRUP.ANAGRUPUZUNLUGU, 2))
                      = ANASTOKGRUP.KODU LEFT OUTER JOIN
                      dbo.HESAP AS HESAPGELIR ON dbo.STOKGRUP.MUHGHESAPID = HESAPGELIR.HESAPID LEFT OUTER JOIN
                      dbo.HESAP AS HESAPSTOK ON dbo.STOKGRUP.MUHNHESAPID = HESAPSTOK.HESAPID LEFT OUTER JOIN
                      dbo.HESAP AS HESAPSARF ON dbo.STOKGRUP.MUHSHESAPID = HESAPSARF.HESAPID
WHERE     (dbo.STOKGRUP.TURU = N'STOK')
ORDER BY dbo.STOKGRUP.KODU



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO





CREATE VIEW dbo.VETS_URUNGRUP
AS
SELECT     TOP 100 PERCENT dbo.STOKGRUP.KODU, dbo.STOKGRUP.ADI, dbo.STOKGRUP.TURU, SUBSTRING(dbo.STOKGRUP.KODU, 1,
                      ISNULL(dbo.STOKGRUP.ANAGRUPUZUNLUGU, 2)) AS ANAGRUPKODU, ANASTOKGRUP.ADI AS ANAGRUPADI, SUBSTRING(dbo.STOKGRUP.KODU, 1,
                      ISNULL(dbo.STOKGRUP.ALTGRUPUZUNLUGU, 4)) AS ALTGRUPKODU, ALTSTOKGRUP.ADI AS ALTGRUPADI, SUBSTRING(dbo.STOKGRUP.KODU, 1,
                      ISNULL(dbo.STOKGRUP.ALT2GRUPUZUNLUGU, 6)) AS ALT2GRUPKODU, ALT2STOKGRUP.ADI AS ALT2GRUPADI, dbo.STOKGRUP.OZELKOD1,
                      dbo.STOKGRUP.SAKLA, dbo.STOKGRUP.MUHNHESAPID AS STOKHESAPID, HESAPSARF.KODU AS STOKHESAPKODU,
                      HESAPSARF.ACIKLAMA AS STOKHESAPADI, dbo.STOKGRUP.MUHSHESAPID AS SARFHESAPID, HESAPGELIR.KODU AS SARFHESAPKODU,
                      HESAPGELIR.ACIKLAMA AS SARFHESAPADI, dbo.STOKGRUP.MUHGHESAPID AS GELIRHESAPID, HESAPSTOK.KODU AS GELIRHESAPKODU,
                      HESAPSTOK.ACIKLAMA AS GELIRHESAPADI
FROM         dbo.STOKGRUP LEFT OUTER JOIN
                      dbo.STOKGRUP AS ALT2STOKGRUP ON SUBSTRING(dbo.STOKGRUP.KODU, 1, ISNULL(dbo.STOKGRUP.ALT2GRUPUZUNLUGU, 6))
                      = ALT2STOKGRUP.KODU LEFT OUTER JOIN
                      dbo.STOKGRUP AS ALTSTOKGRUP ON SUBSTRING(dbo.STOKGRUP.KODU, 1, ISNULL(dbo.STOKGRUP.ALTGRUPUZUNLUGU, 4))
                      = ALTSTOKGRUP.KODU LEFT OUTER JOIN
                      dbo.STOKGRUP AS ANASTOKGRUP ON SUBSTRING(dbo.STOKGRUP.KODU, 1, ISNULL(dbo.STOKGRUP.ANAGRUPUZUNLUGU, 2))
                      = ANASTOKGRUP.KODU LEFT OUTER JOIN
                      dbo.HESAP AS HESAPGELIR ON dbo.STOKGRUP.MUHGHESAPID = HESAPGELIR.HESAPID LEFT OUTER JOIN
                      dbo.HESAP AS HESAPSTOK ON dbo.STOKGRUP.MUHNHESAPID = HESAPSTOK.HESAPID LEFT OUTER JOIN
                      dbo.HESAP AS HESAPSARF ON dbo.STOKGRUP.MUHSHESAPID = HESAPSARF.HESAPID
WHERE     (dbo.STOKGRUP.TURU = N'URUN')
ORDER BY dbo.STOKGRUP.KODU



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE VIEW dbo.VETS_URUN_SATIS
AS
SELECT     TOP 100 PERCENT dbo.DEPOFIS.SDEPART, dbo.DEPART.ADI AS DEPADI, dbo.DEPOFISISL.STOKID, dbo.STOK.KODU, dbo.STOK.ADI,
                      SUM(dbo.DEPOFISISL.MIKTAR) AS ADET, SUM(dbo.DEPOFISISL.MIKTAR * dbo.DEPOFISISL.BFIYAT) AS TUTAR, dbo.DEPOFIS.ISLEM,
                      dbo.DEPOFIS.TARIH
FROM         dbo.DEPOFIS INNER JOIN
                      dbo.DEPOFISISL ON dbo.DEPOFIS.DEPOFISID = dbo.DEPOFISISL.DEPOFISID INNER JOIN
                      dbo.STOK ON dbo.DEPOFISISL.STOKID = dbo.STOK.STOKID INNER JOIN
                      dbo.DEPART ON dbo.DEPOFIS.SDEPART = dbo.DEPART.KODU
WHERE     (dbo.DEPOFIS.ISLEM = 'SATIS')
GROUP BY dbo.DEPOFIS.SDEPART, dbo.DEPART.ADI, dbo.DEPOFISISL.STOKID, dbo.STOK.KODU, dbo.STOK.ADI, dbo.DEPOFIS.ISLEM,
                      dbo.DEPOFIS.TARIH
ORDER BY dbo.DEPOFIS.SDEPART, dbo.STOK.KODU



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VWETS_CARI
AS
SELECT     dbo.ETS_CARI.*, dbo.HESAP.KODU AS EHESAPKODU, dbo.HESAP.ACIKLAMA AS EHESAPACK, dbo.HESAP.DOVTURU AS EHESAODVZ
FROM         dbo.ETS_CARI LEFT OUTER JOIN
                      dbo.HESAP ON dbo.ETS_CARI.HESAPID = dbo.HESAP.HESAPID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO







CREATE VIEW VWETS_GUNLUKURUNSATISMALIYET
AS
SELECT TARIH,DEPART.KODU,DEPART.ADI,URUNID,STOK.ADI AS URUNADI,
MAX(SATIST) AS SATIST,
MAX(ODENMEZT) AS ODENMEZT,
MAX(IKRAMT) AS IKRAMT,
(MAX(SATIST)*SUM(TBL2.MALIYET))   AS SATISMALIYET,
(MAX(ODENMEZT)*SUM(TBL2.MALIYET)) AS ODENMEZMALIYET,
(MAX(IKRAMT)*SUM(TBL2.MALIYET))   AS IKRAMMALIYET,
MAX(SATISADET)               AS SATISADET,
MAX(ODENMEZADET)             AS ODENMEZADET,
MAX(IKRAMADET)               AS IKRAMADET
FROM
(
SELECT TARIH,ISLEM,SDEPART,SATIST,ODENMEZT,IKRAMT,SATISADET,ODENMEZADET,IKRAMADET,URUNID
,ORAN*ISNULL((
SELECT TOP 1 (FATISL.BFIYAT*(100 - ISNULL(FATISL.SATIRIND,0))/100 * (100 - ISNULL(FATISL.SATIRIND2,0))/100) As SFIYAT
      FROM STOK,FATISL,FATURA WHERE STOK.STOKID=FATISL.STOKID AND STOK.TURU='Hammadde' AND FATURA.FATID=FATISL.FATID AND  FATISL.STOKID=STOK.STOKID AND
      TURADI IN('ALI?','ALIS') AND FATISL.STOKID=RECETE.STOKID AND FATURA.TARIH<=TBL.TARIH ORDER BY TARIH DESC),0) AS MALIYET
 FROM (
		SELECT D.TARIH,D.ISLEM,D.SDEPART,DI.STOKID,
		SUM(CASE WHEN D.ISLEM='SATIS'   THEN MIKTAR*BFIYAT ELSE 0 END) AS SATIST,
		SUM(CASE WHEN D.ISLEM='ODENMEZ' THEN MIKTAR*BFIYAT ELSE 0 END) AS ODENMEZT,
		SUM(CASE WHEN D.ISLEM='IKRAM'   THEN MIKTAR*BFIYAT ELSE 0 END) AS IKRAMT,
		SUM(CASE WHEN D.ISLEM='SATIS'   THEN MIKTAR ELSE 0 END) AS SATISADET,
		SUM(CASE WHEN D.ISLEM='ODENMEZ' THEN MIKTAR ELSE 0 END) AS ODENMEZADET,
		SUM(CASE WHEN D.ISLEM='IKRAM'   THEN MIKTAR ELSE 0 END) AS IKRAMADET
		FROM DEPOFIS AS D,DEPOFISISL AS DI
		WHERE D.DEPOFISID=DI.DEPOFISID AND
		      ((D.LOGODANGELDI=0) OR (D.LOGODANGELDI IS NULL)) AND ((D.URUNFISID=0) OR (URUNFISID IS NULL))
		      AND D.ISLEM IN ('SATIS','ODENMEZ','IKRAM')
		GROUP BY D.TARIH,D.ISLEM,D.SDEPART,DI.STOKID
        ) AS TBL,RECETE
WHERE TBL.STOKID=RECETE.URUNID
) AS TBL2,DEPART,STOK
WHERE TBL2.SDEPART=DEPART.KODU AND
TBL2.URUNID=STOK.STOKID
GROUP BY
TARIH,DEPART.KODU,DEPART.ADI,TBL2.SDEPART,URUNID,STOK.ADI



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO





CREATE VIEW dbo.VWETS_HESAP_BAKIYE AS
SELECT     TOP 100 PERCENT HESAP.HESAPID, HESAP.KODU, LEFT('       ', LEN(HESAP.KODU) / 3) + HESAP.KODU AS MKODU, ACIKLAMA, DOVTURU,
                      MIKBIRIM AS MB, CASE WHEN LTRIM(DOVTURU) <> '' THEN DOVTURU ELSE 'TL' END AS DT, SUM(UCMIZAN.TBORC) AS TBORC,
                      SUM(UCMIZAN.TALACAK) AS TALACAK, CASE WHEN (SUM(UCMIZAN.TBORC) - SUM(UCMIZAN.TALACAK)) > 0 THEN (SUM(UCMIZAN.TBORC)
                      - SUM(UCMIZAN.TALACAK)) ELSE 0 END AS TBORCB, CASE WHEN (SUM(UCMIZAN.TALACAK) - SUM(UCMIZAN.TBORC))
                      > 0 THEN (SUM(UCMIZAN.TALACAK) - SUM(UCMIZAN.TBORC)) ELSE 0 END AS TALACAKB, SUM(UCMIZAN.TDBORC) AS TDBORC,
                      SUM(UCMIZAN.TDALACAK) AS TDALACAK, CASE WHEN (SUM(UCMIZAN.TDBORC) - SUM(UCMIZAN.TDALACAK)) > 0 THEN (SUM(UCMIZAN.TDBORC)
                      - SUM(UCMIZAN.TDALACAK)) ELSE 0 END AS TDBORCB, CASE WHEN (SUM(UCMIZAN.TDALACAK) - SUM(UCMIZAN.TDBORC))
                      > 0 THEN (SUM(UCMIZAN.TDALACAK) - SUM(UCMIZAN.TDBORC)) ELSE 0 END AS TDALACAKB, SUM(UCMIZAN.TMBORC) AS TMBORC,
                      SUM(UCMIZAN.TMALACAK) AS TMALACAK, CASE WHEN (SUM(UCMIZAN.TMBORC) - SUM(UCMIZAN.TMALACAK)) > 0 THEN (SUM(UCMIZAN.TMBORC)
                      - SUM(UCMIZAN.TMALACAK)) ELSE 0 END AS TMBORCB, CASE WHEN (SUM(UCMIZAN.TMALACAK) - SUM(UCMIZAN.TMBORC))
                      > 0 THEN (SUM(UCMIZAN.TMALACAK) - SUM(UCMIZAN.TMBORC)) ELSE 0 END AS TMALACAKB
FROM         (SELECT     1 AS UCHESAP, HESAPISL.HESAPID, HESAPISL.KODU, SUM(HESAPISL.BORC) AS TBORC, SUM(HESAPISL.ALACAK) AS TALACAK,
                                              SUM(HESAPISL.DBORC) AS TDBORC, SUM(HESAPISL.DALACAK) AS TDALACAK, SUM(HESAPISL.MBORC) AS TMBORC,
                                              SUM(HESAPISL.MALACAK) AS TMALACAK
                       FROM          (ETS_HESAPISL AS HESAPISL INNER JOIN
                                              HESAP ON HESAPISL.HESAPID = HESAP.HESAPID) INNER JOIN
                                              FIS ON HESAPISL.FISCOUNTER = FIS.COUNTER
                       GROUP BY HESAPISL.HESAPID, HESAPISL.KODU) AS UCMIZAN RIGHT JOIN
                      HESAP ON LEFT(UCMIZAN.KODU, LEN(HESAP.KODU)) = HESAP.KODU
GROUP BY HESAP.HESAPID, HESAP.KODU, HESAP.ACIKLAMA, DOVTURU, MIKBIRIM
ORDER BY HESAP.KODU



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO








CREATE VIEW dbo.VWETS_STOKGRUP
AS
SELECT     dbo.STOKGRUP.*, dbo.HESAP.KODU AS NMUHKODU, dbo.HESAP.ACIKLAMA AS NMUHADI, HESAP_1.KODU AS SMUHKODU,
                      HESAP_1.ACIKLAMA AS SMUHADI, HESAP_2.KODU AS GMUHKODU, HESAP_2.ACIKLAMA AS GMUHADI
FROM         dbo.STOKGRUP LEFT OUTER JOIN
                      dbo.HESAP HESAP_2 ON dbo.STOKGRUP.MUHGHESAPID = HESAP_2.HESAPID LEFT OUTER JOIN
                      dbo.HESAP ON dbo.STOKGRUP.MUHNHESAPID = dbo.HESAP.HESAPID LEFT OUTER JOIN
                      dbo.HESAP HESAP_1 ON dbo.STOKGRUP.MUHSHESAPID = HESAP_1.HESAPID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.qHESAPISL
AS
SELECT     dbo.ETS_HESAPISL.HESAPID, dbo.FIS.TARIH, dbo.FIS.FISNO, dbo.HESAP.KODU, dbo.ETS_HESAPISL.ACIKLAMA, dbo.ETS_HESAPISL.BORC, dbo.ETS_HESAPISL.ALACAK,
                      dbo.ETS_HESAPISL.DBORC, dbo.ETS_HESAPISL.DALACAK, dbo.ETS_HESAPISL.MBORC, dbo.ETS_HESAPISL.MALACAK, dbo.ETS_HESAPISL.MASMER, dbo.FIS.OZELKOD,
                      dbo.FIS.BELGENO, dbo.ETS_HESAPISL.COUNTER, dbo.ETS_HESAPISL.FISCOUNTER, dbo.FIS.SKODU,ETS_HESAPISL.VADE,ETS_HESAPISL.KAYITID,ETS_HESAPISL.OZELKOD SATIROZELKOD,
                      dbo.ETS_HESAPISL.MASMERID
FROM         dbo.FIS
INNER JOIN
   dbo.HESAP INNER JOIN
   dbo.ETS_HESAPISL ON dbo.HESAP.HESAPID = dbo.ETS_HESAPISL.HESAPID ON dbo.FIS.COUNTER = dbo.ETS_HESAPISL.FISCOUNTER



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_CARIISL
AS
SELECT     dbo.CARIISL.CARIISLID, dbo.CARIISL.CARIID, CARI1.UNVANI AS UNVANI1, CARI1.CGRUBU AS CGRUBU1, CARI1.HESAPID AS HESAPID1,
                      CARI1.HESAPKODU AS HESAPKODU1, CARI1.HESAPADI AS HESAPADI1, CARI1.HESAPDOVIZ AS EHESAPDOVIZ1, dbo.CARIISL.CARIID2,
                      CARI2.UNVANI AS UNVANI2, CARI2.CGRUBU AS CGRUBU2, CARI2.HESAPID AS HESAPID2, CARI2.HESAPKODU AS HESAPKODU2,
                      CARI2.HESAPADI AS HESAPADI2, CARI2.HESAPDOVIZ AS HESAPDOVIZ2, dbo.CARIISL.TARIH, dbo.CARIISL.VADE, dbo.CARIISL.ACIKLAMA,
                      dbo.CARIISL.EVRAKNO, dbo.CARIISL.ISLTUR, dbo.CARIISL.BORC, dbo.CARIISL.ALACAK, dbo.CARIISL.DBORC, dbo.CARIISL.DALACAK,
                      dbo.CARIISL.DOVIZ, dbo.CARIISL.FATCOUNTER, dbo.CARIISL.ISLEMNO, dbo.CARIISL.DURUM, dbo.CARIISL.KTARIH, dbo.CARIISL.KYAPAN,
                      dbo.CARIISL.MUHFC AS FISCOUNTER, dbo.FIS.TARIH AS FISTARIH, dbo.FIS.FISNO, dbo.FIS.FISTURU, dbo.FIS.ACIKLAMA AS FISACIKLAMA,
                      dbo.FIS.OZELKOD AS FISOZELKOD, dbo.CARIISL.OZELKOD, dbo.CARIISL.SKODU, dbo.SUBELER.SUBEADI, dbo.CARIISL.GKODU,
                      dbo.CARIISL.GGRUBU, dbo.GELIRGRUP.ADI AS GELIRGRUBUADI, dbo.GELIRGRUP.KDV AS GELIRGRUBUKDV, dbo.CARIISL.DEPT,
                      dbo.DEPART.ADI AS DEPARTADI, dbo.DEPART.TUR AS DEPARTTUR, dbo.DEPART.KDV AS DEPARTKDV, dbo.CARIISL.ADISYONID,
                      dbo.CARIISL.TAMAMLANDI, dbo.CARIISL.CIHESAPID, dbo.CARIISL.CIHESAPID2, dbo.CARIISL.KDVTUTAR, dbo.CARIISL.KDVHESAPID,
                      dbo.CARIISL.GDR1TUTAR, dbo.CARIISL.GDR1HESAPID, dbo.CARIISL.GDR2TUTAR, dbo.CARIISL.GDR2HESAPID, dbo.CARIISL.GDR3TUTAR,
                      dbo.CARIISL.GDR3HESAPID, dbo.CARIISL.STP1TUTAR, dbo.CARIISL.STP1HESAPID, dbo.CARIISL.STP2TUTAR, dbo.CARIISL.STP2HESAPID
FROM         dbo.CARIISL LEFT OUTER JOIN
                      dbo.DEPART ON dbo.CARIISL.DEPT  = dbo.DEPART.KODU   LEFT OUTER JOIN
                      dbo.GELIRGRUP ON dbo.CARIISL.GGRUBU  = dbo.GELIRGRUP.KODU   LEFT OUTER JOIN
                      dbo.SUBELER ON dbo.CARIISL.SKODU  = dbo.SUBELER.SUBEKODU   LEFT OUTER JOIN
                      dbo.FIS ON dbo.CARIISL.MUHFC = dbo.FIS.COUNTER LEFT OUTER JOIN
                      dbo.VETS_CARI AS CARI1 ON dbo.CARIISL.CARIID2 = CARI1.CARIID LEFT OUTER JOIN
                      dbo.VETS_CARI AS CARI2 ON dbo.CARIISL.CARIID = CARI2.CARIID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



CREATE VIEW dbo.VETS_HESAPISL
AS
SELECT     dbo.ETS_HESAPISL.COUNTER, dbo.ETS_HESAPISL.FISCOUNTER, dbo.ETS_HESAPISL.HESAPID, dbo.VETS_HESAP.KODU, dbo.VETS_HESAP.ACIKLAMA AS HESAPADI, 
                      dbo.VETS_HESAP.TIP AS HESAPTIPI, dbo.VETS_HESAP.DOVTURU AS HESAPDVZ, dbo.ETS_HESAPISL.ACIKLAMA, dbo.ETS_HESAPISL.BORC, 
                      dbo.ETS_HESAPISL.ALACAK, dbo.ETS_HESAPISL.DBORC, dbo.ETS_HESAPISL.DALACAK, dbo.ETS_HESAPISL.MBORC, dbo.ETS_HESAPISL.MALACAK, dbo.ETS_HESAPISL.MASMER, 
                      dbo.ETS_HESAPISL.OZELKOD, dbo.ETS_HESAPISL.VADE, dbo.ETS_HESAPISL.KUR, dbo.ETS_HESAPISL.KAYITID, dbo.ETS_HESAPISL.YETKILI, dbo.VETS_FIS.TARIH, 
                      dbo.VETS_FIS.FISNO, dbo.VETS_FIS.FISTURU, dbo.VETS_FIS.ACIKLAMA AS FISACIKLAMA, dbo.VETS_FIS.BELGENO, 
                      dbo.VETS_FIS.OZELKOD AS FISOZELKOD, dbo.VETS_FIS.YETKILI AS FISYETKILI, dbo.VETS_FIS.YEVNO, dbo.VETS_FIS.SKODU, 
                      dbo.VETS_FIS.SUBEADI, dbo.ETS_HESAPISL.DEGISTIREN, dbo.VETS_HESAP.MMGRUBU, dbo.VETS_HESAP.FAALIYETICI
FROM         dbo.ETS_HESAPISL INNER JOIN
                      dbo.VETS_HESAP ON dbo.ETS_HESAPISL.HESAPID = dbo.VETS_HESAP.HESAPID INNER JOIN
                      dbo.VETS_FIS ON dbo.ETS_HESAPISL.FISCOUNTER = dbo.VETS_FIS.COUNTER



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO








CREATE VIEW dbo.VWETS_CARIISL
AS
SELECT     dbo.CARIISL.*, CARI1.UNVANI AS UNVANI1, CARI1.HESAPID AS HESAPID1, CARI1.EHESAPKODU AS EHESAPKODU1,
                      CARI1.EHESAPACK AS EHESAPACK1, CARI1.EHESAODVZ AS EHESAODVZ1, CARI2.UNVANI AS UNVANI2, CARI2.EHESAPKODU AS EHESAPKODU2,
                      CARI2.EHESAPACK AS EHESAPACK2, CARI2.EHESAODVZ AS EHESAODVZ2
FROM         dbo.CARIISL LEFT OUTER JOIN
                      dbo.VWETS_CARI CARI1 ON dbo.CARIISL.CARIID2 = CARI1.CARIID LEFT OUTER JOIN
                      dbo.VWETS_CARI CARI2 ON dbo.CARIISL.CARIID = CARI2.CARIID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE VIEW dbo.VWETS_FATURA
AS
SELECT     dbo.FATURA.*, dbo.VWETS_CARI.UNVANI AS CUNVANI, dbo.VWETS_CARI.VD AS CVD, dbo.VWETS_CARI.VDNO AS CVDNO,
                      dbo.VWETS_CARI.STDIND AS CSTDIND, dbo.VWETS_CARI.VADEGUN AS CVADEGUN, dbo.VWETS_CARI.FKODU AS CFKODU,
                      dbo.VWETS_CARI.EHESAPKODU AS CHESAPKODU, dbo.VWETS_CARI.HESAPID AS CHESAPID
FROM         dbo.FATURA LEFT OUTER JOIN
                      dbo.VWETS_CARI ON dbo.FATURA.CARIID = dbo.VWETS_CARI.CARIID
WHERE     (dbo.FATURA.FIPTAL = 0)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO








CREATE VIEW dbo.VWETS_CARIISL_BY_OZELKOD
AS
SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, OZELKOD, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(ISNULL(BORC, 0) + ISNULL(ALACAK, 0))
                      AS TUTAR, COUNT(*) AS ISLADET
FROM         dbo.VWETS_CARIISL
GROUP BY OZELKOD, MONTH(TARIH), YEAR(TARIH)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO




CREATE PROCEDURE DEPOFISIKES 
@ISLEM AS NVARCHAR(10),
@STOKID AS INT,
@SKODU AS NVARCHAR(10),
@GDEPOID AS INT,
@CDEPOID AS INT,
@TARIH AS DATETIME,
@ADET AS FLOAT,
@SFIYAT AS FLOAT,
@YETKILI AS NVARCHAR(15),
@ACIKLAMA AS NVARCHAR(200),
@ISLREFID AS INT
AS
DECLARE @FISID AS INT
DECLARE @ISLID AS INT

IF NOT EXISTS (SELECT STOKID FROM STOK WHERE STOKID = @STOKID)
BEGIN
   RAISERROR('Stok Kart? bulunamad?',16,1)
   RETURN 1
END

IF (@ISLEM='?IKI?') OR (@ISLEM='TRANSFER') OR (@ISLEM='sRET~M') 
IF NOT EXISTS (SELECT DEPOID FROM DEPO WHERE DEPOID = @GDEPOID)
BEGIN
   RAISERROR('GiriY Depo Kart? bulunamad?',16,1)
   RETURN 2
END

IF (@ISLEM='?IKI?') OR (@ISLEM='TRANSFER') OR (@ISLEM='TsKET~M')  OR (@ISLEM='ZAY~') 
IF NOT EXISTS (SELECT DEPOID FROM DEPO WHERE DEPOID = @CDEPOID)
BEGIN
   RAISERROR('??k?Y Depo Kart? bulunamad?',16,1)
   RETURN 2
END

IF ((@ISLEM='?IKI?') OR (@ISLEM='TRANSFER'))  AND (@GDEPOID=@CDEPOID) 
  RETURN 

SELECT @FISID = DEPOFISID FROM DEPOFIS WHERE TARIH = @TARIH AND ISLEM = @ISLEM AND 
                                                                                              GSKODU = @SKODU AND CSKODU = @SKODU AND
                                                                                              GDEPOID = @GDEPOID AND CDEPOID = @CDEPOID AND 
                                                                                              ACIKLAMA = 'Otomatik Depo ~Ylemi~'
IF @@ROWCOUNT=0  --FIS EKLEYELIM
BEGIN
  EXEC SAYACOKU 'DEPOFIS',@FISID OUTPUT
  INSERT INTO DEPOFIS([DEPOFISID],[TARIH], [YETKILI], [ISLEM], [ENO], [ACIKLAMA], [GSKODU], [CSKODU], [GDEPOID], [CDEPOID], [TADET], [TTUTAR])
                            VALUES (@FISID,@TARIH,@YETKILI,@ISLEM,CAST(@FISID AS NVARCHAR(10)),'Otomatik Depo ~Ylemi~',@SKODU,@SKODU,@GDEPOID,@CDEPOID,0,0)
  IF @@ERROR<>0 
  BEGIN
    RAISERROR('Depo fiYi eklenemedi.',16,1)
    RETURN 4
  END
END

--SIMDI SATIRI EKLEYELIM
--  EXEC SAYACOKU 'DEPOFISISL',@ISLID  OUTPUT
  INSERT INTO DEPOFISISL(/*[DEPOFISISLID],*/ [DEPOFISID], [STOKID], [MIKTAR], [BFIYAT],[SFIYAT],[YETKILI],[ACIKLAMA],[ISLREFID])
  VALUES (/*@ISLID,*/@FISID,@STOKID,@ADET,@SFIYAT,@SFIYAT,@YETKILI,@ACIKLAMA,@ISLREFID)
  IF @@ERROR<>0 
  BEGIN
    RAISERROR('Depo iYlemi eklenemedi.',16,1)
    RETURN 5
  END

  UPDATE DEPOFIS SET TADET = (ISL.ADET) , TTUTAR=(ISL.TUTAR) 
   FROM DEPOFIS INNER JOIN (SELECT DEPOFISID,COUNT(*) AS ADET, SUM(MIKTAR*BFIYAT) AS TUTAR FROM DEPOFISISL WHERE DEPOFISID=@FISID GROUP BY DEPOFISID) AS ISL 
      ON ISL.DEPOFISID=DEPOFIS.DEPOFISID 
   WHERE DEPOFIS.DEPOFISID=@FISID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO





CREATE PROCEDURE DEPOFISISLDUZELT
@ISLEM AS NVARCHAR(10),
@STOKID AS INT,
@SKODU AS NVARCHAR(10),
@GDEPOID AS INT,
@CDEPOID AS INT,
@TARIH AS DATETIME,
@ADET AS FLOAT,
@SFIYAT AS FLOAT,
@YETKILI AS NVARCHAR(15),
@ACIKLAMA AS NVARCHAR(200),
@ISLREFID AS INT
AS
DECLARE @FISID AS INT
DECLARE @ISLID AS INT

IF NOT EXISTS (SELECT STOKID FROM STOK WHERE STOKID = @STOKID)
BEGIN
   RAISERROR('Stok Kart? bulunamad?',16,1)
   RETURN 1
END

IF (@ISLEM='?IKI?') OR (@ISLEM='TRANSFER') OR (@ISLEM='sRET~M') 
IF NOT EXISTS (SELECT DEPOID FROM DEPO WHERE DEPOID = @GDEPOID)
BEGIN
   RAISERROR('GiriY Depo Kart? bulunamad?',16,1)
   RETURN 2
END

IF (@ISLEM='?IKI?') OR (@ISLEM='TRANSFER') OR (@ISLEM='TsKET~M')  OR (@ISLEM='ZAY~') 
IF NOT EXISTS (SELECT DEPOID FROM DEPO WHERE DEPOID = @CDEPOID)
BEGIN
   RAISERROR('??k?Y Depo Kart? bulunamad?',16,1)
   RETURN 2
END

IF ((@ISLEM='?IKI?') OR (@ISLEM='TRANSFER'))  AND (@GDEPOID=@CDEPOID) 
  RETURN 

SELECT @FISID = DEPOFISISL.DEPOFISID, @ISLID = DEPOFISISLID 
FROM DEPOFISISL INNER JOIN DEPOFIS ON DEPOFISISL.DEPOFISID = DEPOFIS.DEPOFISID 
WHERE ISLEM=@ISLEM AND ISLREFID = @ISLREFID

IF @@ROWCOUNT=1  -- ~?LEM SATIRI BULUNDU
  UPDATE DEPOFISISL SET MIKTAR = @ADET,  BFIYAT = @SFIYAT,  SFIYAT = @SFIYAT, ACIKLAMA = @ACIKLAMA WHERE DEPOFISISLID = @ISLID
ELSE
  RETURN

  UPDATE DEPOFIS SET TADET = (ISL.ADET) , TTUTAR=(ISL.TUTAR) 
   FROM DEPOFIS INNER JOIN (SELECT DEPOFISID,COUNT(*) AS ADET, SUM(MIKTAR*BFIYAT) AS TUTAR FROM DEPOFISISL WHERE DEPOFISID=@FISID GROUP BY DEPOFISID) AS ISL 
      ON ISL.DEPOFISID=DEPOFIS.DEPOFISID 
   WHERE DEPOFIS.DEPOFISID=@FISID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO




CREATE PROCEDURE DEPOFISISLSIL 
@ISLEM AS NVARCHAR(10),
@STOKID AS INT,
@SKODU AS NVARCHAR(10),
@GDEPOID AS INT,
@CDEPOID AS INT,
@TARIH AS DATETIME,
@ADET AS FLOAT,
@SFIYAT AS FLOAT,
@YETKILI AS NVARCHAR(15),
@ACIKLAMA AS NVARCHAR(200),
@ISLREFID AS INT
AS
DECLARE @FISID AS INT
DECLARE @ISLID AS INT

IF NOT EXISTS (SELECT STOKID FROM STOK WHERE STOKID = @STOKID)
BEGIN
   RAISERROR('Stok Kart? bulunamad?',16,1)
   RETURN 1
END

IF (@ISLEM='?IKI?') OR (@ISLEM='TRANSFER') OR (@ISLEM='sRET~M') 
IF NOT EXISTS (SELECT DEPOID FROM DEPO WHERE DEPOID = @GDEPOID)
BEGIN
   RAISERROR('GiriY Depo Kart? bulunamad?',16,1)
   RETURN 2
END

IF (@ISLEM='?IKI?') OR (@ISLEM='TRANSFER') OR (@ISLEM='TsKET~M')  OR (@ISLEM='ZAY~') 
IF NOT EXISTS (SELECT DEPOID FROM DEPO WHERE DEPOID = @CDEPOID)
BEGIN
   RAISERROR('??k?Y Depo Kart? bulunamad?',16,1)
   RETURN 2
END

IF ((@ISLEM='?IKI?') OR (@ISLEM='TRANSFER'))  AND (@GDEPOID=@CDEPOID) 
  RETURN 

SELECT @FISID = DEPOFISISL.DEPOFISID, @ISLID = DEPOFISISLID 
FROM DEPOFISISL INNER JOIN DEPOFIS ON DEPOFISISL.DEPOFISID = DEPOFIS.DEPOFISID 
WHERE ISLEM=@ISLEM AND ISLREFID = @ISLREFID

IF @@ROWCOUNT=1  -- ~?LEM SATIRI BULUNDU
BEGIN
  UPDATE DEPOFISISL SET MIKTAR = MIKTAR - @ADET WHERE DEPOFISISLID = @ISLID
END
ELSE
BEGIN
   -- ESK~DEN G~R~LM~? ~LA? VE MALZEMELER
   SELECT @FISID = DEPOFISID FROM DEPOFIS WHERE TARIH = @TARIH AND ISLEM = @ISLEM AND 
	                                                                                              GSKODU = @SKODU AND CSKODU = @SKODU AND
	                                                                                              GDEPOID = @GDEPOID AND CDEPOID = @CDEPOID AND 
	                                                                                              ACIKLAMA = 'Otomatik Depo ~Ylemi~'
   IF @@ROWCOUNT=0  --F~? YOK
   BEGIN
     EXEC SAYACOKU 'DEPOFIS',@FISID OUTPUT
     INSERT INTO DEPOFIS([DEPOFISID],[TARIH], [YETKILI], [ISLEM], [ENO], [ACIKLAMA], [GSKODU], [CSKODU], [GDEPOID], [CDEPOID], [TADET], [TTUTAR])
                               VALUES (@FISID,@TARIH,@YETKILI,@ISLEM,CAST(@FISID AS NVARCHAR(10)),'Otomatik Depo ~Ylemi~',@SKODU,@SKODU,@GDEPOID,@CDEPOID,0,0)
     IF @@ERROR<>0 
     BEGIN
       RAISERROR('Depo fiYi eklenemedi.',16,1)
       RETURN 4
     END
   END
   
   --SIMDI SATIRI EKLEYELIM
   --  EXEC SAYACOKU 'DEPOFISISL',@ISLID  OUTPUT
     INSERT INTO DEPOFISISL(/*[DEPOFISISLID],*/ [DEPOFISID], [STOKID], [MIKTAR], [BFIYAT],[SFIYAT],[YETKILI],[ACIKLAMA])
     VALUES (/*@ISLID,*/@FISID,@STOKID,-1*@ADET,@SFIYAT,@SFIYAT,@YETKILI,@ACIKLAMA)
     IF @@ERROR<>0 
     BEGIN
       RAISERROR('Depo iYlemi eklenemedi.',16,1)
       RETURN 5
     END
END

  UPDATE DEPOFIS SET TADET = (ISL.ADET) , TTUTAR=(ISL.TUTAR) 
   FROM DEPOFIS INNER JOIN (SELECT DEPOFISID,COUNT(*) AS ADET, SUM(MIKTAR*BFIYAT) AS TUTAR FROM DEPOFISISL WHERE DEPOFISID=@FISID GROUP BY DEPOFISID) AS ISL 
      ON ISL.DEPOFISID=DEPOFIS.DEPOFISID 
   WHERE DEPOFIS.DEPOFISID=@FISID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[DUZELT] AS
UPDATE FATURA SET TARIH = CAST(FLOOR(CAST(TARIH AS FLOAT)) AS SMALLDATETIME) WHERE CAST(TARIH AS FLOAT) <> FLOOR(CAST(TARIH AS FLOAT))



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE dbo.ENTALIS 

AS 
BEGIN

DECLARE @HATANO INT
DECLARE @FATID  INTEGER
DECLARE @CARIID INTEGER
DECLARE @TARIH  DATETIME
DECLARE @SONTARIH  DATETIME
DECLARE @FATNO  NVARCHAR(30)
DECLARE @STOKID INTEGER
DECLARE @KDV    FLOAT
DECLARE @TOPLAM FLOAT
DECLARE @SubeKodu NVARCHAR(10)
DECLARE @FATURAACIKLAMA NVARCHAR(255)
DECLARE @HATAMSG NVARCHAR(255)

DECLARE @FISCOUNTER NVARCHAR(10)
DECLARE @FISNO NVARCHAR(50)
DECLARE @Ozelkod  NVARCHAR(50)
DECLARE @OzelKod2 NVARCHAR(50)
DECLARE @FISACIKLAMA NVARCHAR(250)
DECLARE @TEKKDVHESABI INTEGER
DECLARE @STOKGRUPLU INTEGER
DECLARE @RS INTEGER
DECLARE @FATURAACIKLAMASI INTEGER
DECLARE @FISNOMESAJ INTEGER
DECLARE @TEKMAHSUPDABIRLESTIR INTEGER

DECLARE @CARIHESAPID INTEGER
DECLARE @CARIKODU NVARCHAR(50)
DECLARE @CARIUNVANI NVARCHAR(150)
DECLARE @CARIID2  INTEGER


DECLARE @SORUNLUSTOKKODU NVARCHAR(20)
DECLARE @SORUNLUSTOKADI NVARCHAR(100)
DECLARE @SORUNLUKDV NVARCHAR

DECLARE @FBORC   FLOAT
DECLARE @FALACAK FLOAT
DECLARE @FDBORC   FLOAT
DECLARE @FDALACAK FLOAT


SET @RS          = 7 -- :RS           -- 7
SET @SubeKodu    = '01' --:SUBEKODU
SET @Ozelkod     = '' --:OZELKOD
SET @OzelKod2    = 'EntAl?Y' -- :OZELKOD2     -- 
SET @FISACIKLAMA = 'Al?Y Faturalar? Entegrasyonu' --:FISACIKLAMA  -- 
SET @TEKKDVHESABI= 0 --:TEKKDVHESABI -- 0
SET @STOKGRUPLU  = 0 --:STOKGRUPLU   -- 0
SET @FATURAACIKLAMASI = 0 --:FATURAACIKLAMASI --1
SET @FISNOMESAJ       = 0 -- :FISNOMESAJ
SET @TEKMAHSUPDABIRLESTIR = 0 -- :TEKMAHSUPDABIRLESTIR

DECLARE DNCList CURSOR FOR

SELECT F.FATID,F.CARIID,F.TARIH,F.FATNO,F.SKODU,F.GTOPLAM,F.ACIKLAMA FROM FATURA F
--&FATNO
WHERE TARIH BETWEEN '07.01.2007' AND '07.31.2007' AND TURADI = 'ALIS' AND MUHFC  IS NULL


SET @FISNO = NULL

 OPEN DNCList
         FETCH NEXT FROM DNCList into @FATID,@CARIID,@TARIH,@FATNO,@SubeKodu,@TOPLAM,@FATURAACIKLAMA
         SET @SONTARIH = @TARIH

                 while @@fetch_status = 0
                 begin

SET @HATANO = 0

                     SET @CARIHESAPID = NULL
                     SET @CARIKODU = NULL
                     SET @CARIID2 = NULL
                     SET @CARIUNVANI = NULL

                     -- ETS_CARI hesab?n muhasebe kodunu oku
            SELECT @CARIHESAPID = C.HESAPID,@CARIKODU = C.KODU,@CARIID2 = C.CARIID,@CARIUNVANI = C.UNVANI FROM ETS_CARI C
            WHERE C.CARIID = @CARIID

            -- ETS_CARI hesab?n kart? yok.
            IF (@CARIID2 IS NULL)
               BEGIN
                RAISERROR('Faturada seÅili olan ETS_CARI kart bulunamad?.!!',16,1)
                CLOSE DNCList
                DEALLOCATE DNCList
                RETURN
               END

            -- ETS_CARI hesap kart?n?n muhasebe kodu yok
            IF (@CARIHESAPID IS NULL)
               BEGIN
                RAISERROR('%s kodlu ETS_CARI hesap iÅin muhasebe kodu seÅilmemiY.!!',16,1,@CARIKODU)
                CLOSE DNCList
                DEALLOCATE DNCList
                RETURN
               END
            -- ETS_CARI hesab?n muhasebe kodu hesap plan?nda yok.
            ELSE IF (NOT EXISTS(SELECT COUNT(*) FROM HESAP H WHERE H.HESAPID = @CARIHESAPID))
               BEGIN
                RAISERROR('%s kodlu ETS_CARI hesap iÅin seÅilen muhasebe kodu doõru g"r?nm?yor.!!',16,1,@CARIKODU)
                CLOSE DNCList
                DEALLOCATE DNCList
                RETURN
               END

            SET @SORUNLUSTOKKODU = NULL
            -- muhasebe kodu olamayan stok kart? kontrol?
            SELECT TOP 1  @SORUNLUSTOKKODU = S.KODU, @SORUNLUSTOKADI =S.ADI
            FROM FATISL FI
               LEFT JOIN STOK S ON S.STOKID = FI.STOKID
               LEFT JOIN STOKGRUP SG ON SG.KODU = S.GRUP
               LEFT JOIN HESAP H ON H.HESAPID = ISNULL(FI.HESAPID, SG.MUHNHESAPID)
            WHERE FI.FATID = @FATID AND H.HESAPID IS NULL
            -- muhasebe kodu olamayan stok kart? kontrol?
            IF (@SORUNLUSTOKKODU IS NOT NULL)
               BEGIN
                RAISERROR('%s kodlu stok kart? iÅin muhasebe kodu doõru g"r?nm?yor.!!',16,1,@SORUNLUSTOKKODU )
                CLOSE DNCList
                DEALLOCATE DNCList
                RETURN
               END



            SET @SORUNLUKDV = NULL

            SELECT @SORUNLUKDV = cast(FI.KDV as NVARCHAR)
             FROM FATISL FI
            LEFT JOIN HESAP H ON H.KODU =
              (SELECT TOP 1 C.VALUESTR FROM [CONFIG] C
               WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON' AND C.KEYNAME = 'Indirilecek  KDV Hesabi %'+RTRIM(CAST(FI.KDV AS NVARCHAR(3))))
            WHERE FI.FATID = @FATID
               AND FI.KDV > 0
               AND H.HESAPID IS NULL
            IF (@SORUNLUKDV IS NOT NULL)
               BEGIN
                RAISERROR('%s KDV oran? iÅin muhasebe kodu sorunlu g"r?n?yor.!!',16,1,@SORUNLUKDV)
                CLOSE DNCList
                DEALLOCATE DNCList
                RETURN
               END


            BEGIN TRANSACTION

            IF (@FATURAACIKLAMASI = 1)
                SET @FISACIKLAMA = @FATURAACIKLAMA

            IF (@TEKMAHSUPDABIRLESTIR = 0) OR (@FISCOUNTER IS NULL)
               BEGIN

                   EXEC SAYACOKU 'MUHFIS', @FISCOUNTER OUTPUT

                   INSERT INTO FIS ([COUNTER], TARIH, FISNO, FISTURU, ACIKLAMA, BORC, ALACAK,DBORC,DALACAK,BELGENO,OZELKOD,SKODU)
                   VALUES (@FISCOUNTER ,  @TARIH , @FISNO , 'MAHSUP' , @FISACIKLAMA,@TOPLAM,@TOPLAM,0,0,@Ozelkod,@OzelKod2,@SubeKodu)
                   IF @@ERROR != 0 
                       SET @HATANO = @@ERROR

                   SET @SONTARIH = @TARIH
               END
             ELSE
               BEGIN
                   IF (@TARIH > @SONTARIH)
                      SET @SONTARIH = @TARIH
               END

            INSERT INTO ETS_HESAPISL (FISCOUNTER,ACIKLAMA,HESAPID,BORC,ALACAK,KUR,DBORC,DALACAK,MBORC,MALACAK,MASMER,KAYITID,OZELKOD)
            SELECT @FISCOUNTER, CONVERT(varchar, @TARIH, 4)  + ' / ' + @FATNO + ' nl.Al?Y Fat '  ,ETS_CARI.HESAPID,0,ROUND(SUM(FATURA.GTOPLAM),2),CASE WHEN (FATURA.DOVIZKURU IS NULL) OR (FATURA.DOVIZKURU = 1) THEN 0 ELSE FATURA.DOVIZKURU END,0,CASE WHEN CASE WHEN (FATURA.DOVIZKURU IS NULL) OR (FATURA.DOVIZKURU = 1) THEN 0 ELSE FATURA.DOVIZKURU END = 0 THEN 0 ELSE ROUND(SUM(FATURA.GTOPLAM),2) / FATURA.DOVIZKURU END,0,0,NULL,@FATID,'F'
            FROM FATURA,ETS_CARI
            WHERE FATURA.CARIID=ETS_CARI.CARIID  AND FATURA.FATID=@FATID
            GROUP BY ETS_CARI.HESAPID,FATURA.DOVIZKURU
                   IF @@ERROR <> 0  
                        SET @HATANO = 1
 PRINT STR(@HATANO)                 

            IF (@TEKKDVHESABI = 1) -- KDV Y~ TEK HESAPTA GtSTER
              BEGIN
               IF (@STOKGRUPLU = 1)
               BEGIN
                INSERT INTO ETS_HESAPISL (FISCOUNTER,ACIKLAMA,HESAPID,BORC,ALACAK,DBORC,DALACAK,MBORC,MALACAK,MASMER,KAYITID,OZELKOD)
                SELECT @FISCOUNTER,ACIKLAMA,HESAPID,TBORC,TALACAK,0,0,0,0,SRMMRKKODU,@FATID,'F'
                FROM (
                    SELECT @FATNO + ' nl.Al?Y Fat ' + VWETS_FATISL.STOKADI + ' / ' + @CARIUNVANI ACIKLAMA, CASE WHEN (HESAPID IS NOT NULL) AND (HESAPID<>0) THEN HESAPID ELSE MUHNHESAPID END AS HESAPID,
                           ROUND(SUM(NTUTAR),2) AS TBORC,0 AS TALACAK,SRMMRKKODU
                    FROM VWETS_FATISL
                    WHERE FATID=@FATID
                    GROUP BY MUHNHESAPID,HESAPID,SRMMRKKODU,VWETS_FATISL.STOKID,VWETS_FATISL.STOKADI
                    UNION ALL
                    SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI,(SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                             LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                             WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                                AND C.KEYNAME = 'Indirilecek  KDV Hesabi %18')
                    ,ROUND(SUM(NALISKDV),2),0,NULL
                    FROM VWETS_FATISL WHERE FATID=@FATID
                    GROUP BY FATID
                    HAVING SUM(NALISKDV)>0.001) AS TBL
                   IF @@ERROR <> 0 
                       SET @HATANO = @@ERROR
               END
               ELSE -- IF (@STOKGRUPLU IS NOT NULL)
               BEGIN
                INSERT INTO ETS_HESAPISL (FISCOUNTER,ACIKLAMA,HESAPID,BORC,ALACAK,DBORC,DALACAK,MBORC,MALACAK,MASMER,KAYITID,OZELKOD)
                SELECT @FISCOUNTER,ACIKLAMA,HESAPID,TBORC,TALACAK,0,0,0,0,SRMMRKKODU,@FATID,'F'
                FROM (
                    SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI ACIKLAMA, CASE WHEN (HESAPID IS NOT NULL) AND (HESAPID<>0) THEN HESAPID ELSE MUHNHESAPID END AS HESAPID,
                           ROUND(SUM(NTUTAR),2) AS TBORC,0 AS TALACAK,SRMMRKKODU
                    FROM VWETS_FATISL
                    WHERE FATID=@FATID
                    GROUP BY MUHNHESAPID,HESAPID,SRMMRKKODU
                    UNION ALL
                    SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI,(SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                             LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                             WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                                AND C.KEYNAME = 'Indirilecek  KDV Hesabi %18')
                    ,ROUND(SUM(NALISKDV),2),0,NULL
                    FROM VWETS_FATISL WHERE FATID=@FATID
                    GROUP BY FATID
                    HAVING SUM(NALISKDV)>0.001) AS TBL
                   IF @@ERROR <> 0 
                       SET @HATANO = @@ERROR
               END
              END
            ELSE -- IF (@TEKKDVHESABI IS NOT NULL)
              BEGIN
               IF (@STOKGRUPLU = 1)
               BEGIN
                INSERT INTO ETS_HESAPISL (FISCOUNTER,ACIKLAMA,HESAPID,BORC,ALACAK,DBORC,DALACAK,MBORC,MALACAK,MASMER,KAYITID,OZELKOD)
                SELECT  @FISCOUNTER,ACIKLAMA,  HESAPID,TBORC,TALACAK,0,0,0,0,SRMMRKKODU,@FATID,'F'
                  FROM ( SELECT @FATNO + ' nl.Al?Y Fat ' + VWETS_FATISL.STOKADI + ' / ' + @CARIUNVANI ACIKLAMA, CASE WHEN (HESAPID IS NOT NULL) AND (HESAPID<>0) THEN HESAPID
                                ELSE MUHNHESAPID END AS HESAPID,ROUND(SUM(NTUTAR),2) AS TBORC,0 AS TALACAK,SRMMRKKODU
                         FROM VWETS_FATISL
                         WHERE FATID=@FATID
                         GROUP BY MUHNHESAPID,HESAPID,SRMMRKKODU,VWETS_FATISL.STOKID,VWETS_FATISL.STOKADI
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI, (SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %1')
                        ,ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV= 1 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI,(SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %8')
                         ,ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV= 8 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI, (SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %18')
                         ,ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV=18 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI,(SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %26'),
                         ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV=26 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001) AS TBL
                   IF @@ERROR <> 0 
                       SET @HATANO = @@ERROR
                END
               ELSE -- IF (@STOKGRUPLU IS NOT NULL)
               BEGIN
                INSERT INTO ETS_HESAPISL (FISCOUNTER,ACIKLAMA,HESAPID,BORC,ALACAK,DBORC,DALACAK,MBORC,MALACAK,MASMER,KAYITID,OZELKOD)
                SELECT  @FISCOUNTER,ACIKLAMA,  HESAPID,TBORC,TALACAK,0,0,0,0,SRMMRKKODU,@FATID,'F'
                  FROM ( SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI  ACIKLAMA, CASE WHEN (HESAPID IS NOT NULL) AND (HESAPID<>0) THEN HESAPID
                                ELSE MUHNHESAPID END AS HESAPID,ROUND(SUM(NTUTAR),2) AS TBORC,0 AS TALACAK,SRMMRKKODU
                         FROM VWETS_FATISL
                         WHERE FATID=@FATID
                         GROUP BY MUHNHESAPID,HESAPID,SRMMRKKODU
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI, (SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %1')
                        ,ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV= 1 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI,(SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %8')
                         ,ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV= 8 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI, (SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %18')
                         ,ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV=18 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001
                         UNION ALL
                         SELECT @FATNO + ' nl.Al?Y Fat ' + @CARIUNVANI,(SELECT TOP 1 H.HESAPID FROM [CONFIG] C
                                 LEFT JOIN HESAP H ON H.KODU = RTRIM(C.VALUESTR)
                                 WHERE C.PROGNAME = 'ETS' AND C.SECTIONSTR = 'ENTEGRASYON'
                                    AND C.KEYNAME = 'Indirilecek  KDV Hesabi %26'),
                         ROUND(SUM(NALISKDV),2),0,NULL
                         FROM VWETS_FATISL
                         WHERE ALISKDV=26 AND FATID=@FATID
                         GROUP BY FATID
                         HAVING SUM(NALISKDV)>0.001) AS TBL
                   IF @@ERROR != 0 
                       SET @HATANO = @@ERROR
               END
              END

            SET @FBORC   = 0
            SET @FALACAK = 0
            SET @FDBORC  = 0
            SET @FDALACAK= 0

            SELECT @FBORC = SUM(H.BORC),@FALACAK = SUM(H.ALACAK),
                    @FDBORC = SUM(H.DBORC),@FDALACAK = SUM(H.DALACAK)
            FROM ETS_HESAPISL H WHERE H.FISCOUNTER = @FISCOUNTER

            EXEC ETS_MUHFISNO   @SubeKodu,'MAHSUP', @SONTARIH, @FISNO OUTPUT
                   IF @@ERROR != 0 
                       SET @HATANO = @@ERROR

            UPDATE FIS SET BORC = @FBORC, ALACAK = @FALACAK, TARIH = @SONTARIH, FISNO = @FISNO
            WHERE FIS.COUNTER = @FISCOUNTER
                   IF @@ERROR != 0 
                       SET @HATANO = @@ERROR

            UPDATE FATURA SET DURUM = 1,MUHFC=@FISCOUNTER WHERE FATID = @FATID
                   IF @@ERROR != 0 
                       SET @HATANO = @@ERROR

           IF @HATANO != 0 
           BEGIN
                 PRINT 'ROLLING'
                 ROLLBACK TRAN      
           END 
           ELSE 
                 COMMIT TRANSACTION

            /*IF (@FISNOMESAJ = 1)
                    RAISERROR('Entegre Edilen FiYin Numaras? : %d',16,1,@FISNO)
                 */
            SELECT @FISCOUNTER

            FETCH NEXT FROM DNCList into @FATID,@CARIID,@TARIH,@FATNO,@SubeKodu,@TOPLAM,@FATURAACIKLAMA
                 end  -- while @@fetch_status = 0



 CLOSE DNCList
 DEALLOCATE DNCList
END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



/*------ 13.08.2007 10:50:05 --------*/

CREATE PROCEDURE [dbo].ETS_MUHFISNO
  @SubeKodu NVARCHAR(25),
  @FISTURU NVARCHAR(25),
  @TARIH DATETIME,
  @FISNO NVARCHAR(25) OUTPUT
AS
BEGIN
DECLARE @RS NVARCHAR(10)
DECLARE @RS2 INTEGER

IF EXISTS(SELECT CONFIG.CONFIGID FROM CONFIG WHERE CONFIG.PROGNAME = 'ETS' AND CONFIG.SECTIONSTR = 'Fis'
           AND CONFIG.KEYNAME = 'Fisno aagg001 format?nda olsun' AND CONFIG.VALUESTR = '0')
   BEGIN
     SELECT @FISNO = MAX(FISNO)+1 FROM [FIS] WHERE SKODU = @SubeKodu AND FISTURU = @FISTURU
   END
ELSE
   BEGIN
    DECLARE @A NVARCHAR(50)
    DECLARE @B NVARCHAR(50)
    SET @A = NULL
    SET @B = LEFT(convert(nvarchar(5), @TARIH,1),2) + RIGHT(convert(nvarchar(5), @TARIH,1),2)
    SELECT  @A = MAX(FISNO) + 1 FROM FIS WHERE FISNO LIKE @B + '%'
    IF (@A IS NULL)
       SET @FISNO = @B+'001'
    ELSE SET @FISNO = @A
   END

SELECT @RS = VALUESTR FROM CONFIG
    WHERE SECTIONSTR = 'MuhFisi'
    AND KEYNAME = 'Otomatik FisNo  Rakam Say?s?'
    AND PROGNAME = 'ETS'

IF (@RS IS NOT NULL)  AND (ISNUMERIC(@RS) = 1)
   SET @RS2 = CAST(@RS AS INTEGER)
ELSE
   SET @RS2 = 7


   WHILE (LEN(@FISNO) < @RS2)
     BEGIN
      SET @FISNO = '0' + @FISNO;
     END
END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE   PROCEDURE [dbo].[KASA_OZET]
@CARIID int,
@TARIH1 DateTime,
@TARIH2 DateTime
AS
DECLARE
  @TARIH DateTime
SET @TARIH = @TARIH1
WHILE @TARIH <= @TARIH2
BEGIN
	IF NOT EXISTS(SELECT GUN FROM GUNLER WHERE GUN = @TARIH)
		INSERT GUNLER ([GUN]) VALUES (@TARIH)
	SET @TARIH = DATEADD(day,1,@TARIH)
END
SELECT [GUN] TARIH,
	(SELECT SUM(BORC) - SUM(ALACAK) FROM CARIISLEM WHERE CARIID = @CARIID AND TARIH < CONVERT(VARCHAR(8), [GUN] ,112)) DDEVIR,
	(SELECT SUM(BORC) - SUM(ALACAK) FROM CARIISLEM WHERE CARIID = @CARIID AND TARIH <= CONVERT(VARCHAR(8), [GUN] ,112)) YDEVIR,
	(SELECT SUM(BORC) FROM CARIISLEM WHERE CARIID = @CARIID AND TARIH = CONVERT(VARCHAR(8), [GUN] ,112)) BORC,
	(SELECT SUM(ALACAK) FROM CARIISLEM WHERE CARIID = @CARIID AND TARIH = CONVERT(VARCHAR(8), [GUN] ,112)) ALACAK
FROM GUNLER 
WHERE [GUN] >= @TARIH1 AND [GUN] <= @TARIH2
ORDER BY [GUN]



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




--
-- Definition for stored procedure SAYACOKU : 
--

CREATE PROCEDURE [dbo].SAYACOKU
@Tb nvarchar(255) , @Id int OUTPUT
AS
  IF NOT EXISTS (SELECT * FROM SAYACLAR WHERE TABLENAME = @Tb)
  BEGIN
    SET @Id = 1
    INSERT INTO SAYACLAR (TABLENAME , SIRANO) VALUES (@Tb , 2)
  END
  ELSE
  BEGIN
    SELECT  @ID = SIRANO FROM SAYACLAR WHERE TABLENAME = @Tb
    update SAYACLAR set SIRANO=SIRANO+1 where TABLENAME=@Tb
  END




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO




--
-- Definition for stored procedure STOKDEGERBAKIYE : 
--
CREATE PROCEDURE [dbo].STOKDEGERBAKIYE
@STOKID int,
@TARIH1 DateTime,
@TARIH2 DateTime,
@GA FLOAT OUTPUT,
@GT FLOAT OUTPUT,
@CA FLOAT OUTPUT,
@CT FLOAT OUTPUT,
@KA FLOAT OUTPUT,
@KT FLOAT OUTPUT,
@Kar FLOAT OUTPUT,
@KarY FLOAT OUTPUT,
@BTutar FLOAT OUTPUT,
@BAdet FLOAT OUTPUT,
@SALISFIYAT FLOAT OUTPUT,
@LGFIYAT FLOAT OUTPUT,
@LCFIYAT FLOAT OUTPUT,
@LKFIYAT FLOAT OUTPUT,
@LKT FLOAT OUTPUT,
@LYAO FLOAT OUTPUT

AS
BEGIN

SET @GA = 0.00      SET @GT = 0.00
SET @CA = 0.00      SET @CT = 0.00
SET @KA = 0.00      SET @KT = 0.00
SET @Kar = 0.00     SET @KarY = 0.00
SET @BTutar = 0.00  SET @BAdet = 0.00

---- ***********
DECLARE @GCADET FLOAT
DECLARE @NFIYAT FLOAT
DECLARE @TOPLAM FLOAT


DECLARE dondur CURSOR
     FOR
     SELECT ISNULL(GCADET,0),ISNULL(NFIYAT,0),ISNULL(TOPLAM,0),ISNULL(SALISFIYAT,0) FROM [STOKISL] SH
     WHERE STOKID= @STOKID AND TARIH BETWEEN @TARIH1 AND @TARIH2
     -- &subewhere
     ORDER BY SH.TARIH

OPEN dondur

FETCH NEXT FROM dondur INTO @GCADET,@NFIYAT,@TOPLAM,@SALISFIYAT
WHILE (@@FETCH_STATUS = 0)
     BEGIN
      IF (@GCADET > 0)
        BEGIN
          SET @BTutar = @BTutar + @GCAdet * @NFIYAT
          SET @BAdet  = @BAdet  + @GCAdet
          SET @GA = @GA + @GCAdet
          SET @GT = @GT + @TOPLAM
        END
      ELSE
        BEGIN
          IF (@BAdet > 0)
            BEGIN
             SET @BTutar = @BTutar + @GCAdet * @BTutar / @BAdet
             SET @BAdet  = @BAdet  + @GCAdet
            END

          SET @CA = @CA - @GCAdet
          SET @CT = @CT - @TOPLAM
        END
      FETCH NEXT FROM dondur INTO @GCADET,@NFIYAT,@TOPLAM,@SALISFIYAT
     END

CLOSE dondur
DEALLOCATE dondur


    SET @KA = @GA-@CA
    SET @KT = @GT-@CT


    SET @LKT = (@KA * @SALISFIYAT)

    IF (@GA<>0)
      SET @LGFIYAT = @GT/@GA
    ELSE SET @LGFIYAT = 0

    IF (@CA<>0)
      SET @LCFIYAT = @CT/@CA
    ELSE SET @LCFIYAT = 0

    IF (@KA<>0)
      SET @LKFIYAT = @KT/@KA
    ELSE SET @LKFIYAT = 0

    IF (@BAdet<>0)
    BEGIN
      SET @LYAO  =  @BTutar/@BAdet
      SET @LKT   =  @KA*@BTutar/@BAdet
    END

    if ((@GA<>0) and (@CA<>0))
    begin
       SET @Kar  = @CT-(@GT/@GA)*@CA
       if ((@GT/@GA*@CA)<>0)
          SET @KarY = @Kar/((@GT/@GA)*@CA)
    end

    SET @KarY = (100*@KarY)

SELECT
  @GA LGA,
  @GT LGT,
  @CA LCA,
  @CT LCT,
  @KA LKA,
  @KT KT,
  @Kar KAR,
  @KarY KARY,
  @BTutar BTUTAR,
  @BAdet BADET,
  @LGFIYAT LGFIYAT,
  @LCFIYAT LCFIYAT,
  @LKFIYAT LKFIYAT,
  @LKT LKT,
  @LYAO LYAO

END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[TUKETIMFISIKES] 
@STOKID AS INT,
@DEPOID AS INT,
@TARIH AS DATETIME,
@ADET AS FLOAT,
@SFIYAT AS FLOAT
AS
SELECT * FROM STOK WHERE STOKID = @STOKID



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[UCHESAPTEMIZLE] AS
UPDATE HESAP SET UCHESAP = 0;



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[UCHESAPYAP] AS
UPDATE HESAP SET UCHESAP = 1
WHERE KODU IN
(SELECT HESAP.KODU
FROM HESAP
GROUP BY HESAP.KODU
HAVING ((((SELECT COUNT(*) FROM HESAP AS H WHERE LEFT(H.KODU,LEN(HESAP.KODU))=HESAP.KODU ))=1)));



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[YASLANALICI]
@TARIH AS SMALLDATETIME, 
@HESAPALICI AS NVARCHAR(50), 
@SUBEKODU AS NVARCHAR(10),
@DOVIZLI AS BIT
 AS 
IF(@SUBEKODU='')
BEGIN
  IF (@DOVIZLI=1)
  BEGIN
     UPDATE HESAPISL3 SET KAPANAN=BORC WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND KODU NOT IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
     UPDATE HESAPISL3 SET KAPANAN=DBORC WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND KODU IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
  END
  ELSE    
     UPDATE HESAPISL3 SET KAPANAN=BORC WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH
     
END 
ELSE 
BEGIN
    IF (@DOVIZLI=1)
  BEGIN
     UPDATE HESAPISL3 SET KAPANAN =BORC WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU AND KODU NOT IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
     UPDATE HESAPISL3 SET KAPANAN =DBORC WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU AND KODU IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
  END
  ELSE    
 UPDATE HESAPISL3 SET KAPANAN =BORC WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU
END
DECLARE @KODU NVARCHAR(40)
DECLARE @TOPLAMODEME FLOAT
DECLARE @TOPLAMKAPANAN FLOAT
DECLARE @COUNTER INT
DECLARE @FATURAALANI FLOAT
DECLARE @HESAPISL3_CURSOR CURSOR 
IF (@SUBEKODU='') 
BEGIN 
  IF(@DOVIZLI=1)
   BEGIN
     
    SET @HESAPISL3_CURSOR=CURSOR FOR
    SELECT KODU, SUM(ALACAK) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND ((DOVTURU IS NULL) OR (DOVTURU = '')) GROUP BY KODU HAVING SUM(ALACAK) < SUM(BORC) 
      UNION ALL 
    SELECT KODU, SUM(ALACAK) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')) GROUP BY KODU HAVING SUM(ALACAK) < SUM(BORC)
   END
  ELSE
   BEGIN
    SET @HESAPISL3_CURSOR=CURSOR FOR
    SELECT KODU, SUM(ALACAK) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH GROUP BY KODU HAVING SUM(ALACAK) < SUM(BORC)
  END
END
ELSE
BEGIN 
  SET @HESAPISL3_CURSOR=CURSOR FOR
  SELECT KODU, SUM(ALACAK) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU GROUP BY KODU HAVING SUM(ALACAK) < SUM(BORC)
END
OPEN @HESAPISL3_CURSOR
FETCH NEXT FROM @HESAPISL3_CURSOR INTO @KODU, @TOPLAMODEME
WHILE(@@FETCH_STATUS = 0)
BEGIN
SET @TOPLAMKAPANAN = 0
DECLARE @HESAPISL3_CURSOR2 CURSOR
IF(@SUBEKODU='')
BEGIN  
  SET @HESAPISL3_CURSOR2= CURSOR FOR
  SELECT HCOUNTER, BORC FROM HESAPISL3 WHERE KODU = @KODU AND TARIH <= @TARIH  ORDER BY TARIH, HCOUNTER 
END 
ELSE
BEGIN
  SET @HESAPISL3_CURSOR2= CURSOR FOR
  SELECT HCOUNTER, BORC FROM HESAPISL3 WHERE KODU = @KODU AND TARIH <= @TARIH AND SKODU=@SUBEKODU ORDER BY TARIH, HCOUNTER  
END
OPEN @HESAPISL3_CURSOR2
FETCH NEXT FROM @HESAPISL3_CURSOR2 INTO @COUNTER, @FATURAALANI
WHILE(@@FETCH_STATUS = 0)
  BEGIN
    IF(@TOPLAMKAPANAN < @TOPLAMODEME)
    BEGIN
      IF(@TOPLAMODEME - @TOPLAMKAPANAN > @FATURAALANI)
       BEGIN
         SET @TOPLAMKAPANAN = @TOPLAMKAPANAN + @FATURAALANI
       END
     ELSE
       BEGIN
          UPDATE HESAPISL3 SET KAPANAN = @TOPLAMODEME - @TOPLAMKAPANAN WHERE HCOUNTER = @COUNTER
          SET @TOPLAMKAPANAN = @TOPLAMODEME
       END
    END
  ELSE
    BEGIN
      UPDATE HESAPISL3 SET KAPANAN = 0
                     WHERE KODU = @KODU
                           AND ((TARIH = (SELECT TARIH FROM HESAPISL3 WHERE HCOUNTER = @COUNTER) AND HCOUNTER >= @COUNTER)
                             OR TARIH > (SELECT TARIH FROM HESAPISL3 WHERE HCOUNTER = @COUNTER))
      BREAK
    END
 
   FETCH NEXT FROM @HESAPISL3_CURSOR2 INTO @COUNTER, @FATURAALANI
 END
 CLOSE @HESAPISL3_CURSOR2
 
DEALLOCATE @HESAPISL3_CURSOR2
 FETCH NEXT FROM @HESAPISL3_CURSOR INTO @KODU, @TOPLAMODEME
END
CLOSE @HESAPISL3_CURSOR
DEALLOCATE @HESAPISL3_CURSOR



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[YASLANDIRMA] 
@TARIH AS SMALLDATETIME, 
@HESAPALICI AS NVARCHAR(50), 
@SUBEKODU AS NVARCHAR(10),
@DOVIZLI AS BIT
 AS 
IF(@SUBEKODU='')
BEGIN
  IF (@DOVIZLI=1)
  BEGIN
     UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND KODU NOT IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
     UPDATE HESAPISL3 SET KAPANAN =DALACAK WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND KODU IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
  END
  ELSE    
     UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH
     
END 
ELSE 
BEGIN
    IF (@DOVIZLI=1)
  BEGIN
     UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU AND KODU NOT IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
     UPDATE HESAPISL3 SET KAPANAN =DALACAK WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU AND KODU IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPALICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
  END
  ELSE    
 UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU
END
DECLARE @KODU NVARCHAR(40)
DECLARE @TOPLAMODEME FLOAT
DECLARE @TOPLAMKAPANAN FLOAT
DECLARE @COUNTER INT
DECLARE @FATURAALANI FLOAT
DECLARE @HESAPISL3_CURSOR CURSOR 
IF (@SUBEKODU='') 
BEGIN 
  IF(@DOVIZLI=1)
   BEGIN
     
    SET @HESAPISL3_CURSOR=CURSOR FOR
    SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND ((DOVTURU IS NULL) OR (DOVTURU = '')) GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC) 
      UNION ALL 
    SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')) GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC)
   END
  ELSE
   BEGIN
    SET @HESAPISL3_CURSOR=CURSOR FOR
    SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC)
  END
END
ELSE
BEGIN 
  SET @HESAPISL3_CURSOR=CURSOR FOR
  SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPALICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC)
END
OPEN @HESAPISL3_CURSOR
FETCH NEXT FROM @HESAPISL3_CURSOR INTO @KODU, @TOPLAMODEME
WHILE(@@FETCH_STATUS = 0)
BEGIN
SET @TOPLAMKAPANAN = 0
DECLARE @HESAPISL3_CURSOR2 CURSOR
IF(@SUBEKODU='')
BEGIN  
  SET @HESAPISL3_CURSOR2= CURSOR FOR
  SELECT HCOUNTER, ALACAK FROM HESAPISL3 WHERE KODU = @KODU AND TARIH <= @TARIH  ORDER BY TARIH, HCOUNTER 
END 
ELSE
BEGIN
  SET @HESAPISL3_CURSOR2= CURSOR FOR
  SELECT HCOUNTER, ALACAK FROM HESAPISL3 WHERE KODU = @KODU AND TARIH <= @TARIH AND SKODU=@SUBEKODU ORDER BY TARIH, HCOUNTER  
END
OPEN @HESAPISL3_CURSOR2
FETCH NEXT FROM @HESAPISL3_CURSOR2 INTO @COUNTER, @FATURAALANI
WHILE(@@FETCH_STATUS = 0)
  BEGIN
    IF(@TOPLAMKAPANAN < @TOPLAMODEME)
    BEGIN
      IF(@TOPLAMODEME - @TOPLAMKAPANAN > @FATURAALANI)
       BEGIN
         SET @TOPLAMKAPANAN = @TOPLAMKAPANAN + @FATURAALANI
       END
     ELSE
       BEGIN
          UPDATE HESAPISL3 SET KAPANAN = @TOPLAMODEME - @TOPLAMKAPANAN WHERE HCOUNTER = @COUNTER
          SET @TOPLAMKAPANAN = @TOPLAMODEME
       END
    END
  ELSE
    BEGIN
      UPDATE HESAPISL3 SET KAPANAN = 0
                     WHERE KODU = @KODU
                           AND ((TARIH = (SELECT TARIH FROM HESAPISL3 WHERE HCOUNTER = @COUNTER) AND HCOUNTER >= @COUNTER)
                             OR TARIH > (SELECT TARIH FROM HESAPISL3 WHERE HCOUNTER = @COUNTER))
      BREAK
    END
 
   FETCH NEXT FROM @HESAPISL3_CURSOR2 INTO @COUNTER, @FATURAALANI
 END
 CLOSE @HESAPISL3_CURSOR2
 
DEALLOCATE @HESAPISL3_CURSOR2
 FETCH NEXT FROM @HESAPISL3_CURSOR INTO @KODU, @TOPLAMODEME
END
CLOSE @HESAPISL3_CURSOR
DEALLOCATE @HESAPISL3_CURSOR



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE PROCEDURE [dbo].[YASLANSATICI]
@TARIH AS SMALLDATETIME, 
@HESAPSATICI AS NVARCHAR(50), 
@SUBEKODU AS NVARCHAR(10),
@DOVIZLI AS BIT
 AS 
IF(@SUBEKODU='')
BEGIN
  IF (@DOVIZLI=1)
  BEGIN
     UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND KODU NOT IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPSATICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
     UPDATE HESAPISL3 SET KAPANAN =DALACAK WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND KODU IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPSATICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
  END
  ELSE    
     UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH
     
END 
ELSE 
BEGIN
    IF (@DOVIZLI=1)
  BEGIN
     UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU AND KODU NOT IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPSATICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
     UPDATE HESAPISL3 SET KAPANAN =DALACAK WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU AND KODU IN (SELECT KODU FROM HESAP WHERE KODU LIKE  @HESAPSATICI+'%' AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')))
  END
  ELSE    
 UPDATE HESAPISL3 SET KAPANAN =ALACAK WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU
END
DECLARE @KODU NVARCHAR(40)
DECLARE @TOPLAMODEME FLOAT
DECLARE @TOPLAMKAPANAN FLOAT
DECLARE @COUNTER INT
DECLARE @FATURAALANI FLOAT
DECLARE @HESAPISL3_CURSOR CURSOR 
IF (@SUBEKODU='') 
BEGIN 
  IF(@DOVIZLI=1)
   BEGIN
     
    SET @HESAPISL3_CURSOR=CURSOR FOR
    SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND ((DOVTURU IS NULL) OR (DOVTURU = '')) GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC) 
      UNION ALL 
    SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND NOT ((DOVTURU IS NULL) OR (DOVTURU = '')) GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC)
   END
  ELSE
   BEGIN
    SET @HESAPISL3_CURSOR=CURSOR FOR
    SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC)
  END
END
ELSE
BEGIN 
  SET @HESAPISL3_CURSOR=CURSOR FOR
  SELECT KODU, SUM(BORC) AS ODEME FROM HESAPISL3 WHERE KODU LIKE @HESAPSATICI+'%' AND TARIH <= @TARIH AND SKODU=@SUBEKODU GROUP BY KODU HAVING SUM(ALACAK) > SUM(BORC)
END
OPEN @HESAPISL3_CURSOR
FETCH NEXT FROM @HESAPISL3_CURSOR INTO @KODU, @TOPLAMODEME
WHILE(@@FETCH_STATUS = 0)
BEGIN
SET @TOPLAMKAPANAN = 0
DECLARE @HESAPISL3_CURSOR2 CURSOR
IF(@SUBEKODU='')
BEGIN  
  SET @HESAPISL3_CURSOR2= CURSOR FOR
  SELECT HCOUNTER, ALACAK FROM HESAPISL3 WHERE KODU = @KODU AND TARIH <= @TARIH  ORDER BY TARIH, HCOUNTER 
END 
ELSE
BEGIN
  SET @HESAPISL3_CURSOR2= CURSOR FOR
  SELECT HCOUNTER, ALACAK FROM HESAPISL3 WHERE KODU = @KODU AND TARIH <= @TARIH AND SKODU=@SUBEKODU ORDER BY TARIH, HCOUNTER  
END
OPEN @HESAPISL3_CURSOR2
FETCH NEXT FROM @HESAPISL3_CURSOR2 INTO @COUNTER, @FATURAALANI
WHILE(@@FETCH_STATUS = 0)
  BEGIN
    IF(@TOPLAMKAPANAN < @TOPLAMODEME)
    BEGIN
      IF(@TOPLAMODEME - @TOPLAMKAPANAN > @FATURAALANI)
       BEGIN
         SET @TOPLAMKAPANAN = @TOPLAMKAPANAN + @FATURAALANI
       END
     ELSE
       BEGIN
          UPDATE HESAPISL3 SET KAPANAN = @TOPLAMODEME - @TOPLAMKAPANAN WHERE HCOUNTER = @COUNTER
          SET @TOPLAMKAPANAN = @TOPLAMODEME
       END
    END
  ELSE
    BEGIN
      UPDATE HESAPISL3 SET KAPANAN = 0
                     WHERE KODU = @KODU
                           AND ((TARIH = (SELECT TARIH FROM HESAPISL3 WHERE HCOUNTER = @COUNTER) AND HCOUNTER >= @COUNTER)
                             OR TARIH > (SELECT TARIH FROM HESAPISL3 WHERE HCOUNTER = @COUNTER))
      BREAK
    END
 
   FETCH NEXT FROM @HESAPISL3_CURSOR2 INTO @COUNTER, @FATURAALANI

 END
 CLOSE @HESAPISL3_CURSOR2
 
DEALLOCATE @HESAPISL3_CURSOR2
 FETCH NEXT FROM @HESAPISL3_CURSOR INTO @KODU, @TOPLAMODEME
END
CLOSE @HESAPISL3_CURSOR
DEALLOCATE @HESAPISL3_CURSOR



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO




--
-- Definition for triggers : 
--

CREATE TRIGGER [dbo].[NO_DELETE] ON [dbo].[CARIISL]
FOR DELETE
AS
DECLARE @RC INT
SELECT @RC=COUNT(CARIISLID) FROM DELETED
IF @RC > 10
BEGIN
   RAISERROR ('10 dan fazla satir silinemez', 16, 1)
   ROLLBACK TRANSACTION
END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO





--
-- Definition for triggers :
--


CREATE TRIGGER [dbo].[ETS_FATURA_tr] ON [dbo].[FATURA]
FOR DELETE
AS
BEGIN
 DECLARE @SAYI INTEGER
 DECLARE @KNO  INTEGER
 SET @SAYI = NULL

 SELECT @SAYI = DURUM, @KNO = FATID FROM DELETED WHERE DURUM = 1
 IF (@SAYI IS NOT NULL)
    BEGIN
     RAISERROR('MuhasebeleYtirilmiY bir kayd? silemezsiniz.!!',16,1)
     ROLLBACK TRANSACTION
     RETURN
    END

 DELETE FROM FATISL
 WHERE FATISL.FATID = @KNO

END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO




CREATE TRIGGER [dbo].[ETS_FIS_TRD] ON [dbo].[FIS]
FOR DELETE
AS
BEGIN

  declare @KNO INTEGER
  DECLARE @SAYI INTEGER

  SELECT @KNO = DELETED.COUNTER FROM DELETED

DELETE FROM HESAPISLSIL
WHERE
  FISCOUNTER = @KNO

DELETE FROM FISSIL
WHERE
  COUNTER = @KNO

INSERT INTO FISSIL
SELECT * FROM DELETED F WHERE F.COUNTER = @KNO

INSERT INTO
    HESAPISLSIL(FISCOUNTER,HESAPID,ACIKLAMA,BORC,ALACAK,DBORC,DALACAK,MBORC,
                MALACAK,MASMER,OZELKOD,KAPANAN,VADE,KUR,YEVNO,TLBORC,
                TLALACAK,KAYITID,YETKILI,DEGISTIREN)
SELECT FISCOUNTER,HESAPID,ACIKLAMA,BORC,ALACAK,DBORC,DALACAK,MBORC,
                MALACAK,MASMER,OZELKOD,KAPANAN,VADE,KUR,YEVNO,TLBORC,
                TLALACAK,KAYITID,YETKILI,DEGISTIREN FROM ETS_HESAPISL
WHERE FISCOUNTER = @KNO


DELETE FROM ETS_HESAPISL
WHERE
  FISCOUNTER = @KNO



  SET @SAYI = 0


  SELECT TOP 1 @SAYI = F.FATID FROM FATURA F WHERE F.MUHFC = @KNO

  IF (@SAYI > 0)
    BEGIN
     update fatura set MUHASEBE = NULL ,DURUM = 0, MUHFC = NULL
     where MUHFC = @KNO
    END

END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO




--DISABLE TRIGGER [ETS_FIS_TRD] ON [dbo].[FIS]
--GO

/*------ 20.07.2007 19:14:06 --------*/

CREATE TRIGGER [dbo].[ETS_STOK_SILMEKONTROL] ON [dbo].[STOK]
FOR DELETE
AS
BEGIN
DECLARE @STOKID INTEGER

SELECT @STOKID = DELETED.STOKID FROM DELETED

 IF EXISTS(
    SELECT TOP 1 FI.STOKID FROM FATISL FI WHERE FI.STOKID = @STOKID
    UNION ALL
    SELECT TOP 1 DF.STOKID FROM DEPOFISISL DF WHERE DF.STOKID = @STOKID
    UNION ALL
    SELECT TOP 1 SS.STOKID FROM SSAYIM SS WHERE SS.STOKID = @STOKID
    UNION ALL
    SELECT TOP 1 SS.STOKID FROM SATINALMAISL SS WHERE SS.STOKID = @STOKID
     )
    BEGIN
      RAISERROR('~Ylem g"rm?Y bir stoõu silemezsiniz.!!',18,1)
      ROLLBACK TRANSACTION
    END


END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

