
IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'Portals' and column_name = 'CargoLimitAbroad') ALTER TABLE [dbo].Portals ADD [CargoLimitAbroad] decimal(18,2)
IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'PricePaymentList' and column_name = 'CargoDiscount') ALTER TABLE [dbo].PricePaymentList ADD [CargoDiscount] bit
IF not exists (select column_name from INFORMATION_SCHEMA.columns  where table_name = 'ShoppingCart' and column_name = 'ValueAddNoQty') ALTER TABLE [dbo].ShoppingCart ADD [ValueAddNoQty]  decimal(18,4) not null default ((0))
GO
  
    
/****** Object:  Table [dbo].[CampainCargo]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CampainCargo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CampainCargo](
	[IND] [int] IDENTITY(1,1) NOT NULL,
	[CampainId] [int] NULL,
	[CargoDiscountType] [int] NULL,
	[CargoDiscountAmount] [decimal](18, 2) NULL,
	[CargoMinPrice] [decimal](18, 2) NULL,
	[CargoMaxPrice] [decimal](18, 2) NULL,
 CONSTRAINT [PK_CampainCargo] 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].[PricePaymentCargo]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PricePaymentCargo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PricePaymentCargo](
	[IND] [int] IDENTITY(1,1) NOT NULL,
	[PricePaymentId] [int] NULL,
	[CargoId] [int] NULL,
	[CargoName] [nvarchar](50) NULL,
	[DiscountType] [int] NULL,
	[DiscountAmount] [decimal](18, 2) NULL,
 CONSTRAINT [PK_PricePaymentCargo] 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].[TempCategorieRelations]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TempCategorieRelations]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TempCategorieRelations](
	[IND] [int] IDENTITY(1,1) NOT NULL,
	[ProCatId] [int] NULL,
	[TempCatId] [int] NULL,
 CONSTRAINT [PK_TempCategorieRelations] 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].[TempCategories]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TempCategories]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TempCategories](
	[TempCatId] [int] IDENTITY(1,1) NOT NULL,
	[TempCatName] [nvarchar](100) NULL,
	[TempCatCode] [nvarchar](100) NULL,
	[TempParent] [int] NULL,
	[Lineage] [nvarchar](100) NULL,
	[Depth] [int] NULL CONSTRAINT [DF_TempCategories_Depth]  DEFAULT ((0)),
	[Lineage2] [varchar](100) NULL,
 CONSTRAINT [PK_TempCategories] PRIMARY KEY CLUSTERED 
(
	[TempCatId] 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 OFF
GO
/****** Object:  Table [dbo].[Top10Group]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Top10Group]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Top10Group](
	[TabId] [int] IDENTITY(1,1) NOT NULL,
	[PortalId] [int] NULL,
	[ModuleId] [int] NULL,
	[TabName] [nvarchar](250) NULL,
	[TabIsActive] [bit] NULL,
	[TabImg] [nvarchar](250) NULL,
	[TabCatId] [int] NULL,
	[FirstSelect] [bit] NULL,
 CONSTRAINT [PK_Top10Grup] PRIMARY KEY CLUSTERED 
(
	[TabId] 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:  Trigger [dbo].[TempCategories_InsertTrigger]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TempCategories_InsertTrigger]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TempCategories_InsertTrigger]
ON [dbo].[TempCategories]
FOR INSERT AS
UPDATE child
   
    SET Depth = ISNULL(parent.Depth + 1,0), 
    -- the Lineage is simply the Lineage of the parent,
    -- plus the child''s Id (and appropriate ''/'' characters
    Lineage = ISNULL(parent.Lineage,''/'') + LTrim(Str(child.TempCatId)) + ''/'' ,
    Lineage2 = ISNULL(parent.Lineage2,''|'') + LTrim(child.TempCatName) + ''|'' 

FROM TempCategories child INNER JOIN inserted i ON i.TempCatId=child.TempCatId
-- now, we attempt to find the parent of this
-- "child" - but it might not exist, so these
-- values may well be NULL
LEFT OUTER JOIN TempCategories parent ON child.TempParent=parent.TempCatId
' 
GO
/****** Object:  Trigger [dbo].[TempCategories_UpdateTrigger]    Script Date: 31.8.2015 15:13:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TempCategories_UpdateTrigger]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TempCategories_UpdateTrigger]
ON [dbo].[TempCategories]
FOR UPDATE AS

UPDATE child
    SET  
--    IsVisible=old.IsVisible,
    Depth = child.Depth - old.Depth + ISNULL(parent.Depth + 1,0),
    Lineage = ISNULL(parent.Lineage,''/'') + LTrim(Str(old.TempCatId)) + ''/'' + right(child.Lineage, len(child.Lineage) - len(old.Lineage)),
    Lineage2 = ISNULL(parent.Lineage2,''|'') + old.TempCatName + ''|'' + (right(child.Lineage2, len(child.Lineage2) - len(old.Lineage2)))  
    
FROM TempCategories child INNER JOIN inserted old ON child.Lineage LIKE old.Lineage + ''%''
LEFT OUTER JOIN TempCategories parent ON old.TempParent=parent.TempCatId
' 
GO


 
/****** Object:  View [dbo].[ProductList]    Script Date: 31.8.2015 15:16:56 ******/
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, dbo.ProductImages.Description AS ImageDesc
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 AND dbo.ProductImages.IsDefault = 1 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.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 (ProductMarks.MarkId is NULL and (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()))

