 
/****** Object:  Table [dbo].[CosMailRules]    Script Date: 13.7.2015 10:34:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CosMailRules]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CosMailRules](
	[IND] [int] IDENTITY(1,1) NOT NULL,
	[RuleType] [int] NULL,
	[RuleQuery] [nvarchar](150) NULL,
	[SendDay] [int] NULL,
	[CreatedDate] [datetime] NULL,
	[UserId] [int] NULL,
	[RuleName] [nvarchar](50) NULL,
	[IsActive] [bit] NULL,
	[IsCouponActive] [bit] NULL,
	[Discount] [decimal](18, 4) NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[MinQty] [int] NULL,
	[MinPrice] [decimal](18, 4) NULL,
	[ProductId] [int] NULL,
	[SendCount] [int] NULL,
	[ReplyCount] [int] NULL,
	[ProductName] [nvarchar](500) NULL,
 CONSTRAINT [PK_CosMailRules] PRIMARY KEY CLUSTERED 
(
	[IND] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[CosMails]    Script Date: 13.7.2015 10:34:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CosMails]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CosMails](
	[MailId] [int] IDENTITY(1,1) NOT NULL,
	[MailPopServer] [nvarchar](50) NOT NULL,
	[MailSmtpServer] [nvarchar](50) NOT NULL,
	[MailSmtpPort] [int] NOT NULL,
	[MailPop3Port] [int] NOT NULL,
	[MailSsl] [bit] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[MailUserName] [nvarchar](50) NOT NULL,
	[MailPassword] [nvarchar](50) NOT NULL,
	[MailSender] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_CosMails] PRIMARY KEY CLUSTERED 
(
	[MailId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[PriceProducts]    Script Date: 13.7.2015 10:34:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PriceProducts]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PriceProducts](
	[IND] [int] IDENTITY(1,1) NOT NULL,
	[PriceProductName] [nvarchar](50) NULL,
	[PriceProductCode] [nvarchar](50) NULL,
	[Status] [bit] NULL,
	[ApplyOrder] [int] NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[UserFilter] [nvarchar](150) NULL,
	[UserFilterDesc] [nvarchar](150) NULL,
	[StokFilter] [nvarchar](150) NULL,
	[StokFilterDesc] [nvarchar](150) NULL,
	[Details] [nvarchar](250) NULL,
 CONSTRAINT [PK_PriceProducts] PRIMARY KEY CLUSTERED 
(
	[IND] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_PriceProducts]    Script Date: 13.7.2015 10:34:33 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PriceProducts]') AND name = N'IX_PriceProducts')
CREATE NONCLUSTERED INDEX [IX_PriceProducts] ON [dbo].[PriceProducts]
(
	[PriceProductCode] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO





IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'C2CShopSettings' and column_name = 'IsActive') ALTER TABLE [dbo].C2CShopSettings ADD [IsActive] bit 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'C2C_Previliges' and column_name = 'AddProduct') ALTER TABLE [dbo].C2C_Previliges ADD [AddProduct] bit 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Cargo' and column_name = 'PriceForCountry') ALTER TABLE [dbo].Cargo ADD [PriceForCountry] bit 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Cargo' and column_name = 'DefaultPrice') ALTER TABLE [dbo].Cargo ADD [DefaultPrice] decimal(18,2) 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Cargo' and column_name = 'ValueAddKK') ALTER TABLE [dbo].Cargo ADD [ValueAddKK] decimal(18,2) 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CargoInfo' and column_name = 'CountryId') ALTER TABLE [dbo].CargoInfo ADD [CountryId] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CargoInfo' and column_name = 'CityId') ALTER TABLE [dbo].CargoInfo ADD [CityId] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CargoInfo' and column_name = 'DistrictId') ALTER TABLE [dbo].CargoInfo ADD [DistrictId] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CosCampaign' and column_name = 'SendThreadTime') ALTER TABLE [dbo].CosCampaign ADD [SendThreadTime] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CosCampaign' and column_name = 'MailRule') ALTER TABLE [dbo].CosCampaign ADD [MailRule] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CosCampaign' and column_name = 'IsActive') ALTER TABLE [dbo].CosCampaign ADD [IsActive] bit 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'CosCampaign' and column_name = 'SendTimer') ALTER TABLE [dbo].CosCampaign ADD [SendTimer] bit 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Currencys' and column_name = 'Efektif') ALTER TABLE [dbo].Currencys ADD [Efektif] bit 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Faqs' and column_name = 'SupportId') ALTER TABLE [dbo].Faqs ADD [SupportId] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Faqs' and column_name = 'TypeId') ALTER TABLE [dbo].Faqs ADD [TypeId] int 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Payments' and column_name = 'CustomerCard') ALTER TABLE [dbo].Payments ADD [CustomerCard] nvarchar(50) 
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Portals' and column_name = 'CreditCardDisCountType') ALTER TABLE [dbo].Portals ADD [CreditCardDisCountType] int not null default 0
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'PriceList' and column_name = 'SeePrice') ALTER TABLE [dbo].PriceList ADD [SeePrice] bit
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductCode1' and column_name = 'Code') ALTER TABLE [dbo].ProductCode1 ADD [Code] nvarchar(50)
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductCode2' and column_name = 'Code') ALTER TABLE [dbo].ProductCode2 ADD [Code] nvarchar(50)
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductCode3' and column_name = 'Code') ALTER TABLE [dbo].ProductCode3 ADD [Code] nvarchar(50)
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductCode4' and column_name = 'Code') ALTER TABLE [dbo].ProductCode4 ADD [Code] nvarchar(50)
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductGroups' and column_name = 'Type') ALTER TABLE [dbo].ProductGroups ADD [Type] bit
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductOptions' and column_name = 'AttentionAmount') ALTER TABLE [dbo].ProductOptions ADD [AttentionAmount] bit
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductWizards' and column_name = 'CategoryId') ALTER TABLE [dbo].ProductWizards ADD [CategoryId] int
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ProductWizards' and column_name = 'Type') ALTER TABLE [dbo].ProductWizards ADD [Type] int
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'SupportRequestsOtherMail' and column_name = 'MailDesc') ALTER TABLE [dbo].SupportRequestsOtherMail ADD [MailDesc] nvarchar(500)
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'QuestionMaster' and column_name = 'ModuleName') ALTER TABLE [dbo].QuestionMaster ADD [ModuleName] nvarchar(50)
GO

IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ShoppingCart' and column_name = 'Mobile') ALTER TABLE [dbo].ShoppingCart ADD [Mobile] bit default 0
GO




/****** Object:  View [dbo].[AdminProductListAll2]    Script Date: 13.7.2015 10:42:54 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




ALTER VIEW [dbo].[AdminProductListAll2]
AS
SELECT     dbo.Categories.CatId, dbo.Categories.CatName, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.StockQty, 
                      dbo.ProductMarks.MarKName, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.SatisFiyati0, dbo.ProductUnits.SatisFiyati1, dbo.ProductUnits.SatisFiyati2, 
                      dbo.ProductUnits.SatisFiyati3, dbo.Products.SellNoneStock, dbo.Categories.PortalId, dbo.ProductMarks.MarkId, dbo.Products.Code1, dbo.ProductUnits.Desi, 
                      dbo.Products.IsActive, Currencys_0.CurrencyName AS Pb0, Currencys_1.CurrencyName AS Pb1, Currencys_2.CurrencyName AS Pb2, 
                      Currencys_3.CurrencyName AS Pb3, dbo.ProductUnits.UnitId, dbo.Products.ShowInMainPage, dbo.ProductUnits.LastModified, dbo.ProductUnits.EskiAlisFiyati, 
                      dbo.ProductUnits.AlisFiyati, Currencys_A.CurrencyName AS APb, dbo.Categories.Lineage, dbo.Products.CampainId, dbo.Products.IsPenta, dbo.ProductImages.Path, 
                      dbo.ProductImages.IsDefault, dbo.Products.CreatedDate, dbo.ProductUsages.UsageId, dbo.ProductAlternatives.AlternativeId, dbo.Products.WizardId, 
                      dbo.ProductAttributes.ProductAttributesId, dbo.Products.ShowOrder, dbo.Products.Code2, dbo.Products.Code3, dbo.Products.Code4, dbo.Products.Code5, 
                      dbo.Products.Code6, dbo.Products.Code7, dbo.Products.Code8, dbo.Products.Code9, dbo.Products.Code10, dbo.Products.Code11, dbo.Products.Code12, 
                      dbo.Products.Code13, dbo.Products.Code14, dbo.Products.Code15, Currencys_4.CurrencyName AS Pb4, Currencys_5.CurrencyName AS Pb5, 
                      Currencys_P.CurrencyName AS PPb, dbo.ProductUnits.SatisFiyati4, dbo.ProductUnits.SatisFiyati5, dbo.Products.HizliKargo, dbo.Products.AyniGunTeslim, 
                      dbo.Products.IndirimliUrun, dbo.Products.FirsatUrunu, dbo.Products.SokFiyatliUrun, dbo.Products.EnUcuzUrun, dbo.Products.OzelUrun, 
                      dbo.Products.SinirliSayidaUrun, dbo.Products.YeniUrun, dbo.Products.HediyeliUrun, dbo.ProductUnits.PiyasaFiyati,dbo.Products.AuthorId,dbo.Products.PublisherId
FROM         dbo.Products INNER JOIN
                      dbo.Currencys AS Currencys_A INNER JOIN
                      dbo.Currencys AS Currencys_2 INNER JOIN
                      dbo.ProductUnits INNER JOIN
                      dbo.Currencys AS Currencys_1 ON dbo.ProductUnits.Pb1 = Currencys_1.CurrencyId ON Currencys_2.CurrencyId = dbo.ProductUnits.Pb2 INNER JOIN
                      dbo.Currencys AS Currencys_3 ON dbo.ProductUnits.Pb3 = Currencys_3.CurrencyId ON Currencys_A.CurrencyId = dbo.ProductUnits.APb INNER JOIN
                      dbo.Currencys AS Currencys_0 ON dbo.ProductUnits.Pb0 = Currencys_0.CurrencyId ON dbo.Products.ProductId = dbo.ProductUnits.ProductId INNER JOIN
                      dbo.Currencys AS Currencys_4 ON dbo.ProductUnits.Pb4 = Currencys_4.CurrencyId INNER JOIN
                      dbo.Currencys AS Currencys_5 ON dbo.ProductUnits.Pb5 = Currencys_5.CurrencyId INNER JOIN
                      dbo.Currencys AS Currencys_P ON Currencys_A.CurrencyId = Currencys_P.CurrencyId LEFT OUTER JOIN
                      dbo.ProductAttributes ON dbo.Products.ProductId = dbo.ProductAttributes.ProductId LEFT OUTER JOIN
                      dbo.ProductAlternatives ON dbo.Products.ProductId = dbo.ProductAlternatives.ProductId LEFT OUTER JOIN
                      dbo.ProductUsages ON dbo.Products.ProductId = dbo.ProductUsages.ProductId LEFT OUTER JOIN
                      dbo.ProductImages ON dbo.Products.ProductId = dbo.ProductImages.ProductId LEFT OUTER JOIN
                      dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId LEFT OUTER JOIN
                      dbo.ProductCategories INNER JOIN
                      dbo.Categories ON dbo.ProductCategories.CategoryId = dbo.Categories.CatId ON dbo.Products.ProductId = dbo.ProductCategories.ProductId






GO
 

/****** Object:  View [dbo].[ProductList]    Script Date: 13.7.2015 10:43:22 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




ALTER VIEW [dbo].[ProductList]
AS
SELECT        dbo.Categories.CatId, dbo.Categories.CatName, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.Description, 
                         dbo.Products.StockQty, dbo.ProductKdvs.KdvRate, dbo.ProductImages.Path, dbo.ProductMarks.MarKName, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.Carpan, 
                         dbo.ProductUnits.SatisFiyati0, dbo.ProductUnits.SatisFiyati1, dbo.ProductUnits.SatisFiyati2, dbo.ProductUnits.SatisFiyati3, dbo.ProductUnits.Isk1, 
                         dbo.ProductUnits.Isk2, dbo.ProductUnits.Isk3, Currencys_0.CurrencyName AS Currency0, Currencys_1.CurrencyName AS Currency1, 
                         Currencys_2.CurrencyName AS Currency2, Currencys_3.CurrencyName AS Currency3, Currencys_0.Rate AS Rate0, Currencys_1.Rate AS Rate1, 
                         Currencys_2.Rate AS Rate2, Currencys_3.Rate AS Rate3, dbo.Products.SellNoneStock, dbo.Products.ShowInMainPage, dbo.Categories.PortalId, 
                         dbo.ProductMarks.MarkId, dbo.Products.ShowOrder, dbo.Products.Details, dbo.Categories.Url AS CatUrl, dbo.Products.Url AS ProductUrl, dbo.Categories.Lineage, 
                         dbo.Products.SearchKeywords, dbo.Products.Hit, dbo.Products.PublisherId, Currencys_P.CurrencyName AS CurrencyP, dbo.ProductUnits.PiyasaFiyati, 
                         Currencys_4.CurrencyName AS Currency4, Currencys_5.CurrencyName AS Currency5, Currencys_4.Rate AS Rate4, Currencys_5.Rate AS Rate5, 
                         Currencys_P.Rate AS RateP, Currencys_A.Rate AS RateA, dbo.ProductUnits.SatisFiyati4, dbo.ProductUnits.SatisFiyati5, dbo.ProductUnits.Isk4, dbo.ProductUnits.Isk5,
                          dbo.Products.HizliKargo, dbo.Products.AyniGunTeslim, dbo.Products.IndirimliUrun, dbo.Products.FirsatUrunu, dbo.Products.SokFiyatliUrun, 
                         dbo.Products.EnUcuzUrun, dbo.Products.OzelUrun, dbo.Products.SinirliSayidaUrun, dbo.Products.YeniUrun, dbo.Products.HediyeliUrun, dbo.Products.StartDate, 
                         dbo.Products.EndDate, dbo.Categories.StartDate AS CStartDate, dbo.Categories.EndDate AS CEndDate, dbo.Products.ProductSizeOptionId, dbo.ProductUnits.Barcode,
                          dbo.Products.Code15, dbo.Products.Code14, dbo.Products.Code13, dbo.Products.Code12, dbo.Products.Code11, dbo.Products.Code10, dbo.Products.Code9, 
                         dbo.Products.Code8, dbo.Products.Code7, dbo.Products.Code6, dbo.Products.Code5, dbo.Products.Code4, dbo.Products.Code3, dbo.Products.Code2, 
                         dbo.Products.Code1, dbo.Products.StokType, dbo.ProductUnits.AlisFiyati, dbo.Products.AuthorId, dbo.Products.CompanyId, dbo.Products.IsActive
FROM            dbo.ProductCategories INNER JOIN
                         dbo.Categories ON dbo.ProductCategories.CategoryId = dbo.Categories.CatId INNER JOIN
                         dbo.ProductUnits INNER JOIN
                         dbo.Products ON dbo.ProductUnits.ProductId = dbo.Products.ProductId ON dbo.ProductCategories.ProductId = dbo.Products.ProductId INNER JOIN
                         dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId INNER JOIN
                         dbo.ProductImages ON dbo.Products.ProductId = dbo.ProductImages.ProductId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_5 ON dbo.ProductUnits.Pb5 = Currencys_5.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_4 ON dbo.ProductUnits.Pb4 = Currencys_4.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_P ON dbo.ProductUnits.PPb = Currencys_P.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_0 ON dbo.ProductUnits.Pb0 = Currencys_0.CurrencyId LEFT OUTER JOIN
                         dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_2 ON dbo.ProductUnits.Pb2 = Currencys_2.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_1 ON dbo.ProductUnits.Pb1 = Currencys_1.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_3 ON dbo.ProductUnits.Pb3 = Currencys_3.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_A ON dbo.ProductUnits.APb = Currencys_A.CurrencyId
WHERE        (dbo.Categories.IsActive = 1) AND (dbo.ProductMarks.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.ProductUnits.IsDefault = 1) AND 
                         (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, 
                         GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND (ISNULL(dbo.Products.StartDate, DATEADD(day, 
                         - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) OR (dbo.ProductMarks.MarkId IS NULL)




GO


 

/****** Object:  View [dbo].[ProductListDetails5]    Script Date: 13.7.2015 10:43:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER VIEW [dbo].[ProductListDetails5]
AS
SELECT        dbo.Categories.CatId, dbo.Categories.CatName, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.Description, dbo.Products.StockQty, dbo.ProductKdvs.KdvRate, 
                         dbo.ProductImages.Path, dbo.ProductMarks.MarKName, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.Carpan, dbo.ProductUnits.SatisFiyati0, dbo.ProductUnits.SatisFiyati1, dbo.ProductUnits.SatisFiyati2, 
                         dbo.ProductUnits.SatisFiyati3, dbo.ProductUnits.Isk1, dbo.ProductUnits.Isk2, dbo.ProductUnits.Isk3, Currencys_0.CurrencyName AS Currency0, Currencys_1.CurrencyName AS Currency1, 
                         Currencys_2.CurrencyName AS Currency2, Currencys_3.CurrencyName AS Currency3, Currencys_0.Rate AS Rate0, Currencys_1.Rate AS Rate1, Currencys_2.Rate AS Rate2, Currencys_3.Rate AS Rate3, 
                         dbo.Products.SellNoneStock, dbo.Products.ShowInMainPage, dbo.Categories.PortalId, dbo.ProductMarks.MarkId, dbo.Products.ShowOrder, dbo.Products.Details, dbo.Products.Code14, dbo.Products.Code15, 
                         dbo.Categories.Url AS CatUrl, dbo.Products.Url AS ProductUrl, dbo.Categories.Lineage, dbo.ProductUnits.UnitId, dbo.ProductUnits.IsDefault AS UnitsIsDefault, dbo.Products.WizardId, dbo.Products.CampainId, 
                         dbo.Products.ForceCargo, dbo.ProductUnits.Desi, dbo.Products.StartDate, dbo.Products.EndDate, dbo.Products.Code10, dbo.Products.Code11, dbo.Products.Code12, dbo.Products.Code13, 
                         dbo.Publishers.PublisherId, dbo.Publishers.PublisherName, dbo.Authors.AuthorId, dbo.Authors.AuthorName, Currencys_4.CurrencyName AS Currency4, Currencys_4.Rate AS Rate4, 
                         Currencys_5.CurrencyName AS Currency5, Currencys_5.Rate AS Rate5, dbo.ProductUnits.SatisFiyati4, dbo.ProductUnits.SatisFiyati5, dbo.ProductUnits.Isk4, dbo.ProductUnits.Isk5, 
                         Currencys_P.CurrencyName AS CurrencyP, Currencys_P.Rate AS RateP, dbo.ProductUnits.PiyasaFiyati, dbo.Products.HizliKargo, dbo.Products.AyniGunTeslim, dbo.Products.IndirimliUrun, 
                         dbo.Products.FirsatUrunu, dbo.Products.SokFiyatliUrun, dbo.Products.EnUcuzUrun, dbo.Products.OzelUrun, dbo.Products.SinirliSayidaUrun, dbo.Products.YeniUrun, dbo.Products.HediyeliUrun, 
                         dbo.Categories.StartDate AS CStartDate, dbo.Categories.EndDate AS CEndDate, dbo.Products.ProductSizeOptionId, dbo.ProductUnits.AlisFiyati, Currencys_A.AlisRate, dbo.Products.Code1, dbo.Products.Code2, 
                         dbo.Products.Code3, dbo.Products.Code4
FROM            dbo.ProductCategories INNER JOIN
                         dbo.Categories ON dbo.ProductCategories.CategoryId = dbo.Categories.CatId INNER JOIN
                         dbo.ProductUnits INNER JOIN
                         dbo.Products ON dbo.ProductUnits.ProductId = dbo.Products.ProductId ON dbo.ProductCategories.ProductId = dbo.Products.ProductId INNER JOIN
                         dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId INNER JOIN
                         dbo.ProductImages ON dbo.Products.ProductId = dbo.ProductImages.ProductId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_P ON dbo.ProductUnits.PPb = Currencys_P.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_5 ON dbo.ProductUnits.Pb5 = Currencys_5.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_4 ON dbo.ProductUnits.Pb4 = Currencys_4.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_A ON dbo.ProductUnits.APb = Currencys_A.CurrencyId LEFT OUTER JOIN
                         dbo.Publishers ON dbo.Products.PublisherId = dbo.Publishers.PublisherId LEFT OUTER JOIN
                         dbo.Authors ON dbo.Products.AuthorId = dbo.Authors.AuthorId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_0 ON dbo.ProductUnits.Pb0 = Currencys_0.CurrencyId LEFT OUTER JOIN
                         dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_2 ON dbo.ProductUnits.Pb2 = Currencys_2.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_1 ON dbo.ProductUnits.Pb1 = Currencys_1.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_3 ON dbo.ProductUnits.Pb3 = Currencys_3.CurrencyId
WHERE        (dbo.Categories.IsActive = 1) AND (dbo.ProductMarks.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND 
                         (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, 
                         GETDATE())) >= GETDATE()) AND (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND 
                         (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND 
                         (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND (dbo.ProductMarks.MarkId IS NULL) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductMarks.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND 
                         (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, 
                         GETDATE())) >= GETDATE()) AND (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND 
                         (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND 
                         (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND (dbo.ProductMarks.MarkId IS NULL) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductMarks.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND 
                         (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, 
                         GETDATE())) >= GETDATE()) AND (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND 
                         (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND 
                         (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND (dbo.ProductMarks.MarkId IS NULL) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductMarks.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND 
                         (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, 
                         GETDATE())) >= GETDATE()) AND (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND 
                         (dbo.ProductUnits.IsActive = 1) AND (ISNULL(dbo.Categories.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Categories.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND 
                         (ISNULL(dbo.Products.StartDate, DATEADD(day, - 1, GETDATE())) <= GETDATE()) AND (ISNULL(dbo.Products.EndDate, DATEADD(day, 1, GETDATE())) >= GETDATE()) AND (dbo.ProductMarks.MarkId IS NULL)

GO


 
/****** Object:  View [dbo].[ProductListDetails5a]    Script Date: 13.7.2015 10:43:59 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER VIEW [dbo].[ProductListDetails5a]
AS
SELECT        dbo.Categories.CatId, dbo.Categories.CatName, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.Description, dbo.Products.StockQty, dbo.ProductKdvs.KdvRate, 
                         dbo.ProductImages.Path, dbo.ProductMarks.MarKName, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.Carpan, dbo.ProductUnits.SatisFiyati0, dbo.ProductUnits.SatisFiyati1, dbo.ProductUnits.SatisFiyati2, 
                         dbo.ProductUnits.SatisFiyati3, dbo.ProductUnits.Isk1, dbo.ProductUnits.Isk2, dbo.ProductUnits.Isk3, Currencys_0.CurrencyName AS Currency0, Currencys_1.CurrencyName AS Currency1, 
                         Currencys_2.CurrencyName AS Currency2, Currencys_3.CurrencyName AS Currency3, Currencys_0.Rate AS Rate0, Currencys_1.Rate AS Rate1, Currencys_2.Rate AS Rate2, Currencys_3.Rate AS Rate3, 
                         dbo.Products.SellNoneStock, dbo.Products.ShowInMainPage, dbo.Categories.PortalId, dbo.ProductMarks.MarkId, dbo.Products.ShowOrder, dbo.Products.Details, dbo.Products.Code14, dbo.Products.Code15, 
                         dbo.Categories.Url AS CatUrl, dbo.Products.Url AS ProductUrl, dbo.Categories.Lineage, dbo.ProductUnits.UnitId, dbo.ProductUnits.IsDefault AS UnitsIsDefault, dbo.Products.WizardId, dbo.Products.CampainId, 
                         dbo.Products.ForceCargo, dbo.ProductUnits.Desi, dbo.Products.Code10, dbo.Products.Code11, dbo.Products.Code12, dbo.Products.Code13, dbo.Publishers.PublisherId, dbo.Publishers.PublisherName, 
                         dbo.Authors.AuthorId, dbo.Authors.AuthorName, Currencys_4.CurrencyName AS Currency4, Currencys_4.Rate AS Rate4, Currencys_5.CurrencyName AS Currency5, Currencys_5.Rate AS Rate5, 
                         dbo.ProductUnits.SatisFiyati4, dbo.ProductUnits.SatisFiyati5, dbo.ProductUnits.Isk4, dbo.ProductUnits.Isk5, Currencys_P.CurrencyName AS CurrencyP, Currencys_P.Rate AS RateP, dbo.ProductUnits.PiyasaFiyati,
                          dbo.Products.EndDate, dbo.Products.StartDate, dbo.Categories.IsActive AS CatIsActive, dbo.ProductMarks.IsActive AS MarkIsActive, dbo.Products.IsActive AS ProductIsActive, dbo.Products.HediyeliUrun, 
                         dbo.Products.YeniUrun, dbo.Products.SinirliSayidaUrun, dbo.Products.OzelUrun, dbo.Products.EnUcuzUrun, dbo.Products.SokFiyatliUrun, dbo.Products.FirsatUrunu, dbo.Products.IndirimliUrun, 
                         dbo.Products.AyniGunTeslim, dbo.Products.HizliKargo, dbo.Products.PublisherId AS Expr1, dbo.Products.AuthorId AS Expr2, dbo.ProductUnits.AlisFiyati, Currencys_A.AlisRate, dbo.Products.Code1, 
                         dbo.Products.Code2, dbo.Products.Code3, dbo.Products.Code4
FROM            dbo.ProductCategories INNER JOIN
                         dbo.Categories ON dbo.ProductCategories.CategoryId = dbo.Categories.CatId INNER JOIN
                         dbo.ProductUnits INNER JOIN
                         dbo.Products ON dbo.ProductUnits.ProductId = dbo.Products.ProductId ON dbo.ProductCategories.ProductId = dbo.Products.ProductId INNER JOIN
                         dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId INNER JOIN
                         dbo.ProductImages ON dbo.Products.ProductId = dbo.ProductImages.ProductId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_P ON dbo.ProductUnits.PPb = Currencys_P.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_5 ON dbo.ProductUnits.Pb5 = Currencys_5.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_4 ON dbo.ProductUnits.Pb4 = Currencys_4.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_A ON dbo.ProductUnits.APb = Currencys_A.CurrencyId LEFT OUTER JOIN
                         dbo.Publishers ON dbo.Products.PublisherId = dbo.Publishers.PublisherId LEFT OUTER JOIN
                         dbo.Authors ON dbo.Products.AuthorId = dbo.Authors.AuthorId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_0 ON dbo.ProductUnits.Pb0 = Currencys_0.CurrencyId LEFT OUTER JOIN
                         dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_2 ON dbo.ProductUnits.Pb2 = Currencys_2.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_1 ON dbo.ProductUnits.Pb1 = Currencys_1.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_3 ON dbo.ProductUnits.Pb3 = Currencys_3.CurrencyId
WHERE        (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (dbo.ProductMarks.MarkId IS NULL) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (dbo.ProductMarks.MarkId IS NULL) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (dbo.ProductMarks.MarkId IS NULL) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) OR
                         (dbo.ProductImages.IsDefault = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductUnits.IsActive = 1) AND (dbo.ProductMarks.MarkId IS NULL)

GO


 

/****** Object:  View [dbo].[ProductListLigth]    Script Date: 13.7.2015 10:44:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER VIEW [dbo].[ProductListLigth]
AS
SELECT        dbo.Categories.CatId, dbo.Categories.CatName, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.ProductImages.Path, dbo.ProductMarks.MarKName, 
                         dbo.ProductUnits.SatisFiyati1, Currencys_1.CurrencyName AS Currency1, Currencys_1.Rate AS Rate1, dbo.Categories.PortalId, dbo.ProductMarks.MarkId, dbo.Categories.Url AS CatUrl, 
                         dbo.Products.Url AS ProductUrl, dbo.Categories.Lineage, dbo.Products.SearchKeywords, dbo.Products.StockQty, dbo.Products.Hit, dbo.ProductKdvs.KdvRate, dbo.Products.HizliKargo, 
                         dbo.Products.AyniGunTeslim, dbo.Products.IndirimliUrun, dbo.Products.FirsatUrunu, dbo.Products.SokFiyatliUrun, dbo.Products.EnUcuzUrun, dbo.Products.OzelUrun, dbo.Products.SinirliSayidaUrun, 
                         dbo.Products.YeniUrun, dbo.Products.HediyeliUrun, dbo.ProductMarks.Image AS MarkImage, dbo.Products.CompanyId
FROM            dbo.ProductCategories INNER JOIN
                         dbo.Categories ON dbo.ProductCategories.CategoryId = dbo.Categories.CatId INNER JOIN
                         dbo.ProductUnits INNER JOIN
                         dbo.Products ON dbo.ProductUnits.ProductId = dbo.Products.ProductId ON dbo.ProductCategories.ProductId = dbo.Products.ProductId INNER JOIN
                         dbo.ProductImages ON dbo.Products.ProductId = dbo.ProductImages.ProductId INNER JOIN
                         dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId LEFT OUTER JOIN
                         dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_1 ON dbo.ProductUnits.Pb1 = Currencys_1.CurrencyId
WHERE        (dbo.Categories.IsActive = 1) AND (dbo.ProductMarks.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) OR
          (dbo.Categories.IsActive = 1) AND (dbo.ProductImages.IsDefault = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) AND (NOT (dbo.ProductImages.Path = N'')) AND (Currencys_1.CurrencyId > 0) AND (dbo.ProductMarks.MarkId IS NULL)  


GO


 
/****** Object:  View [dbo].[ProductsExportAllOptions]    Script Date: 13.7.2015 10:45:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER VIEW [dbo].[ProductsExportAllOptions]
AS
SELECT        TOP (100) PERCENT P.IsActive AS UrunAktif, P.ProductCode AS StokKodu, P.ProductName AS StokAdi, P.Description AS StokAciklama, P.Details, P.CompanyId,
                         REPLACE(P.StockQty, '.', ',') AS StokEnvanter, ISNULL
                             ((SELECT        TOP 1 Path
                                 FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
                                 FROM            ProductImages
                                 WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 1), '') AS StokResmi, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 2), '') AS StokResmi2, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 3), '') AS StokResmi3, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 4), '') AS StokResmi4, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 5), '') AS StokResmi5, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 6), '') AS StokResmi6, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 7), '') AS StokResmi7, ISNULL
    ((SELECT        TOP 1 Path
        FROM            (SELECT        ROW_NUMBER() OVER (ORDER BY ProductId ASC) AS rownumber, Path, ProductId
        FROM            ProductImages
        WHERE        (ProductId = P.ProductId)) AS Images
WHERE        rownumber = 8), '') AS StokResmi8, ISNULL(dbo.ProductMarks.MarKName, N'') AS MarkaAdi, REPLACE(dbo.ProductKdvs.KdvRate, '.', ',') AS KdvOrani, 
dbo.ProductUnits.BirimAdi, REPLACE(dbo.ProductUnits.Carpan, '.', ',') AS BirimCarpan, REPLACE(dbo.ProductUnits.SatisFiyati0, '.', ',') AS SatisFiyati0, 
Currencys_0.CurrencyName AS SatisFiyati0ParaBirimi, REPLACE(dbo.ProductUnits.SatisFiyati1, '.', ',') AS SatisFiyati1, dbo.ProductUnits.Isk1, 
Currencys_1.CurrencyName AS SatisFiyati1ParaBirimi, REPLACE(dbo.ProductUnits.SatisFiyati2, '.', ',') AS SatisFiyati2, dbo.ProductUnits.Isk2, 
Currencys_2.CurrencyName AS SatisFiyati2ParaBirimi, REPLACE(dbo.ProductUnits.SatisFiyati3, '.', ',') AS SatisFiyati3, dbo.ProductUnits.Isk3, 
Currencys_3.CurrencyName AS SatisFiyati3ParaBirimi, REPLACE(dbo.ProductUnits.AlisFiyati, '.', ',') AS AlisFiyati, Currencys_A.CurrencyName AS AlisFiyatiParaBirimi, 
REPLACE(dbo.ProductUnits.En, '.', ',') AS En, REPLACE(dbo.ProductUnits.Boy, '.', ',') AS Boy, REPLACE(dbo.ProductUnits.Yukseklik, '.', ',') AS Yukseklik, 
REPLACE(dbo.ProductUnits.Agirlik, '.', ',') AS Agirlik, REPLACE(dbo.ProductUnits.Desi, '.', ',') AS Desi, P.PortalId, P.SellNoneStock, P.Code1 AS Kod1, P.Code2 AS Kod2, 
P.Code3 AS Kod3, P.Code4 AS Kod4, P.Code5 AS Kod5, P.Code6 AS Kod6, P.Code7 AS Kod7, P.Code8 AS Kod8, P.Code9 AS Kod9, P.Code10 AS Kod10, P.Code11 AS Kod11, 
P.Code12 AS Kod12, P.Code13 AS Kod13, P.Code14 AS Kod14, P.Code15 AS Kod15, P.ProductId AS UrunId, P.CreatedDate, P.ProviderStockCode AS UreticiKodu, 
dbo.Categories.Lineage, P.Url, dbo.Categories.Lineage2, P.SearchKeywords, dbo.ProductMarks.MarkId, P.IsPenta AS XmlTedarikciId, REPLACE(dbo.ProductUnits.PiyasaFiyati, 
'.', ',') AS PiyasaFiyati, Currencys_P.CurrencyName AS PiyasaFiyatiParaBirimi, Currencys_4.CurrencyName AS SatisFiyati4ParaBirimi, REPLACE(dbo.ProductUnits.SatisFiyati4, 
'.', ',') AS SatisFiyati4, dbo.ProductUnits.Isk4, Currencys_5.CurrencyName AS SatisFiyati5ParaBirimi, REPLACE(dbo.ProductUnits.SatisFiyati5, '.', ',') AS SatisFiyati5, 
dbo.ProductUnits.Isk5, P.HizliKargo, P.AyniGunTeslim, P.IndirimliUrun, P.FirsatUrunu, P.SokFiyatliUrun, P.EnUcuzUrun, P.OzelUrun, P.SinirliSayidaUrun, P.YeniUrun, 
P.HediyeliUrun, dbo.Providers.ProviderName AS TedarikciAdi, Providers_1.ProviderName AS XmlTedarikciAdi, dbo.Categories.CatId AS CatId1, dbo.Categories.Depth, 
P.ProductSizeOptionId, dbo.ProductUnits.Barcode
FROM            dbo.ProductKdvs RIGHT OUTER JOIN
                         dbo.Providers RIGHT OUTER JOIN
                         dbo.Providers AS Providers_1 RIGHT OUTER JOIN
                         dbo.Products AS P ON Providers_1.ProviderId = P.IsPenta ON dbo.Providers.ProviderId = P.ProviderId LEFT OUTER JOIN
                         dbo.Categories RIGHT OUTER JOIN
                         dbo.ProductCategories ON dbo.Categories.CatId = dbo.ProductCategories.CategoryId ON P.ProductId = dbo.ProductCategories.ProductId ON 
                         dbo.ProductKdvs.KdvId = P.KdvId LEFT OUTER JOIN
                         dbo.ProductMarks ON P.MarkId = dbo.ProductMarks.MarkId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_0 RIGHT OUTER JOIN
                         dbo.Currencys AS Currencys_4 INNER JOIN
                         dbo.ProductUnits ON Currencys_4.CurrencyId = dbo.ProductUnits.Pb4 INNER JOIN
                         dbo.Currencys AS Currencys_5 ON dbo.ProductUnits.Pb5 = Currencys_5.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_P ON dbo.ProductUnits.PPb = Currencys_P.CurrencyId ON Currencys_0.CurrencyId = dbo.ProductUnits.Pb0 LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_3 ON dbo.ProductUnits.Pb3 = Currencys_3.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_2 ON dbo.ProductUnits.Pb2 = Currencys_2.CurrencyId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_A ON dbo.ProductUnits.APb = Currencys_A.CurrencyId ON P.ProductId = dbo.ProductUnits.ProductId LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_1 ON dbo.ProductUnits.Pb1 = Currencys_1.CurrencyId
WHERE        (NOT (P.Url IS NULL)) AND (NOT (dbo.ProductUnits.UnitId IS NULL))


GO




 
/****** Object:  StoredProcedure [dbo].[AddCargo]    Script Date: 20.6.2015 10:53:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddCargo]
(
 
    @PortalId int,
    @CargoName   nvarchar(50),
    @CargoMail   nvarchar(50),
    @CashOnDelivery bit,
    @IsOnline bit=0,
    @ValueAdd decimal=0,
    @ValueAddKK decimal=0,
    @IsActive bit=1,
    @ShowOrder tinyint=0,
    @ShowDetails bit=0,
    @PriceForCountry bit=0,
    @DefaultPrice decimal=0,
    @CargoId      int OUTPUT
)
AS
IF NOT EXISTS ( select * from Cargo where CargoName=@CargoName and PortalId=@PortalId )
BEGIN
INSERT INTO Cargo
(

    CargoName,CargoMail,PortalId,CashOnDelivery,IsOnline,ValueAdd,IsActive,ShowOrder,ShowDetails,PriceForCountry,DefaultPrice,ValueAddKK
)

VALUES
(
    @CargoName,@CargoMail,@PortalId,@CashOnDelivery,@IsOnline,@ValueAdd,@IsActive,@ShowOrder,@ShowDetails,@PriceForCountry,@DefaultPrice,@ValueAddKK
)
SELECT
    @CargoId = @@Identity
END
ELSE
BEGIN
SELECT
    @CargoId = 0
END
GO

 
/****** Object:  StoredProcedure [dbo].[addToComplaintUnSubScribe]    Script Date: 20.6.2015 10:53:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[addToComplaintUnSubScribe]
@mail varchar(100),
@hashID varchar(50),
@complaintType Tinyint,
@UsersID int
AS
declare @userID int
declare @campaignID int
select @userID=userID,@campaignID=campaignID  from CosCampaign where hashID=@hashID

if not EXISTS(Select complaintID  From CosComplaintMail Where mail=@mail and userID=@userID )
begin
update Users set IsSendMail=0  where Email=@mail and UserId=@UsersID
update MailList set Durum=0  where Email=@mail
INSERT INTO CosComplaintMail
(
mail,
campaignID,
complaintType,
userID
)

VALUES
(
@mail,
@campaignID,
@complaintType,
@userID
)
select fromMail from cosUser where userID=@userID
end

else
begin
select '1'
end

GO
 
/****** Object:  StoredProcedure [dbo].[AddUser3]    Script Date: 20.6.2015 10:54:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[AddUser3]
(
@PortalId		int,
@UserType		int,
@FullName		nvarchar(100),
@UserSex		int=-2,
@Phone1			nvarchar(14)='',
@Phone2			nvarchar(14)='',
@FaxNumber		nvarchar(14),
@MobilePhone	nvarchar(14),
@CityId			int,
@Addres			nvarchar(400),
@CompanyName	nvarchar(100),
@CompanyPhone1	nvarchar(14),
@CompanyPhone2	nvarchar(14)='',
@CompanyEmail	nvarchar(100),
@CompanyCityId	int,
@CompanyId		int,
@CompanyAddres	nvarchar(400),
@CompanyWeb		nvarchar(100)='',
@Name			nvarchar(50),
@Email			nvarchar(100),
@Password		nvarchar(20),
@TCKimlikNo	    varchar(11)='',
@BirthDate		smalldatetime=null,
@Profession	    varchar(25)='',
@WhereToHear	varchar(50)='',
@Education		varchar(25)='',
@IsActive		bit,
@IsSupplier		bit,
@UserId			int OUTPUT
)
AS
set @UserId=-1
if not EXISTS(Select UserId From Users Where Email=@Email and PortalId=@PortalId)
begin
INSERT INTO Users
(
PortalId,		
UserType,		
FullName,		
UserSex	,	
Phone1	,		
Phone2	,	
FaxNumber,	
MobilePhone	,
CityId		,	
Addres		,
CompanyId	,
CompanyName	,
CompanyPhone1,	
CompanyPhone2,	
CompanyEmail,	
CompanyCityId,	
CompanyAddres,	
CompanyWeb,
Name	,		
Email	,		
Password,
TCKimlikNo,
BirthDate,
Profession,
WhereToHear,
Education,
ActivationCode,
IsActive,
IsSupplier
)

VALUES
(
@PortalId		,
@UserType		,
@FullName		,
@UserSex		,
@Phone1			,
@Phone2			,
@FaxNumber		,
@MobilePhone	,
@CityId			,
@Addres			,
@CompanyId		,
@CompanyName	,
@CompanyPhone1	,
@CompanyPhone2	,
@CompanyEmail	,
@CompanyCityId	,
@CompanyAddres	,
@CompanyWeb		,
@Name			,
@Email			,
@Password,		
@TCKimlikNo,
@BirthDate,
@Profession,
@WhereToHear,
@Education,
NEWID(),
@IsActive,
@IsSupplier
)

EXEC AddSupplierPreviliges @@Identity,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1

SELECT
    @UserId = @@Identity
    end
else
begin
select @UserId = 0
end

GO
 
/****** Object:  StoredProcedure [dbo].[CopyProduct]    Script Date: 13.7.2015 10:46:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER  PROCEDURE [dbo].[CopyProduct]
(
    @ProductId int,
    @NewProductId int OUTPUT
)
AS
insert into Products(PortalId, CategoryId, Parent, ProductCode, ProductName, Description, Details, ProviderStockCode, ProviderName, MarkId, IsDeleted, IsActive, SellNoneStock, StockQty, ShowInMainPage, ShowInCategoryPage, ShowOrder, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15, Provider, KdvId, Hit, IsPenta, CreatedDate,HizliKargo, AyniGunTeslim, IndirimliUrun, FirsatUrunu, SokFiyatliUrun, EnUcuzUrun, OzelUrun, SinirliSayidaUrun, YeniUrun, HediyeliUrun,ProviderId,UserId,StokType,StokSubType)
select PortalId, CategoryId, Parent, NEWID() , ProductName, Description, Details, ProviderStockCode, ProviderName, MarkId, IsDeleted, IsActive, SellNoneStock, StockQty, ShowInMainPage, ShowInCategoryPage, ShowOrder, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15, Provider, KdvId, Hit, IsPenta, GETDATE(),HizliKargo, AyniGunTeslim, IndirimliUrun, FirsatUrunu, SokFiyatliUrun, EnUcuzUrun, OzelUrun, SinirliSayidaUrun, YeniUrun, HediyeliUrun,ProviderId,UserId,StokType,StokSubType
FROM Products where ProductId=@ProductId
select @NewProductId=@@Identity

insert into ProductCategories(ProductId,CategoryId)
select @NewProductId,CategoryId FROM ProductCategories where ProductId=@ProductId

insert into ProductUnits(ProductId, Aciklama, BirimAdi, Carpan, AlisFiyati, APb,PiyasaFiyati,PPb,SatisFiyati0,Pb0, SatisFiyati1, Pb1, Isk1, SatisFiyati2, Pb2, Isk2, SatisFiyati3, Pb3, Isk3, SatisFiyati4, Pb4, Isk4, SatisFiyati5, Pb5, Isk5, Barcode, En, Boy, Yukseklik, Agirlik, Hacim, Desi, Indirim1, IsDefault, IsActive, LastModified)
select @NewProductId, Aciklama, BirimAdi, Carpan, AlisFiyati, APb,PiyasaFiyati,PPb,SatisFiyati0,Pb0, SatisFiyati1, Pb1, Isk1, SatisFiyati2, Pb2, Isk2, SatisFiyati3, Pb3, Isk3,SatisFiyati4, Pb4, Isk4, SatisFiyati5, Pb5, Isk5, Barcode, En, Boy, Yukseklik, Agirlik, Hacim, Desi, Indirim1, IsDefault, IsActive, LastModified
from ProductUnits where ProductId=@ProductId

insert into ProductUsages(ProductId,UProductId)
select @NewProductId, UProductId
FROM ProductUsages where ProductId=@ProductId

insert into ProductImages(ProductId, Description, Path, IsDefault)
select @NewProductId, Description, Path, IsDefault
FROM ProductImages where ProductId=@ProductId

insert into ProductFiles(ProductId, Description, Path, IsDefault)
 select @NewProductId, Description, Path, IsDefault
FROM ProductFiles where ProductId=@ProductId

insert into ProductAlternatives(ProductId, AProductId)
select @NewProductId,AProductId
FROM ProductAlternatives where ProductId=@ProductId

insert into ProductNonAlternatives(ProductId, NAProductId)
select @NewProductId,NAProductId
FROM ProductNonAlternatives where ProductId=@ProductId


INSERT INTO MultiDiscountList (StartQty,EndQty,DiscountType,DiscountAmount,UnitPrice,IsActive,ProductId,UnitId,UnitName)
                      (SELECT StartQty,EndQty,DiscountType,DiscountAmount,UnitPrice,IsActive,@NewProductId,UnitId,UnitName FROM MultiDiscountList Where ProductId=@ProductId)


 
/****** Object:  StoredProcedure [dbo].[GetGroupProducts]    Script Date: 20.6.2015 10:54:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER  PROCEDURE [dbo].[GetGroupProducts]
(
@ProductId int,
@StokIndirim int,
@StokIskActive bit,
@Type bit
)

AS
SELECT  distinct  ProductGroups.StockQty AS 'GroupStockQty',ProductGroups.UnitName,dbo.Products.ProductId,dbo.Products.ProductCode, dbo.Products.ProductName, Products.Url, Products.StockQty,Products.SellNoneStock,
'SatisFiyati'= case (@StokIndirim) when 0 then SatisFiyati1 when 1 then SatisFiyati1 when 2 then SatisFiyati2 when 3 then SatisFiyati3 when 4 then SatisFiyati4 when 5 then SatisFiyati5 end,  case when (@StokIskActive >0 ) then case when (@StokIndirim=0) then 0 when (@StokIndirim=1) then Isk1 when (@StokIndirim=2) then Isk2 when (@StokIndirim=3) then Isk3 when (@StokIndirim=4) then Isk4 when (@StokIndirim=5) then Isk5 end else 0 end as Indirim ,
dbo.Currencys.CurrencyName,Currencys.Rate,Products.Code14,ProductImages.Path
FROM         dbo.Products INNER JOIN
dbo.ProductUnits ON dbo.Products.ProductId = dbo.ProductUnits.ProductId INNER JOIN
dbo.ProductImages  ON dbo.Products.ProductId = dbo.ProductImages.ProductId INNER JOIN
dbo.Currencys ON case (@StokIndirim) when 0 then ProductUnits.Pb1 when 1 then ProductUnits.Pb1 when 2 then ProductUnits.Pb2 when 3 then ProductUnits.Pb3 when 4 then ProductUnits.Pb4 when 5 then ProductUnits.Pb5 end = dbo.Currencys.CurrencyId 
INNER JOIN ProductGroups ON dbo.Products.ProductId = ProductGroups.GProductId
WHERE     (NOT (dbo.Products.ProductId = @ProductId))
and (dbo.Products.ProductId in(Select ProductId from ProductGroups where GProductId=@ProductId AND ProductGroups.Type = @Type)
or dbo.Products.ProductId in(Select GProductId from ProductGroups where ProductId=@ProductId AND ProductGroups.Type = @Type))
AND (dbo.ProductUnits.IsDefault = 1) and (dbo.ProductImages.IsDefault = 1) AND dbo.Products.IsActive=1 AND ProductGroups.Type = @Type

GO

  
/****** Object:  StoredProcedure [dbo].[GetProductDetails5]    Script Date: 13.7.2015 10:46:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER  PROCEDURE [dbo].[GetProductDetails5]

	(
		@PortalId int,
		@ProductId int,
		@StokIndirim int,
		@StokIskActive bit,
		@UnitId int=0
	)

AS
if @UnitId=0
begin
	SELECT
	Details,ProductId, ProductCode, ProductName,Description, StockQty,KdvRate, Path,MarkId, MarkName,BirimAdi,AlisFiyati,AlisRate, Carpan,PiyasaFiyati,SatisFiyati0,Rate0,Currency0,
    'SatisFiyati'= case (@StokIndirim) when 0 then SatisFiyati1 when 1 then SatisFiyati1 when 2 then SatisFiyati2 when 3 then SatisFiyati3 when 4 then SatisFiyati4 when 5 then SatisFiyati5 end,  case when (@StokIskActive >0 ) then case when (@StokIndirim=0) then 0 when (@StokIndirim=1) then Isk1 when (@StokIndirim=2) then Isk2 when (@StokIndirim=3) then Isk3 when (@StokIndirim=4) then Isk4 when (@StokIndirim=5) then Isk5 end else 0 end as Indirim ,  
    'CurrencyName'= case (@StokIndirim) when 0 then Currency1 when 1 then Currency1 when 2 then Currency2 when 3 then Currency3 when 4 then Currency4 when 5 then Currency5 end,
    'Rate'= case (@StokIndirim) when 0 then Rate1 when 1 then Rate1 when 2 then Rate2 when 3 then Rate3 when 4 then Rate4 when 5 then Rate5 end,
    SellNoneStock,Code1,Code2,Code3,Code4,Code14,Code10,Code11,Code12,Code13,Code14,Code15,WizardId,CampainId,ForceCargo,Desi,CStartDate,CEndDate,StartDate,EndDate,PiyasaFiyati,SatisFiyati1,SatisFiyati2,SatisFiyati3,SatisFiyati4,SatisFiyati5,Isk1,Isk2,Isk3,Isk4,Isk5,CurrencyP,Currency1,Currency2,Currency3,Currency4,Currency5,RateP,Rate1,Rate2,Rate3,Rate4,Rate5,AuthorId,AuthorName,PublisherId,PublisherName,HizliKargo,EnUcuzUrun,AyniGunTeslim,OzelUrun,IndirimliUrun,SinirliSayidaUrun,FirsatUrunu,YeniUrun,SokFiyatliUrun,HediyeliUrun,ProductSizeOptionId
FROM       ProductListDetails5 
WHERE   (UnitsIsDefault = 1) AND  (ProductId = @ProductId) and (PortalId = @PortalId) 
end
else
begin
SELECT     
	Details,ProductId, ProductCode, ProductName,Description, StockQty,KdvRate, Path,MarkId,MarKName,BirimAdi,AlisFiyati,AlisRate, Carpan,PiyasaFiyati,SatisFiyati0,Rate0,Currency0,
    'SatisFiyati'= case (@StokIndirim) when 0 then SatisFiyati1 when 1 then SatisFiyati1 when 2 then SatisFiyati2 when 3 then SatisFiyati3 when 4 then SatisFiyati4 when 5 then SatisFiyati5 end,  case when (@StokIskActive >0 ) then case when (@StokIndirim=0) then 0 when (@StokIndirim=1) then Isk1 when (@StokIndirim=2) then Isk2 when (@StokIndirim=3) then Isk3 when (@StokIndirim=4) then Isk4 when (@StokIndirim=5) then Isk5 end else 0 end as Indirim ,  
    'CurrencyName'= case (@StokIndirim) when 0 then Currency1 when 1 then Currency1 when 2 then Currency2 when 3 then Currency3 when 4 then Currency4 when 5 then Currency5 end,
    'Rate'= case (@StokIndirim) when 0 then Rate1 when 1 then Rate1 when 2 then Rate2 when 3 then Rate3 when 4 then Rate4 when 5 then Rate5 end,
    SellNoneStock,Code1,Code2,Code3,Code4,Code10,Code11,Code12,Code13,Code14,Code15,WizardId,CampainId,ForceCargo,Desi,CStartDate,CEndDate,StartDate,EndDate,PiyasaFiyati,SatisFiyati1,SatisFiyati2,SatisFiyati3,SatisFiyati4,SatisFiyati5,Isk1,Isk2,Isk3,Isk4,Isk5,CurrencyP,Currency1,Currency2,Currency3,Currency4,Currency5,RateP,Rate1,Rate2,Rate3,Rate4,Rate5,AuthorId,AuthorName,PublisherId,PublisherName,HizliKargo,EnUcuzUrun,AyniGunTeslim,OzelUrun,IndirimliUrun,SinirliSayidaUrun,FirsatUrunu,YeniUrun,SokFiyatliUrun,HediyeliUrun,ProductSizeOptionId
FROM       ProductListDetails5 
WHERE    (UnitId = @UnitId) AND  (ProductId = @ProductId) and (PortalId = @PortalId) 
end


GO

 
/****** Object:  StoredProcedure [dbo].[GetProductDetails5a]    Script Date: 13.7.2015 10:47:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER  PROCEDURE [dbo].[GetProductDetails5a]

	(
		@PortalId int,
		@ProductId int,
		@StokIndirim int,
		@StokIskActive bit, 
		@UnitId int=0
	)

AS
if @UnitId=0
begin
	SELECT
	Details,ProductId, ProductCode, ProductName,Description, StockQty,KdvRate, Path,MarkId, MarkName,BirimAdi, Carpan,AlisFiyati,AlisRate,PiyasaFiyati,SatisFiyati0,Rate0,Currency0,
    'SatisFiyati'= case (@StokIndirim) when 0 then SatisFiyati1 when 1 then SatisFiyati1 when 2 then SatisFiyati2 when 3 then SatisFiyati3 when 4 then SatisFiyati4 when 5 then SatisFiyati5 end,  case when (@StokIskActive >0 ) then case when (@StokIndirim=0) then 0 when (@StokIndirim=1) then Isk1 when (@StokIndirim=2) then Isk2 when (@StokIndirim=3) then Isk3 when (@StokIndirim=4) then Isk4 when (@StokIndirim=5) then Isk5 end else 0 end as Indirim ,  
    'CurrencyName'= case (@StokIndirim) when 0 then Currency1 when 1 then Currency1 when 2 then Currency2 when 3 then Currency3 when 4 then Currency4 when 5 then Currency5 end,
    'Rate'= case (@StokIndirim) when 0 then Rate1 when 1 then Rate1 when 2 then Rate2 when 3 then Rate3 when 4 then Rate4 when 5 then Rate5 end,
    SellNoneStock,Code1,Code2,Code3,Code4,Code10,Code11,Code12,Code13,Code14,Code15,WizardId,CampainId,ForceCargo,Desi,StartDate,EndDate,PiyasaFiyati,SatisFiyati1,SatisFiyati2,SatisFiyati3,SatisFiyati4,SatisFiyati5,Isk1,Isk2,Isk3,Isk4,Isk5,CurrencyP,Currency1,Currency2,Currency3,Currency4,Currency5,RateP,Rate1,Rate2,Rate3,Rate4,Rate5,AuthorId,AuthorName,PublisherId,PublisherName,CatIsActive,MarkIsActive,ProductIsActive,HizliKargo,EnUcuzUrun,AyniGunTeslim,OzelUrun,IndirimliUrun,SinirliSayidaUrun,FirsatUrunu,YeniUrun,SokFiyatliUrun,HediyeliUrun
FROM       ProductListDetails5a 
WHERE   (UnitsIsDefault = 1) AND  (ProductId = @ProductId) and (PortalId = @PortalId)  
end
else
begin
SELECT     
	Details,ProductId, ProductCode, ProductName,Description, StockQty,KdvRate, Path,MarkId, MarKName,BirimAdi, Carpan,AlisFiyati,AlisRate,PiyasaFiyati,SatisFiyati0,Rate0,Currency0,
    'SatisFiyati'= case (@StokIndirim) when 0 then SatisFiyati1 when 1 then SatisFiyati1 when 2 then SatisFiyati2 when 3 then SatisFiyati3 when 4 then SatisFiyati4 when 5 then SatisFiyati5 end,  case when (@StokIskActive >0 ) then case when (@StokIndirim=0) then 0 when (@StokIndirim=1) then Isk1 when (@StokIndirim=2) then Isk2 when (@StokIndirim=3) then Isk3 when (@StokIndirim=4) then Isk4 when (@StokIndirim=5) then Isk5 end else 0 end as Indirim ,  
    'CurrencyName'= case (@StokIndirim) when 0 then Currency1 when 1 then Currency1 when 2 then Currency2 when 3 then Currency3 when 4 then Currency4 when 5 then Currency5 end,
    'Rate'= case (@StokIndirim) when 0 then Rate1 when 1 then Rate1 when 2 then Rate2 when 3 then Rate3 when 4 then Rate4 when 5 then Rate5 end,
    SellNoneStock,Code1,Code2,Code3,Code4,Code10,Code11,Code12,Code13,Code14,Code15,WizardId,CampainId,ForceCargo,Desi,StartDate,EndDate,PiyasaFiyati,SatisFiyati1,SatisFiyati2,SatisFiyati3,SatisFiyati4,SatisFiyati5,Isk1,Isk2,Isk3,Isk4,Isk5,CurrencyP,Currency1,Currency2,Currency3,Currency4,Currency5,RateP,Rate1,Rate2,Rate3,Rate4,Rate5,AuthorId,AuthorName,PublisherId,PublisherName,CatIsActive,MarkIsActive,ProductIsActive,HizliKargo,EnUcuzUrun,AyniGunTeslim,OzelUrun,IndirimliUrun,SinirliSayidaUrun,FirsatUrunu,YeniUrun,SokFiyatliUrun,HediyeliUrun
FROM       ProductListDetails5a 
WHERE    (UnitId = @UnitId) AND  (ProductId = @ProductId) and (PortalId = @PortalId) 
end


 
GO
 
  
/****** Object:  StoredProcedure [dbo].[ImportXlsCategories]    Script Date: 13.7.2015 10:50:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ImportXlsCategories]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE Procedure [dbo].[ImportXlsCategories]
(
@PortalId		int,
@CategoryCode	nvarchar(100),
@CatName		nvarchar(100),
@Parent			int,
@IsActive		bit,
@IsVisible		bit,
@CatId			int OUTPUT
)
AS


IF @CategoryCode IS NULL OR @CategoryCode=''''
BEGIN
SELECT @CategoryCode=CategoryCode FROM Categories WHERE CatName=@CatName AND Parent=@Parent
IF @CategoryCode IS NULL OR @CategoryCode=''''
BEGIN
SELECT @CategoryCode=NEWID()
END
END



SELECT @CatId = CatId FROM Categories WHERE CatName = @CatName AND Parent=@Parent
     
IF @CatId IS NULL
begin
INSERT INTO Categories
(
PortalId,		
CategoryCode,		
CatName,		
Parent,	
IsActive,		
IsVisible
)

VALUES
(
@PortalId,
@CategoryCode,
@CatName,
@Parent,
@IsActive,
@IsVisible
)

SELECT
    @CatId = @@Identity
    end
else
begin
Update Categories Set PortalId=@PortalId,CategoryCode=@CategoryCode,CatName=@CatName,Parent=@Parent,IsActive=@IsActive,IsVisible=@IsVisible Where CatId=@CatId
Select @CatId
end
' 
END
GO
/****** Object:  StoredProcedure [dbo].[ShoppingCartAddItemMobile]    Script Date: 13.7.2015 10:50:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ShoppingCartAddItemMobile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[ShoppingCartAddItemMobile]
(
    @CartId nvarchar(50),
    @ShoppingCartDefId as int,
    @ProdId int,
	@Qty decimal,
	@PriceId int=0, 
	@Description nvarchar(500)='''',
	@Attributes nvarchar(255)='''',
	@ValueAdd decimal(18,4)=0,
	@NewDesi decimal(18,2)=0,
	@ProductSizeId int=0,
	@StorageId int ,
	@CartTimeOut datetime,
	@Mobile int,
	@Return int OUTPUT
)
As
-- do not allow to buy or add product is not in stock (ferit)
DECLARE @Stock int
Declare @SellNoneStock bit
declare @SellLimitToUser tinyint
declare @Price_Id int
DECLARE @CountItems int
DECLARE @Carpan decimal
DECLARE @InCart decimal
 
if @PriceId=0
begin
select @Price_Id=UnitId from ProductUnits where IsDefault=1 and ProductId=@ProdId
end
else
Begin
select @Price_Id=@PriceId 
end

if @ProductSizeId=0
	Begin
	SELECT @Stock = StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products	WHERE ProductId = @ProdId    
	SELECT @CountItems = isnull(sum(Qty),0) FROM ShoppingCart WHERE ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId AND CartId = @CartId AND Description=@Description and PriceId=@Price_Id 
	SELECT @InCart = isnull(sum(Qty * Carpan),0) from ShoppingCart as c inner join ProductUnits as u on c.ProdId=u.ProductId  and c.PriceId=u.UnitId  WHERE  ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId  AND CartId = @CartId 
	SELECT @Carpan=Carpan from ProductUnits  WHERE ProductId  = @ProdId AND UnitId=@Price_Id
	End
Else
	Begin
	SELECT @Stock = ProductSizes.StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products inner join ProductSizes on Products.ProductId=ProductSizes.ProductId WHERE Products.ProductId = @ProdId and ProductSizeId=@ProductSizeId   
	SELECT @CountItems = isnull(sum(Qty),0) FROM ShoppingCart WHERE ProdId = @ProdId AND PriceId=@Price_Id and ShoppingCartDefId=@ShoppingCartDefId AND CartId = @CartId and ProductSizeId=@ProductSizeId 
	End

 -- do not allow to buy or add product is not alloved max qty (ferit)
if @SellLimitToUser>0	
	Begin
		Declare @SellCount int
		select @SellCount=SUM(Quantity * Carpan) from orderList
		where ProductId=@ProdId and CustomerId=@CartId group by CustomerId
		
		if isnull(@SellCount,0)+isnull(@CountItems,0)+ (@Qty *@Carpan) > @SellLimitToUser
			Begin	
			SELECT @Return=2
			UPDATE ShoppingCart SET Qty = @SellLimitToUser 
			WHERE ProdId = @ProdId AND PriceId=@Price_Id AND CartId = @CartId and ShoppingCartDefId=@ShoppingCartDefId and Attributes=@Attributes
			RETURN 			
			End
	end 
-- do not allow to buy or add product is not in stock (ferit)
IF @CountItems > 0  /* There are items - update the current quantity */
 BEGIN
	If ((@Stock >=(@InCart + (@Qty *@Carpan)))or (@SellNoneStock=1))
    	BEGIN    	
		UPDATE ShoppingCart SET Qty = (@Qty + ShoppingCart.Qty)
   		WHERE ProdId = @ProdId AND PriceId=@Price_Id AND CartId = @CartId and ShoppingCartDefId=@ShoppingCartDefId and Attributes=@Attributes
		SELECT @Return=1
		END
	else
	begin
	SELECT @Return=0
	end
