<!--#include virtual="../includes/sessionvariables.asp" -->
<!--#include virtual="../includes/pagefunctions.asp" -->
<!--#include file="../includes/dbfunctions.asp"--> 
<!--#include file="../includes/Cartfunctions.asp"--> 
<%
Dim tmpArray, itemArray, transArray, Itinerary_ID, User_ID, SQLTrans, SQLUser, SQLEntity, Entity, Guest
Dim HTML, Text, Header, Body, Footer, RepHeader, Body_Header, Body_Detail_Desc, Body_Detail_Dates, SQLItems
Dim RepBodyHeader, RepBodyDates, i, RepBodyDatesBlank, SQLItemID, Nightly_Total
Itinerary_ID = Request.QueryString("Itinerary_ID")
Set RSUser = Server.CreateObject("ADODB.Recordset")
Set RSTrans = Server.CreateObject("ADODB.Recordset")
Set RSEntity = Server.CreateObject("ADODB.Recordset")

Nightly_Total = 0

SQLEntity = "Get_Entity_Detail_From_Itin '" & Itinerary_ID & "'"
RSEntity.Open SQLEntity, Conn

SQLTrans = "Select * From Transactions Where Itinerary_ID = '" & Itinerary_ID & "'"
RSTrans.Open SQLTrans, Conn

User_ID = RSTrans("Contact_ID")

SQLUser = "Select CD.Name_First, CD.Name_Last from Contact_Detail CD Inner Join Users U On U.Contact_ID=CD.Contact_ID Where U.User_ID = '" & User_ID & "'"
'Response.Write SQLUser
RSUser.Open SQLUser, Conn

Guest = RSUser("Name_First") & " " & RSUser("Name_Last")

RSEntity.MoveFirst()
Do while not RSEntity.EOF
i=0

HTML = ""
set Text = Server.CreateObject("Scripting.FileSystemObject")
Set Header = Text.OpenTextFile("d:\web sites\vacation-in-florida\documents\resi-header.htm", 1, False, 0)
Set Body_Header_tmp = Text.OpenTextFile("d:\web sites\vacation-in-florida\documents\resi-body-header.htm", 1, False, 0)
Set Body_Detail_Desc_tmp = Text.OpenTextFile("d:\web sites\vacation-in-florida\documents\resi-body-detail-desc.htm", 1, False, 0)
Set Body_Detail_Dates_tmp = Text.OpenTextFile("d:\web sites\vacation-in-florida\documents\resi-body-detail-dates.htm", 1, False, 0)
Set Footer = Text.OpenTextFile("d:\web sites\vacation-in-florida\documents\resi-footer.htm", 1, False, 0)
RepHeader = Header.ReadAll
Body_Header = Body_Header_tmp.ReadAll
Body_Detail_Desc = Body_Detail_Desc_tmp.ReadAll
Body_Detail_Dates = Body_Detail_Dates_tmp.ReadAll

Entity = RSEntity("Name") & "<br>" & RSEntity("Address_1") & "<br>" & _
	RSEntity("City") & ", " & RSEntity("State") & " " & RSEntity("Zip")

RepHeader = Replace(RepHeader, "{Entity_Name}", Entity)
RepHeader = Replace(RepHeader, "{Guest}", Guest)
RepHeader = Replace(RepHeader, "{Itinerary_ID}", Itinerary_ID)

Set RSDirect = server.CreateObject("ADODB.Recordset")
SQLDirect = "Get_Attribute_Values @GroupID='" & RSEntity("Group_ID") & "', @Att_ID = '607'"
RSDirect.Open SQLDirect, Conn

If Not RSDirect.EOF Then
RepHeader = Replace(RepHeader, "{Direct_Bill}", Itinerary_ID)
Else
RepHeader = Replace(RepHeader, "{Direct_Bill}", "N/A")
End If
RSDirect.Close()

Set RSItemID = Server.CreateObject("ADODB.Recordset")
SQLItemID = "Get_Itin_Item_ID_By_Entity '" & Itinerary_ID & "', '" & RSEntity("Group_ID") & "'"
RSItemID.Open SQLItemID, Conn


'Response.Write RepHeader

'Response.Write Entity
HTML = HTML & RepHeader
Do While Not RSItemID.EOF
i=0
SQLItems = "Get_Itin_Items_By_Entity '" & Itinerary_ID & "', '" & RSEntity("Group_ID") & "', '" & RSItemID("Item_ID") & "'"
'Response.Write SQLItems
Set RSItems = Server.CreateObject("ADODB.Recordset")
RSItems.Open SQLItems, Conn
RepBodyHeader = Replace(Body_Header, "{Nights}", RSItems("Stay"))
RepBodyHeader = Replace(RepBodyHeader, "{Adults}", RSItems("AdultCount"))
RepBodyHeader = Replace(RepBodyHeader, "{Children}", Int(RSItems("Guest_Count"))-Int(RSItems("AdultCount")))

If IsNumeric(RSItems("Special_Request")) Or IsNull(RSItems("Special_Request")) Then
RepBodyHeader = Replace(RepBodyHeader, "{Special_Request}", "None")
Else
RepBodyHeader = Replace(RepBodyHeader, "{Special_Request}", RSItems("Special_Request"))
End If

RepBodyHeader = Replace(RepBodyHeader, "{Room_Type}", RSItemID("Name"))
If Not RSItems("Smoking") Then
RepBodyHeader = Replace(RepBodyHeader, "{Smoking}", "No")
ElseIf RSItems("Smoking") Then
RepBodyHeader = Replace(RepBodyHeader, "{Smoking}", "Yes")
End If