GO


/****** Object:  View [dbo].[ProductsSitemap]    Script Date: 31.8.2015 15:17:21 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

/* View*/
ALTER VIEW [dbo].[ProductsSitemap]
AS
SELECT        dbo.Categories.CatId, dbo.Categories.CatName, dbo.Products.ProductId, dbo.Categories.PortalId, dbo.Categories.Url AS CatUrl, dbo.Products.Url AS ProductUrl, dbo.Products.ProductName
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 LEFT OUTER JOIN
                         dbo.Currencys AS Currencys_0 ON dbo.ProductUnits.Pb0 = Currencys_0.CurrencyId
WHERE        (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1) OR
                         (dbo.Categories.IsActive = 1) AND (dbo.ProductUnits.IsDefault = 1) AND (dbo.Products.IsActive = 1)

GO


/****** Object:  StoredProcedure [dbo].[GetProductDetails5a]    Script Date: 31.8.2015 15:18:14 ******/
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].[ShoppingCartAddItem]    Script Date: 31.8.2015 15:18:47 ******/
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,
	@ValueAddNoQty 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,ValueAddNoQty)
   		 VALUES (@CartId,@ShoppingCartDefId,@Qty,@ProdId,@Price_Id,@Description,@Attributes,@ValueAdd,@NewDesi,@ProductSizeId,@CartTimeOut,@StorageId,@ValueAddNoQty)
		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].[ShoppingCartMigrate]    Script Date: 31.8.2015 15:19:32 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER  PROCEDURE [dbo].[ShoppingCartMigrate]
(
    @OriginalCartId nvarchar(50),
    @NewCartId      nvarchar(50)
)
AS

declare @ProdId int
declare @PriceId int
declare @Qty int
declare @Description varchar(500)
declare @Attributes varchar(255)
declare @ValueAdd decimal(18,4)
declare @ValueAddNoQty decimal(18,4)
declare @NewDesi decimal(18,2)
declare @ProductSizeId int
declare @CartTimeOut datetime
declare @StorageId int

DECLARE c_cursor CURSOR FOR 
   SELECT ProdId,PriceId,Qty,Description,Attributes,ValueAdd,ValueAddNoQty,NewDesi,ProductSizeId,CartTimeOut,StorageId FROM ShoppingCart  WHERE CartId=@OriginalCartId

   OPEN c_cursor
   FETCH NEXT FROM c_cursor INTO @ProdId,@PriceId,@Qty,@Description,@Attributes,@ValueAdd,@ValueAddNoQty,@NewDesi,@ProductSizeId,@CartTimeOut,@StorageId
--Print @ProdId 
--Print @PriceId 
--Print @Qty
--Print '�r�n'
   WHILE @@FETCH_STATUS = 0
   BEGIN
   declare @RecordId int
   declare @Return bit
	exec ShoppingCartAddItem @NewCartId,0,@ProdId,@Qty,@PriceId,@Description,@Attributes,@ValueAdd,@ValueAddNoQty,@NewDesi,@ProductSizeId,@StorageId,@CartTimeOut,@Return
	
      FETCH NEXT FROM c_cursor INTO @ProdId,@PriceId,@Qty,@Description,@Attributes,@ValueAdd,@ValueAddNoQty,@NewDesi,@ProductSizeId,@CartTimeOut,@StorageId
   END
   
   CLOSE c_cursor
   DEALLOCATE c_cursor
   
DELETE FROM ShoppingCart
WHERE CartId = @OriginalCartId and ShoppingCartDefId=0 and CartId<> @NewCartId   
--exec ShoppingCartEmpty @OriginalCartId,0
 
