update pal_SurfaceField
set sequence = 1, gridSequence = 1
where surfaceFieldName = 'OrderCalculationsandProducts_WholesalerProductOrder';

  
update pal_SurfaceField
set sequence = 3, gridSequence = 2
where surfaceFieldName = 'OrderCalculationsandProducts_OrderCalculations';

if((select count(*) from dbo.pal_SurfaceField where surfaceFieldName = 'OrderCalculationsandProducts_UserGuides') = 0)
begin
INSERT INTO [dbo].[pal_SurfaceField]
           ([surfaceId]
           ,[surfaceFieldName]
           ,[surfaceFieldDisplay]
           ,[surfaceFieldTypeId]
           ,[length]
           ,[required]
           ,[lookupCategory]
           ,[relationalFields]
           ,[relationalValues]
           ,[relationalOrderBy]
           ,[relationalSurface]
           ,[relationalObject]
           ,[parentId]
           ,[sequence]
           ,[isActive]
           ,[isGrid]
           ,[isFilter]
           ,[colSequence]
           ,[contentId]
           ,[defaultToCurrent]
           ,[isControlled]
           ,[controlledValue]
           ,[controlText]
           ,[isAutoPostback]
           ,[isHidden]
           ,[isReadOnly]
           ,[placeholder]
           ,[isUnique]
           ,[actionType]
           ,[action]
           ,[actionSource]
           ,[isComparable]
           ,[alternateView]
           ,[isHiddenFromWizzard]
           ,[surfaceDateTypeId]
           ,[isHiddenFromView]
           ,[actionValue]
           ,[surfaceFieldSize]
           ,[isLabelHidden]
           ,[isOnNewLine]
           ,[labelSize]
           ,[isHiddenFromForm]
           ,[accessLevel]
           ,[hasBottomBorder]
           ,[hasFullBorder]
           ,[defaultValue]
           ,[validationType]
           ,[enableBulkUpdate]
           ,[isCurrency]
           ,[isVerticalHeader]
           ,[gridSequence]
           ,[isGrouped]
           ,[isCloneable]
           ,[isCustomSource]
           ,[relationalWhere]
           ,[groupedDisplayCount])
     VALUES
           (3094
           ,'OrderCalculationsandProducts_UserGuides'
           ,'User Guides'
           ,2
           ,0
           ,0
           ,0
           ,''
           ,''
           ,''
           ,''
           ,''
           ,1728
           ,4
           ,1
           ,0
           ,0
           ,0
           ,0
           ,0
           ,1
           ,''
           ,''
           ,0
           ,0
           ,0
           ,''
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,''
           ,6
           ,0
           ,0
           ,4
           ,0
           ,1
           ,0
           ,0
           ,''
           ,0
           ,0
           ,0
           ,0
           ,3
           ,0
           ,0
           ,0
           ,''
           ,0);
end;

if((select count(*) from dbo.pal_Content where title = 'Order Process User Guide') = 0)
begin
INSERT INTO [dbo].[pal_Content]
           ([title]
           ,[contentHTML]
           ,[dateCreated]
           ,[dateUpdated]
           ,[isActive]
           ,[sequence]
           ,[isFeatured])
     VALUES
           ('Order Process User Guide'
           ,'<img alt="" src="/upload/image/Retailer_User_Guide.png" /><span style="white-space: pre;">	<img alt="" src="/upload/image/Wholesaler_User_Guide.png" /></span>'
           ,GETDATE()
           ,GETDATE()
           ,1
           ,0
           ,0);
end;

if((select count(*) from dbo.pal_SurfaceField where surfaceFieldName = 'OrderCalculationsandProducts_UserGuides_OrderProcessUserGuide') = 0)
begin
INSERT INTO [dbo].[pal_SurfaceField]
           ([surfaceId]
           ,[surfaceFieldName]
           ,[surfaceFieldDisplay]
           ,[surfaceFieldTypeId]
           ,[length]
           ,[required]
           ,[lookupCategory]
           ,[relationalFields]
           ,[relationalValues]
           ,[relationalOrderBy]
           ,[relationalSurface]
           ,[relationalObject]
           ,[parentId]
           ,[sequence]
           ,[isActive]
           ,[isGrid]
           ,[isFilter]
           ,[colSequence]
           ,[contentId]
           ,[defaultToCurrent]
           ,[isControlled]
           ,[controlledValue]
           ,[controlText]
           ,[isAutoPostback]
           ,[isHidden]
           ,[isReadOnly]
           ,[placeholder]
           ,[isUnique]
           ,[actionType]
           ,[action]
           ,[actionSource]
           ,[isComparable]
           ,[alternateView]
           ,[isHiddenFromWizzard]
           ,[surfaceDateTypeId]
           ,[isHiddenFromView]
           ,[actionValue]
           ,[surfaceFieldSize]
           ,[isLabelHidden]
           ,[isOnNewLine]
           ,[labelSize]
           ,[isHiddenFromForm]
           ,[accessLevel]
           ,[hasBottomBorder]
           ,[hasFullBorder]
           ,[defaultValue]
           ,[validationType]
           ,[enableBulkUpdate]
           ,[isCurrency]
           ,[isVerticalHeader]
           ,[gridSequence]
           ,[isGrouped]
           ,[isCloneable]
           ,[isCustomSource]
           ,[relationalWhere]
           ,[groupedDisplayCount])
     VALUES
           (3094
           ,'OrderCalculationsandProducts_UserGuides_OrderProcessUserGuide'
           ,'Order Process User Guide'
           ,18
           ,0
           ,0
           ,0
           ,''
           ,''
           ,''
           ,''
           ,''
           ,(select recId from pal_SurfaceField where surfaceFieldName = 'OrderCalculationsandProducts_UserGuides')
           ,1
           ,1
           ,0
           ,0
           ,0
           ,(select recId from pal_Content where title = 'Order Process User Guide')
           ,0
           ,0
           ,''
           ,''
           ,0
           ,0
           ,0
           ,''
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,0
           ,''
           ,12
           ,1
           ,1
           ,12
           ,0
           ,1
           ,0
           ,0
           ,''
           ,0
           ,0
           ,0
           ,0
           ,1
           ,0
           ,1
           ,0
           ,''
           ,0);
end;

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE
	TABLE_NAME = 'publ_WholesalerOrders' AND
	COLUMN_NAME = 'OrderCalculationsandProducts_UserGuides_OrderProcessUserGuide')
begin

alter  table publ_WholesalerOrders
add OrderCalculationsandProducts_UserGuides_OrderProcessUserGuide varchar(max) NULL;

end;