END
ELSE  /* New entry for this Cart.  Add a new record */
BEGIN
	If ((@Stock >=((@Qty *@Carpan) + @InCart)) or (@SellNoneStock=1))
		BEGIN   	
   		 INSERT INTO ShoppingCart (CartId,ShoppingCartDefId,Qty,ProdId,PriceId,Description,Attributes,ValueAdd,NewDesi,ProductSizeId,CartTimeOut,StorageId,Mobile)
   		 VALUES (@CartId,@ShoppingCartDefId,@Qty,@ProdId,@Price_Id,@Description,@Attributes,@ValueAdd,@NewDesi,@ProductSizeId,@CartTimeOut,@StorageId,@Mobile)
		SELECT @Return=(select top 1 RecordId from ShoppingCart order by RecordId desc)
		END
	ELSE
		SELECT @Return=0
END

 
SET ANSI_NULLS ON



' 
END
GO


/****** Object:  StoredProcedure [dbo].[ProductsMostPopular]    Script Date: 20.6.2015 10:55:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER Procedure [dbo].[ProductsMostPopular]
@PortalId int,
@CategoryId int,
@Count int = 5
AS

if @CategoryId<1
	begin
exec('SELECT  TOP ' + @Count + ' SUM(od.Quantity  * od.Carpan)  AS NewTotal,(isnull((select SUM(od2.Quantity  * od2.Carpan) from OrdersListDetails as od2 where ProductId=od.ProductId and OrderDate > DATEADD(day,-7,GETDATE())),0)) AS OldTotal,
				Products.ProductId, Products.ProductCode AS ProductCode, Products.ProductName AS ProductName,Products.ProductUrl,Products.Path
FROM OrdersListDetails as od 
				INNER JOIN ProductListLigth Products ON od.ProductId = Products.ProductId
WHERE (Products.PortalId = ' + @PortalId + ')
GROUP BY Products.ProductId, Products.ProductCode, Products.ProductName,Products.ProductUrl,Products.Path,od.ProductId 
ORDER BY SUM(od.Quantity * od.Carpan) DESC')
	end
else
	begin
exec('SELECT TOP ' + @Count + ' SUM(od.Quantity * od.Carpan) AS NewTotal,(isnull((select SUM(od2.Quantity  * od2.Carpan) from OrdersListDetails as od2 where ProductId=od.ProductId and OrderDate > DATEADD(day,-7,GETDATE())),0)) AS OldTotal,
				 Products.ProductId, Products.ProductCode AS ProductCode,  Products.ProductName AS ProductName, Products.ProductUrl,Products.Path
FROM         OrdersListDetails as od INNER JOIN
                 ProductListLigth Products ON od.ProductId = Products.ProductId INNER JOIN
                 ProductCategories ON od.ProductId = ProductCategories.ProductId
WHERE     (Products.PortalId = ' + @PortalId + ') AND (ProductCategories.CategoryId = ' + @CategoryId + ')
GROUP BY Products.ProductId, Products.ProductCode, Products.ProductName, Products.ProductUrl,Products.Path,od.ProductId 
ORDER BY SUM(od.Quantity * od.Carpan) DESC ')
	end



GO

 
/****** Object:  StoredProcedure [dbo].[ShoppingCartAddItem]    Script Date: 13.7.2015 10:51:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[ShoppingCartAddItem]
(
    @CartId nvarchar(50),
    @ShoppingCartDefId as int,
    @ProdId int,
	@Qty decimal,
	@PriceId int=0, 
	@Description nvarchar(500)='',
	@Attributes nvarchar(255)='',
	@ValueAdd decimal(18,4)=0,
	@NewDesi decimal(18,2)=0,
	@ProductSizeId int=0,
	@StorageId int ,
	@CartTimeOut datetime,
	@Return int OUTPUT
)
As
-- do not allow to buy or add product is not in stock (ferit)
DECLARE @Stock int
Declare @SellNoneStock bit
declare @SellLimitToUser tinyint
declare @Price_Id int
DECLARE @CountItems int
DECLARE @Carpan decimal
DECLARE @InCart decimal
 
if @PriceId=0
begin
select @Price_Id=UnitId from ProductUnits where IsDefault=1 and ProductId=@ProdId
end
else
Begin
select @Price_Id=@PriceId 
end

if @ProductSizeId=0
	Begin
	SELECT @Stock = StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products	WHERE ProductId = @ProdId    
	SELECT @CountItems = isnull(sum(Qty),0) FROM ShoppingCart WHERE ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId AND CartId = @CartId AND Description=@Description and PriceId=@Price_Id 
	SELECT @InCart = isnull(sum(Qty * Carpan),0) from ShoppingCart as c inner join ProductUnits as u on c.ProdId=u.ProductId  and c.PriceId=u.UnitId  WHERE  ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId  AND CartId = @CartId 
	SELECT @Carpan=Carpan from ProductUnits  WHERE ProductId  = @ProdId AND UnitId=@Price_Id
	End
Else
	Begin
	SELECT @Stock = ProductSizes.StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products inner join ProductSizes on Products.ProductId=ProductSizes.ProductId WHERE Products.ProductId = @ProdId and ProductSizeId=@ProductSizeId   
	SELECT @CountItems = isnull(sum(Qty),0) FROM ShoppingCart WHERE ProdId = @ProdId AND PriceId=@Price_Id and ShoppingCartDefId=@ShoppingCartDefId AND CartId = @CartId and ProductSizeId=@ProductSizeId 
	SELECT @InCart = isnull(sum(Qty * Carpan),0) from ShoppingCart as c inner join ProductUnits as u on c.ProdId=u.ProductId  and c.PriceId=u.UnitId  WHERE  ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId  AND CartId = @CartId 
	SELECT @Carpan=Carpan from ProductUnits  WHERE ProductId  = @ProdId AND UnitId=@Price_Id
	End

 -- do not allow to buy or add product is not alloved max qty (ferit)
if @SellLimitToUser>0	
	Begin
		Declare @SellCount int
		select @SellCount=SUM(Quantity * Carpan) from orderList
		where ProductId=@ProdId and CustomerId=@CartId group by CustomerId
		
		if isnull(@SellCount,0)+isnull(@CountItems,0)+ (@Qty *@Carpan) > @SellLimitToUser
			Begin	
			SELECT @Return=2
			UPDATE ShoppingCart SET Qty = @SellLimitToUser 
			WHERE ProdId = @ProdId AND PriceId=@Price_Id AND CartId = @CartId and ShoppingCartDefId=@ShoppingCartDefId and Attributes=@Attributes and Description=@Description
			RETURN 			
			End
	end 
-- do not allow to buy or add product is not in stock (ferit)
IF @CountItems > 0  /* There are items - update the current quantity */
 BEGIN
	If ((@Stock >=(@InCart + (@Qty *@Carpan)))or (@SellNoneStock=1))
    	BEGIN    	
		UPDATE ShoppingCart SET Qty = (@Qty + ShoppingCart.Qty)
   		WHERE ProdId = @ProdId AND PriceId=@Price_Id AND CartId = @CartId and ShoppingCartDefId=@ShoppingCartDefId and Attributes=@Attributes and Description=@Description
		SELECT @Return=1
		END
	else
	begin
	SELECT @Return=0
	end