GO

  
/****** Object:  StoredProcedure [dbo].[ShoppingCartList5]    Script Date: 1.9.2015 15:22:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[ShoppingCartList5]
(
    @CartId nvarchar(50),
    @ShoppingCartDefId int,
    @StokIndirim int,
    @StokIskActive bit,
    @CampainId int
)
AS
if @CampainId>0
Begin
SELECT   DISTINCT   dbo.ShoppingCart.RecordId,dbo.ShoppingCart.CartTimeOut,dbo.ShoppingCart.CartId, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.StockQty, 
                      dbo.ProductKdvs.KdvRate,ProductUnits.UnitId, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.Carpan, 
                     '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.ShoppingCart.Qty, dbo.ProductUnits.Agirlik, dbo.ProductUnits.Hacim, dbo.Products.Provider, Currencys_2.CurrencyName, Currencys_2.Rate,dbo.ProductUnits.Desi,ProductMarks.MarKName,Products.StockQty -(dbo.ProductUnits.Carpan*dbo.ShoppingCart.Qty) as Kalan,Products.Url,Path,dbo.ShoppingCart.Description,dbo.ShoppingCart.Attributes,dbo.ShoppingCart.ValueAdd,dbo.ShoppingCart.ValueAddNoQty,dbo.ShoppingCart.NewDesi
                      , Currencys.Rate AS Rate0, ProductUnits.SatisFiyati0,Products.ForceCargo,ProductUnits.AlisFiyati,ProductUnits.Barcode,ProductSizes.Barcode as ProductSizeBarcode
FROM         dbo.Currencys Currencys_2 INNER JOIN
                      dbo.ProductUnits ON Currencys_2.CurrencyId =  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.ProductUnits.Pb1 
                      INNER JOIN
                      dbo.Products INNER JOIN
                      dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId INNER JOIN
                      dbo.ShoppingCart ON dbo.Products.ProductId = dbo.ShoppingCart.ProdId 
                        ON dbo.ProductUnits.UnitId = dbo.ShoppingCart.PriceId
                        inner join ProductImages on Products.ProductId=ProductImages.ProductId  LEFT OUTER JOIN
                      Currencys ON ProductUnits.Pb0 = Currencys.CurrencyId
					  LEFT OUTER JOIN dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId
                      LEFT OUTER JOIN ProductSizes on ShoppingCart.ProductSizeId=ProductSizes.ProductSizeId
WHERE    (ProductImages.IsDefault=1) and
 (dbo.Products.IsActive = 1) AND 
(dbo.Products.IsDeleted = 0) AND 
(dbo.Products.StockQty > 0 or dbo.Products.SellNoneStock =1 ) AND 
(dbo.ProductUnits.IsActive = 1) AND
(dbo.ShoppingCart.ShoppingCartDefId =@ShoppingCartDefId) AND
(dbo.ShoppingCart.CartId = @CartId) AND (Products.CampainId=@CampainId )
end
else if @CampainId=0
Begin
SELECT   DISTINCT   dbo.ShoppingCart.RecordId,dbo.ShoppingCart.CartTimeOut,dbo.ShoppingCart.CartId, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.StockQty, 
                      dbo.ProductKdvs.KdvRate,ProductUnits.UnitId, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.Carpan, 
                     '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.ShoppingCart.Qty, dbo.ProductUnits.Agirlik, dbo.ProductUnits.Hacim, dbo.Products.Provider, Currencys_2.CurrencyName, Currencys_2.Rate,dbo.ProductUnits.Desi,ProductMarks.MarKName,Products.StockQty -(dbo.ProductUnits.Carpan*dbo.ShoppingCart.Qty) as Kalan,Products.Url,isnull((select Path from ProductImages as p2 where p2.ImageId=ProductSizes.ProductImageId ),Path) as 'Path',dbo.ShoppingCart.Description,dbo.ShoppingCart.Attributes,dbo.ShoppingCart.ValueAdd,dbo.ShoppingCart.ValueAddNoQty,dbo.ShoppingCart.NewDesi
                      , Currencys.Rate AS Rate0, ProductUnits.SatisFiyati0,Products.ForceCargo,ProductUnits.AlisFiyati,ProductUnits.Barcode,ProductSizes.Barcode as ProductSizeBarcode
FROM         dbo.Currencys Currencys_2 INNER JOIN
                      dbo.ProductUnits ON Currencys_2.CurrencyId =  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.ProductUnits.Pb1 
                      INNER JOIN
                      dbo.Products INNER JOIN
                      dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId INNER JOIN
                      dbo.ShoppingCart ON dbo.Products.ProductId = dbo.ShoppingCart.ProdId ON dbo.ProductUnits.UnitId = dbo.ShoppingCart.PriceId inner join 
                      ProductImages on Products.ProductId=ProductImages.ProductId  LEFT OUTER JOIN
                       FCampains ON Products.CampainId = FCampains.FCampainId LEFT OUTER JOIN
                      Currencys ON ProductUnits.Pb0 = Currencys.CurrencyId  LEFT OUTER JOIN
                      dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId
                      LEFT OUTER JOIN ProductSizes on ShoppingCart.ProductSizeId=ProductSizes.ProductSizeId
WHERE    (ProductImages.IsDefault=1) and
 (dbo.Products.IsActive = 1) AND 
(dbo.Products.IsDeleted = 0) AND 
(dbo.Products.StockQty > 0 or dbo.Products.SellNoneStock =1 ) AND 
(dbo.ProductUnits.IsActive = 1) AND
(dbo.ShoppingCart.ShoppingCartDefId =@ShoppingCartDefId) AND
(dbo.ShoppingCart.CartId = @CartId ) AND 
((ISNULL(FCampains.FCampainId, 0) = 0) or (FCampains.IsActive=0) or (FCampains.StartDate > getdate()) or (FCampains.EndDate < Getdate()) )
end
else
Begin
SELECT   DISTINCT   dbo.ShoppingCart.RecordId,dbo.ShoppingCart.CartId, dbo.Products.ProductId, dbo.Products.ProductCode, dbo.Products.ProductName, dbo.Products.StockQty, 
                      dbo.ProductKdvs.KdvRate,ProductUnits.UnitId, dbo.ProductUnits.BirimAdi, dbo.ProductUnits.Carpan, 
                     '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.ShoppingCart.Qty, dbo.ProductUnits.Agirlik, dbo.ProductUnits.Hacim, dbo.Products.Provider, Currencys_2.CurrencyName, Currencys_2.Rate,dbo.ProductUnits.Desi,ProductMarks.MarKName,Products.StockQty -(dbo.ProductUnits.Carpan*dbo.ShoppingCart.Qty) as Kalan,Products.Url,isnull((select Path from ProductImages as p2 where p2.ImageId=ProductSizes.ProductImageId ),Path) as 'Path',dbo.ShoppingCart.Description,dbo.ShoppingCart.Attributes,dbo.ShoppingCart.ValueAdd,dbo.ShoppingCart.ValueAddNoQty,dbo.ShoppingCart.NewDesi
                      , Currencys.Rate AS Rate0, ProductUnits.SatisFiyati0,Products.ForceCargo,ProductUnits.AlisFiyati,ProductUnits.Barcode,ProductSizes.Barcode as ProductSizeBarcode
FROM         dbo.Currencys Currencys_2 INNER JOIN
                      dbo.ProductUnits ON Currencys_2.CurrencyId =  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.ProductUnits.Pb1 
                      INNER JOIN
                      dbo.Products INNER JOIN
                      dbo.ProductKdvs ON dbo.Products.KdvId = dbo.ProductKdvs.KdvId INNER JOIN
                      dbo.ShoppingCart ON dbo.Products.ProductId = dbo.ShoppingCart.ProdId ON dbo.ProductUnits.UnitId = dbo.ShoppingCart.PriceId  inner join 
                      ProductImages on Products.ProductId=ProductImages.ProductId  LEFT OUTER JOIN
                      FCampains ON Products.CampainId = FCampains.FCampainId LEFT OUTER JOIN
                      Currencys ON ProductUnits.Pb0 = Currencys.CurrencyId
					  LEFT OUTER JOIN dbo.ProductMarks ON dbo.Products.MarkId = dbo.ProductMarks.MarkId
					  LEFT OUTER JOIN ProductSizes on ShoppingCart.ProductSizeId=ProductSizes.ProductSizeId
WHERE    (ProductImages.IsDefault=1) and
 (dbo.Products.IsActive = 1) AND 
(dbo.Products.IsDeleted = 0) AND 
(dbo.Products.StockQty > 0 or dbo.Products.SellNoneStock =1 ) AND 
(dbo.ProductUnits.IsActive = 1) AND
(dbo.ShoppingCart.ShoppingCartDefId =@ShoppingCartDefId) AND
(dbo.ShoppingCart.CartId = @CartId ) 
--and((ISNULL(FCampains.FCampainId, 0) = 0) or (FCampains.IsActive=0) or (FCampains.StartDate > getdate()) or (FCampains.Enddate < Getdate()) )
end

GO


/****** Object:  View [dbo].[AdminProductListAll2]    Script Date: 10.9.2015 10:33:40 ******/
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, 
                         dbo.Products.CompanyId
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].[AdminProductListAll2]    Script Date: 17.9.2015 16:10:32 ******/
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, 
                         dbo.Products.CompanyId
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].[OrdersListDetails]    Script Date: 17.9.2015 16:10:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER VIEW [dbo].[OrdersListDetails]
AS
SELECT        dbo.users.FullName, dbo.users.Email, dbo.OrderDetails.OrderDetailsId, dbo.OrderDetails.ProductId, dbo.OrderDetails.ProductCode, dbo.OrderDetails.ProductName, dbo.OrderDetails.BirimAdi, 
                         dbo.OrderDetails.Carpan, dbo.OrderDetails.KdvRate, dbo.OrderDetails.SatisFiyati, dbo.OrderDetails.Pb1, dbo.OrderDetails.Rate, dbo.OrderDetails.BirimIndirimOrani, dbo.OrderDetails.CariIndirimOrani, 
                         dbo.OrderDetails.AlisFiyati, dbo.OrderDetails.APb, dbo.OrderDetails.AlisRate, dbo.OrderDetails.Quantity, dbo.Orders.Status, dbo.OrderDetails.Status AS Status2, OrderStatus.StatusName, 
                         OrderStatus2.StatusName AS StatusName2, dbo.OrderDetails.WillSendMessage, dbo.OrderDetails.Provider, dbo.OrderDetails.MarkName, dbo.OrderDetails.Description, Providers_1.ProviderId, 
                         Providers_1.ProviderName, dbo.Providers.ProviderId AS XmlProviderId, dbo.Providers.ProviderName AS XmlProviderName, dbo.Currencys.CurrencyName, dbo.Orders.OrderId, dbo.Orders.PortalId, 
                         dbo.Orders.CustomerId, dbo.Orders.OrderDate, dbo.Orders.ShipDate, dbo.Orders.IsPayed, dbo.Orders.PaymentType, dbo.Orders.Note, dbo.Orders.ShippingName, dbo.Orders.ShippingPhoneNo, 
                         dbo.Orders.ShippingMobilePhone, dbo.Orders.ShippingCityName, dbo.Orders.ShippingAddress, dbo.Orders.ShippingCargoName, dbo.Orders.BillingName, dbo.Orders.BillingTaxOffice, dbo.Orders.BillingTaxNo, 
                         dbo.Orders.BillingCityName, dbo.Orders.BillingAddress, dbo.Orders.ToplamTutar, dbo.Orders.KdvDahilToplam, dbo.Orders.ToplamKdv, dbo.Orders.ToplamKargo, dbo.Orders.KargoDahilToplamTutar, 
                         dbo.Orders.ToplamIndirim, dbo.Orders.CekIndirimi, dbo.Orders.ToplamAgirlik, dbo.Orders.ToplamHacim, dbo.Orders.ToplamDesi, dbo.Orders.BankName, dbo.Orders.CardName, dbo.Orders.Taksit, 
                         dbo.Orders.BankaToplamTutar, dbo.Orders.BankPayType, dbo.Orders.Integreted, dbo.Orders.Aciklama, dbo.OrderDetails.UserId, dbo.OrderDetails.ProductSizeBarcode, dbo.OrderDetails.ProductBarcode, 
                         dbo.Orders.OrderCode, dbo.Orders.CurrencyRate, dbo.Orders.CurrencyCode, dbo.Orders.CustomerCurrencyRate, dbo.Orders.CustomerCurrencyCode, dbo.Orders.TaksitRate, dbo.OrderDetails.ProductSizeId
FROM            dbo.Orders INNER JOIN
                         dbo.OrderDetails ON dbo.Orders.OrderId = dbo.OrderDetails.OrderId INNER JOIN
                         dbo.Currencys ON dbo.OrderDetails.Pb1 = dbo.Currencys.CurrencyId LEFT OUTER JOIN
                         dbo.Providers ON dbo.OrderDetails.XmlProviderId = dbo.Providers.ProviderId LEFT OUTER JOIN
                         dbo.Providers AS Providers_1 ON dbo.OrderDetails.ProviderId = Providers_1.ProviderId LEFT OUTER JOIN
                         dbo.OrderStatus AS OrderStatus2 ON dbo.OrderDetails.Status = OrderStatus2.StatusId LEFT OUTER JOIN
                         dbo.users ON dbo.Orders.CustomerId = dbo.users.UserId LEFT OUTER JOIN
                         dbo.OrderStatus AS OrderStatus ON dbo.Orders.Status = OrderStatus.StatusId

GO




UPDATE Portals Set Version='3.2.1'
 
GO

