if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventSignUpQuestionOptions' and column_name = 'capacity')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventSignUpQuestionOptions] add capacity int not null default 0
 end
GO


alter procedure {databaseOwner}{objectQualifier}usp_insertEventSignUpQuestionOption
(
 @signUpQuestionId int,
 @name nvarchar(255),
 @sortOrder int,
 @priceAdjustment money,
 @capacity int
)

as

set nocount on
  
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventSignUpQuestionOptions] (signUpQuestionId,name,sortOrder,priceAdjustment,capacity)

	values (@signUpQuestionId,@name,@sortOrder,@priceAdjustment,@capacity)
			
	return

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_NaDevEvent_GetAllEventSignUpQuestionSingleOption]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_NaDevEvent_GetAllEventSignUpQuestionSingleOption
GO

create procedure {databaseOwner}{objectQualifier}usp_NaDevEvent_GetAllEventSignUpQuestionSingleOption
(
@SignUpQuestionOptionId int
)
as

set nocount on

select * from {databaseOwner}[{objectQualifier}tblNaDevEventSignUpQuestionOptions]
where SignUpQuestionOptionId = @SignUpQuestionOptionId

GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsUsersSignedUpToEvent' and column_name = 'BookingSurcharge')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] add BookingSurcharge money not null default 0
 end
GO

alter procedure {databaseOwner}{objectQualifier}usp_UpdateUserSignUpToEvent
(
 @bookingId int,
 @eventId int,
 @moduleId int,
 @userId int,
 @eventStartDate datetime,
 @eventEndDate datetime,
 @additionalInformation ntext,
 @billingAddressId int,
 @numberOfPlaces int,
 @dateBookingMade datetime,
 @paymentStatusId int,
 @tabModuleId int,
 @userSignUpAnswers ntext,
 @totalCost money,
 @numberOfChildPlaces int,
 @discountAmount money,
 @couponCode nvarchar(50),
 @tax money,
 @sentRemindEmail bit,
 @numberOfAttendeesString nvarchar(max),
 @isWaitList bit,
 @BookingSurcharge money
)

as

set nocount on
  
update {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] set   eventId = @eventId,
																				  eventStartDate = @eventStartDate,
																				  eventEndDate = @eventEndDate,
																				  additionalInformation = @additionalInformation,
																				  billingAddressId = @billingAddressId,
																				  numberOfPlaces = @numberOfPlaces,
																				  userId=@userId,
																				  moduleId =@moduleId,
																				  dateBookingMade = @dateBookingMade,
																				  paymentStatusId = @paymentStatusId,
																				  tabModuleId = @tabModuleId,
																				  userSignUpAnswers = @userSignUpAnswers,
																				  totalCost = @totalCost,
																				  numberOfChildPlaces = @numberOfChildPlaces,
																				  discountAmount =@discountAmount,
																				  couponcode = @couponcode,
																				  tax =@tax,
																				  sentRemindEmail =@sentRemindEmail,
																				  numberOfAttendeesString =@numberOfAttendeesString,
																				  isWaitList = @isWaitList,
																				  BookingSurcharge = @BookingSurcharge		 												 
									 
																				  where bookingId = @bookingId												

GO

if not exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}tblNaDevEventsBookingGuest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 begin

	CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEventsBookingGuest](
		[GuestId] [int] IDENTITY(1,1) NOT NULL,
		[bookingId] [int] NOT NULL,
		[addressId] [int] not null,
		[SignUpQuestions] [nvarchar] (max) null
	 CONSTRAINT [PK_{objectQualifier}tblNaDevEventsBookingGuest] PRIMARY KEY CLUSTERED 
	(
		[GuestId] ASC
	)
	)
 end
GO

if not exists (SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_{objectQualifier}tblNaDevEventsBookingGuest_tblNaDevEventsUsersSignedUpToEvent')

ALTER TABLE {databaseOwner}[{objectQualifier}tblNaDevEventsBookingGuest]  WITH CHECK ADD  CONSTRAINT [FK_{objectQualifier}tblNaDevEventsBookingGuest_tblNaDevEventsUsersSignedUpToEvent] FOREIGN KEY([bookingId])
REFERENCES {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] ([bookingId])
ON DELETE CASCADE

GO