END
ELSE  /* New entry for this Cart.  Add a new record */
BEGIN
	If ((@Stock >=((@Qty *@Carpan) + @InCart)) or (@SellNoneStock=1))
		BEGIN   	
   		 INSERT INTO ShoppingCart (CartId,ShoppingCartDefId,Qty,ProdId,PriceId,Description,Attributes,ValueAdd,NewDesi,ProductSizeId,CartTimeOut,StorageId)
   		 VALUES (@CartId,@ShoppingCartDefId,@Qty,@ProdId,@Price_Id,@Description,@Attributes,@ValueAdd,@NewDesi,@ProductSizeId,@CartTimeOut,@StorageId)
		SELECT @Return=(select top 1 RecordId from ShoppingCart order by RecordId desc)
		END
	ELSE
		SELECT @Return=0
END
 
SET ANSI_NULLS ON

GO
 
  
/****** Object:  StoredProcedure [dbo].[ShoppingCartUpdate2]    Script Date: 15.7.2015 09:46:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER  PROCEDURE [dbo].[ShoppingCartUpdate2]
(
    @RecordId int,
    @CartId    nvarchar(50),
    @ProdId int,
    @ShoppingCartDefId int,
    @Qty  decimal,
	@PriceId int=0, 
    @Return tinyint OUTPUT
)
AS
--do not allow to update more quantity than stock (ferit)
declare @Stock int
declare @SellNoneStock bit
declare @SellLimitToUser tinyint
declare @Price_Id int
declare @ProductSizeId int
DECLARE @CountItems decimal
DECLARE @Carpan decimal

if @PriceId=0
begin
select @Price_Id=UnitId from ProductUnits where IsDefault=1 and ProductId=@ProdId
end
else
Begin
select @Price_Id=@PriceId 
end

SELECT @Stock = StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products WHERE ProductId = @ProdId
--Tekstil Control (ferit)
Select @ProductSizeId=ProductSizeId from ShoppingCart where RecordId=@RecordId
if @ProductSizeId=0
	Begin
	SELECT @Stock = StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products	WHERE ProductId = @ProdId    
	SELECT @CountItems = isnull(sum(Qty * Carpan),0) from ShoppingCart as c inner join ProductUnits as u on c.ProdId=u.ProductId  and c.PriceId=u.UnitId  WHERE  ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId  AND CartId = @CartId and PriceId<>@Price_Id 
	SELECT @Carpan=Carpan from ProductUnits  WHERE ProductId  = @ProdId AND UnitId=@Price_Id
	End
Else
	Begin
	SELECT @Stock = ProductSizes.StockQty,@SellNoneStock=SellNoneStock,@SellLimitToUser=isnull(SellLimitToUser,0) FROM Products inner join ProductSizes on Products.ProductId=ProductSizes.ProductId WHERE Products.ProductId = @ProdId and ProductSizeId=@ProductSizeId   
	--SELECT @CountItems = isnull(sum(Qty),0) FROM ShoppingCart WHERE  ProdId = @ProdId AND PriceId=@Price_Id and ShoppingCartDefId=@ShoppingCartDefId  AND CartId = @CartId  and ProductSizeId=@ProductSizeId
	SELECT @CountItems = isnull(sum(Qty * Carpan),0) from ShoppingCart as c inner join ProductUnits as u on c.ProdId=u.ProductId  and c.PriceId=u.UnitId  WHERE  ProdId = @ProdId  and ShoppingCartDefId=@ShoppingCartDefId  AND CartId = @CartId and PriceId<>@Price_Id and ProductSizeId=@ProductSizeId
	SELECT @Carpan=Carpan from ProductUnits  WHERE ProductId  = @ProdId AND UnitId=@Price_Id 
	End

 


 -- do not allow to buy or add product is not alloved max qty (ferit)
if @SellLimitToUser>0
Begin
	Declare @SellCount int
	select @SellCount=SUM(Quantity * Carpan) from orderList where ProductId=@ProdId and CustomerId=@CartId group by CustomerId

	if isnull(@SellCount,0)+ (@Qty *@Carpan) > @SellLimitToUser
		Begin
		SELECT @Return=2
		UPDATE ShoppingCart SET Qty = @SellLimitToUser
		WHERE CartId = @CartId AND PriceId=@Price_Id AND ProdId = @ProdId and ShoppingCartDefId=@ShoppingCartDefId and RecordId=@RecordId
		RETURN
	End
end 
-- do not allow to buy or add product is not in stock (ferit)
If ((@Stock >=(@CountItems + (@Qty * @Carpan)))or (@SellNoneStock=1))
--IF ((@Stock >=  @Qty) or (@SellNoneStock=1))
BEGIN
	SELECT @Return=1
	UPDATE ShoppingCart SET Qty = @Qty
	WHERE CartId = @CartId AND PriceId=@Price_Id AND ProdId = @ProdId and ShoppingCartDefId=@ShoppingCartDefId and RecordId=@RecordId
END
ELSE
SELECT @Return=0

 

GO




 
/****** Object:  Trigger [dbo].[UpdateCancelStatus]    Script Date: 13.7.2015 10:53:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER   TRIGGER [dbo].[UpdateCancelStatus]
ON [dbo].[CancelOrder]
FOR UPDATE
AS 
BEGIN

if UPDATE (Status)
BEGIN
declare @OStatus int,@NStatus int,@CancelOrderId int,@UserId int
SELECT	@NStatus=Status,@CancelOrderId= IND,@UserId=AcceptUserId  from Inserted
SELECT	@OStatus=Status from Deleted
Update CancelOrderDetails set Status=@NStatus,AcceptUserId=@UserId,LastChange=GETDATE() where CancelOrderId=@CancelOrderId and Status=@OStatus

Update CancelOrderDetails set AcceptDate=GETDATE() where CancelOrderId=@CancelOrderId and Status=@OStatus and (@OStatus=-8 or @OStatus=-11)
END
END


GO

SET IDENTITY_INSERT [dbo].[ProductStokType] ON 
INSERT INTO [dbo].[ProductStokType] (StokTypeId,StokTypeName, StokTypeUrl) VALUES (7,N'Kombin','')
INSERT INTO [dbo].[ProductStokType] (StokTypeId,StokTypeName, StokTypeUrl) VALUES (8,N'Gayrimenkul - Menkul','')
SET IDENTITY_INSERT [dbo].[ProductStokType] OFF
 
GO

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_ModuleSettings' AND object_id = OBJECT_ID('ModuleSettings'))
    BEGIN
     create index IX_ModuleSettings on ModuleSettings(ModuleId,SettingName);
    END
GO

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_ProductCategories' AND object_id = OBJECT_ID('ProductCategories'))
    BEGIN
     create index IX_ProductCategories on ProductCategories(CategoryId,ProdCatId);
    END
GO

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_ProductCategories_1' AND object_id = OBJECT_ID('ProductCategories'))
    BEGIN
     create index IX_ProductCategories_1 on ProductCategories(ProductId);
    END
GO

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_Categories' AND object_id = OBJECT_ID('Categories'))
    BEGIN
     create index IX_Categories on Categories(StartDate);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_Categories_1' AND object_id = OBJECT_ID('Categories'))
    BEGIN
     create index IX_Categories_1 on Categories(EndDate);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Ix_ProductImages' AND object_id = OBJECT_ID('ProductImages'))
    BEGIN
     create index Ix_ProductImages on ProductImages(ProductId,IsDefault);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Ix_ProductMarks' AND object_id = OBJECT_ID('ProductMarks'))
    BEGIN
     create index Ix_ProductMarks on ProductMarks(PortalId,MarKName,IsActive);
    END
GO

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Ix_ProductUnits' AND object_id = OBJECT_ID('ProductUnits'))
    BEGIN
     create index Ix_ProductUnits on ProductUnits(ProductId,IsDefault);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_Providers' AND object_id = OBJECT_ID('Providers'))
    BEGIN
     create unique index IX_Providers on Providers(ProviderId,ProviderName);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_Product3dPictures' AND object_id = OBJECT_ID('Product3dPictures'))
    BEGIN
     create clustered index IX_Product3dPictures on Product3dPictures(ProductId);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_Products' AND object_id = OBJECT_ID('Products'))
    BEGIN
     create index IX_Products on Products(ProductCode);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'IX_Products_1' AND object_id = OBJECT_ID('Products'))
    BEGIN
     create index IX_Products_1 on Products(ProductName);
    END
GO
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'xxx' AND object_id = OBJECT_ID('ProductWizardValues'))
    BEGIN
     create index xxx on ProductWizardValues(ProductId,LookUpId);
    END
GO 

 
UPDATE Portals Set Version='3.2.0'
 
GO