Set RSTickets = server.CreateObject("ADODB.Recordset")
SQLTickets = "CheckForTickets '" & Itinerary_ID & "'"
RSTickets.Open SQLTickets, Conn

If RSTickets("Tickets") = 1 Then
RepBodyHeader = Replace(RepBodyHeader, "{Tickets}", "Yes")
Else
RepBodyHeader = Replace(RepBodyHeader, "{Tickets}", "No")
End If
RSTickets.Close()

HTML = HTML & "<br>" & RepBodyHeader & "<table width=""575"" border=""0"" cellspacing=""0"" cellpadding=""0"" bgcolor=""#FFFFFF""><tr>"
HTML = HTML & "<td align=left>" & Body_Detail_Desc & "</td>"
Do While Not RSItems.EOF
If i = 7 Then
HTML = HTML & "</tr><tr><td align=left>" & Body_Detail_Desc & "</td>"
i = 0
End If
RepBodyDates = Body_Detail_Dates



RepBodyDates = Replace(RepBodyDates, "{Date}", Month(RSItems("Date")) & "/" & Day(RSItems("Date")) & "/" & Right(Year(RSItems("Date")), 2))
RepBodyDates = Replace(RepBodyDates, "{Net_Rate}", FormatCurrency(RSItems("Unit_Price"), 2))

Nightly_Total = Nightly_Total + RSItems("Unit_Price")


If RSItems("Extra_Adult") > 0 Then
Set RSCost = Server.CreateObject("ADODB.Recordset")
SQLCost = "[Avante].[dbo].[Get_Extra_Adult] @Entity_ID = '" & RSItemID("Item_ID") & "', @Desc = 'Web'"
RSCost.Open SQLCost, Conn

If Not RSCost.EOF Then
RepBodyDates = Replace(RepBodyDates, "{Extra_Adult}", FormatCurrency((Int(RSCost("Display_Price")) * Int(RSItems("Extra_Adult"))), 2))
Nightly_Total = Nightly_Total + (Int(RSCost("Display_Price")) * Int(RSItems("Extra_Adult")))
End If
RSRoll.Close()
Else
RepBodyDates = Replace(RepBodyDates, "{Extra_Adult}", FormatCurrency(0, 2))
End If

If RSItems("Rollaway") Then
Set RSRoll = Server.CreateObject("ADODB.Recordset")
SQLRoll = "Get_Rollaway_ILL '" & RSItems("Inventory_List_ID") & "'"
RSRoll.Open SQLRoll, Conn

If Not RSRoll.EOF Then
RepBodyDates = Replace(RepBodyDates, "{Rollaway}", FormatCurrency(Int(RSRoll("Display_Price")), 2))
Nightly_Total = Nightly_Total + Int(RSRoll("Display_Price"))
End If
RSRoll.Close()
Else
RepBodyDates = Replace(RepBodyDates, "{Rollaway}", FormatCurrency(0, 2))
End If

	Set RSTax = Server.CreateObject("ADODB.Recordset")
			SQLTax = "Get_Tax_Costs_Lodging '" & RSItems("Inventory_List_ID") & "', '" & CCur(RSItems("Unit_Price")) & "'"
			RSTax.Open SQLTax, Conn
RepBodyDates = Replace(RepBodyDates, "{Taxes}", FormatCurrency(RSTax("Total_Tax"), 2))
Nightly_Total = Nightly_Total + RSTax("Total_Tax")
			RSTax.Close()

RepBodyDates = Replace(RepBodyDates, "{Nightly_Total}", FormatCurrency(Nightly_Total, 2))
HTML = HTML & "<td align=left>" & RepBodyDates & "</td>"
RSItems.MoveNext()
i = i + 1

Loop
If i < 7 Then
RepBodyDatesBlank = Body_Detail_Dates
RepBodyDatesBlank = Replace(RepBodyDatesBlank, "{Date}", "&nbsp;")
RepBodyDatesBlank = Replace(RepBodyDatesBlank, "{Net_Rate}", "&nbsp;")
RepBodyDatesBlank = Replace(RepBodyDatesBlank, "{Extra_Adult}", "&nbsp;")
RepBodyDatesBlank = Replace(RepBodyDatesBlank, "{Rollaway}", "&nbsp;")
RepBodyDatesBlank = Replace(RepBodyDatesBlank, "{Taxes}", "&nbsp;")
RepBodyDatesBlank = Replace(RepBodyDatesBlank, "{Nightly_Total}", "&nbsp;")
For j = 1 to (7 - i)
HTML = HTML & "<td align=left>" & RepBodyDatesBlank & "</td>"
Next
End If
HTML = HTML & "</td></tr></table>"
RSItemID.MoveNext()
Loop
HTML = HTML & Footer.ReadAll

Response.Write HTML

    Dim myMail
    Set myMail = Server.CreateObject("CDONTS.NewMail")

    myMail.Subject="Vacation In Florida Reservation Receipt"

      myMail.From="test@vacationinflorida.com"
      myMail.Body=HTML
      myMail.BodyFormat=0
      myMail.MailFormat=0
      myMail.To = "shadow@empnet.com"
	myMail.Bcc = "caryl@lancair.com"
    'myMail.Send
    set mymail=nothing
    RSEntity.MoveNext()
    
Loop

'Response.Write "Sent" & "<br>"


%>