CREATE PROCEDURE [dbo].[OnlineFindHotelsetupSearchChain]  @IsChainHotel BIT, @HotelChainnumber INT  AS
SET NOCOUNT ON
/*
    Created by Troels Buch Juni 2005
    
    Changes:
	TBU:20150529: Added markasdeleted=0
    TB20140813: Added MailAddresses - 8.1+
	LJE20120622: Always read SeCvrNumber, Phone, ... from Customer.
	LJE20120105: Added RestaurantPhone - for "IsChainHotel" Phone and RestaurantPhone is identical.
	TB20071114: Added HotelCustomerNumber
   	TB20050629: Added Phone and email
	TB20050615:  Added UseProducttypes to #HotelSetupSearchChain - UseProducttypes tells if producttypes is used to find online product availability
	TB20050615:  Added NOLOCK to select
	
    NOTES: 	- 
*/



--DECLARE @PicassoOnlineUseCheapProductKey VARCHAR(50)
DECLARE @SeCvrNumber  VARCHAR(50)
DECLARE @UseProductTypes BIT
DECLARE @Phone VARCHAR (50)
DECLARE @RestaurantPhone VARCHAR (50)
DECLARE @Email VARCHAR (100)
DECLARE @HotelCustomerNumber INT
DECLARE @OnlineHotelMailDomino VARCHAR (100)

SET @UseProductTypes = 0

 -- Copy from GenerateAvailability SP
  CREATE TABLE #HotelSetupSearchChain (		
		[SeCvrNumber] [VARCHAR] (50) NULL,
		[UseProducttypes] [BIT]  NULL,
		[Phone] [VARCHAR] (50) NULL,
		[RestaurantPhone] [VARCHAR] (50) NULL,				
		[Email] [VARCHAR] (100)	 NULL,
		[HotelCustomerNumber] INT NULL,
		[OnlineHotelMailDomino] VARCHAR (100) NULL
		)

   SELECT @SeCvrNumber = CompanyNumber FROM Customer WITH (NOLOCK) WHERE CustomerTypeNumber = 7 AND Hotelnumber = @HotelChainnumber and markasdeleted=0
   SELECT @Phone = Phonenumber FROM Customer WITH (NOLOCK) WHERE CustomerTypeNumber = 7 AND Hotelnumber = @HotelChainnumber and markasdeleted=0
   SELECT @RestaurantPhone = Phonenumber FROM Customer (NOLOCK) WHERE CustomerTypeNumber = 7 AND Hotelnumber = @HotelChainnumber and markasdeleted=0
   --SELECT @Email = Email FROM Customer WITH (NOLOCK) WHERE CustomerTypeNumber = 7 AND Hotelnumber = @HotelChainnumber   
   
   SELECT @Email = MailAddress FROM Customer WITH (NOLOCK)    
   INNER JOIN MailAddresses WITH (NOLOCK) ON MailAddresses.CustomerNumber = Customer.CustomerNumber AND MailAddresses.MailAddressType = 0
   AND Customer.CustomerTypeNumber = 7 and HotelNumber = @HotelChainnumber and markasdeleted=0
   
   SELECT @HotelCustomerNumber = CustomerNumber FROM Customer WITH (NOLOCK) WHERE CustomerTypenumber = 7 and HotelNumber = @HotelChainnumber and markasdeleted=0
   EXEC @OnlineHotelMailDomino = GetHotelSetupKeyValue 'PicassoOnlineHotelMail', @HotelCustomerNumber
	--print 'tb'
	--print @Phone
	--print  @Email

SELECT @UseProductTypes =  keyvalue FROM Hotelsetup WITH (NOLOCK) WHERE Searchkey = 'PicassoOnlineUseProductTypes'


INSERT INTO  #HotelSetupSearchChain (SeCvrNumber, UseProducttypes, Phone, RestaurantPhone
  , Email, HotelCustomerNumber, OnlineHotelMailDomino) 
VALUES (@SeCvrNumber, @UseProductTypes, @Phone, @RestaurantPhone
  , @Email, @HotelCustomerNumber, @OnlineHotelMailDomino)

-----------------------------------------------------------------------------------------------------
SELECT * FROM #HotelSetupSearchChain WITH (NOLOCK)
-----------------------------------------------------------------------------------------------------

DROP TABLE #HotelSetupSearchChain


