%
' Copyright (C) 1998-2005 Cyberstrong Internet Services, Inc. All Rights Reserved
'
' This file has been seeded with unique information at point of sale and
' is traceable to its purchaser.
'
' Your license agreement forbids the removal of this notice.
%>
<%
'
' GetShp.asp - Get shipping data
'
Dim i, iPass, iCount, Action, ShipperErrorMsg, rs, sql
Dim Selected, SelectedItem, CustomerID, iShipping, iPayment
Dim iTax1, iTax2, iTaxableTotal1, iTaxableTotal2, iSubTotal, iSubTotalForShipping, iGrandTotal, OrderId
Dim iShipUnits, rsOrders, rsOrderDetails, rsPaymentMethod, DateErrorMsg
Dim arySurvey, iSurvey, PaymentMethod, PaymentGateway, PaymentAuthTime, ReturnValue
Dim oShippingRates, GetShippingDDBContent, FirstShippingMethod
Dim pAdvTax, PreviewFieldList
'wl(session ("edit") & "ded")
'wl(session ("Username"))
' GetFieldData() - If the first pass, look up value in the data base,
' for subsequent passes use value when this form was last displayed.
' The field "argDefault" is not used here but is included for compatiblity reasons
Public Function GetFieldData(ByVal argFieldName, ByVal argDefault)
If (iPass = "") Then
' Do this just once, on first call to this routine ...
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM Customers WHERE CustomerID = " & CleanSQL(CustomerID, "i"), Conn, adOpenKeyset, adLockOptimistic
iPass = 1
End If
Select Case iPass
Case 1: GetFieldData = IIF(Request.Form(argFieldName) <> "", stripHTML(Request.Form(argFieldName)), rs(argFieldName))
Case 2: GetFielddata = stripHTML(Request.Form(argFieldName))
End Select
End Function
' Get demo field data ...
Public Function GetDemoFieldData(ByVal FieldName, ByVal DemoData)
If (gblDemoMode) Then
GetDemoFieldData = DemoData
Else
GetDemoFieldData = stripHTML(Request.Form(FieldName))
End If
End Function
' GetShippingMethod() - Get the currently displayed shipping method ...
Public Function GetShippingMethod()
Select Case iPass
Case 1:
GetShippingMethod = FirstShippingMethod
Case 2:
GetShippingMethod = Trim(Request.Form("ShippingMethod"))
' Shipping method may not be available after ship info change, substitute first method ...
If (Not isObject(oShippingRates(GetShippingMethod))) Then
GetShippingMethod = FirstShippingMethod
End If
End Select
End Function
' DisplayPaymentDropDown() - Display dropdown boxes on this page ...
Public Sub DisplayPaymentDropDown(ByVal TableName, ByVal FormFieldName, ByVal ValueField, ByVal DisplayField, ByVal ActiveField, ByVal OrderBy)
Dim rstDropDown
set rstDropDown = Server.CreateObject("ADODB.Recordset")
rstDropDown.Open "SELECT * FROM " & CleanSQL(TableName, "a") & " ORDER BY " & CleanSQL(OrderBy, "a"), Conn, adOpenKeyset, adLockOptimistic
If (iPass = 2) Then
SelectedItem = Request.Form(FormFieldName)
End If
wl("")
' Write JavaScript to fill in CC box with message for those
' gateways that only collect credit card info on their own screens ...
Dim UseGateWay, GatewayFillCCMsg, MsgList
wl("")
wl("")
wl("")
wl("")
rstDropDown.Close
End Sub
' GetShippingDDB() - Returns HTML for shipping drop down menu ...
Public Function GetShippingDDB()
Dim SQL, Key, rsShipMethods, ErrorMsg, Selected
Dim ShippingMethod, ShippingRateList
Dim ws
' Return content from previous call to avoid
' multiple calculation ...
If (GetShippingDDBContent <> "") Then
GetShippingDDB = GetShippingDDBContent
Exit Function
End If
Set ws = New clsWS ' Write string class.
' Select active rates in DDB for user selection ...
SQL = "SELECT * FROM ShippingMethods " & _
"WHERE {fn LCase(ShippingMethodActive)} = 'yes' " & _
"ORDER BY ShippingOrderBy"
Set rsShipMethods = Server.CreateObject("ADODB.Recordset")
rsShipMethods.Open SQL, Conn, adOpenKeyset, adLockOptimistic
ShippingRateList = oShippingRates.Keys
FirstShippingMethod = ""
' Write the DDB for user selection ...
ws("")
rsShipMethods.Close : Set rsShipMethods = Nothing
GetShippingDDB = ws.Gets()
GetShippingDDBContent = GetShippingDDB ' Save content for future call.
End Function
' FormatShippingMethod() - Remove delimiters and dollar amounts from shipping method ...
Public Function FormatShippingMethod(ByVal argShippingMethodText)
FormatShippingMethod = Replace(argShippingMethodText, ",", " ")
End Function
' PaysStateTax() - Returns True if this customer pays state tax, False otherwise.
' - Used in CalcOrderTotals() for standard tax calculations only.
' - Not used with advanced tax add-on.
Public Function PaysStateTax()
Dim State, StateList
PaysStateTax = False
If ((Not cstHideSalesTax) AND (Not cstSuppressShipTo)) Then
StateList = Split(cstHomeState & ",", ",")
For Each State in StateList
If (Trim(State) <> "") Then
If (LCase(Trim(GetFieldData("ShipStateOrProvince", ""))) = LCase(Trim(State))) Then
PaysStateTax = True
End If
End If
Next
End If
End Function
' CalcOrderTotals() - Calculate order totals ...
Public Sub CalcOrderTotals()
Dim iUserTaxableTotal, ShippingMethod, rsShipMethods, rs, SQL
ShippingMethod = GetShippingMethod()
' Get shipping cost and transit time ...
iShipping = 0
iShipping = RoundCurrency(GetShippingCost(oShippingRates, ShippingMethod))
' Pass forward after screen refresh...
Session("40iShipping") = iShipping
Session("40TransitTime") = GetTransitTime(oShippingRates, ShippingMethod)
' Calculate taxes ...
If (Not cstHideSalesTax) Then
If (isInstalled("Feature:Advanced Tax")) Then
' Advanced tax processing ...
Set pAdvTax = FeatureInstalled("Feature:Advanced Tax")
With pAdvTax
If (cstSalesTaxUsesBillToAddress) Then
' Use billing address for tax rule evaluation ...
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM Customers WHERE CustomerID = " & CleanSQL(CustomerID, "i")
rs.Open SQL, Conn, adOpenKeyset, adLockOptimistic
.Country = rs("Country")
.State = rs("StateOrProvince")
.City = rs("City")
.PostalCode = rs("PostalCode")
rs.Close : Set rs = Nothing
Else
' Use shipping address for tax rule evaluation ...
.Country = GetFieldData("ShipCountry", "")
.State = GetFieldData("ShipStateOrProvince", "")
.City = GetFieldData("ShipCity", "")
.PostalCode = GetFieldData("ShipPostalCode", "")
End If
' Remaining advance tax set up ...
.TaxableTotal1 = iTaxableTotal1
.TaxableTotal2 = iTaxableTotal2
.Shipping = iShipping
' Calculate advance taxes ...
.Calculate()
' Recover results ...
iTax1 = RoundCurrency(.Tax1)
iTax2 = RoundCurrency(.Tax2)
End With
Else
' Standard tax processing ...
If (PaysStateTax()) Then
If (UserExit(usrCalcTaxableTotal, Conn, 0, 0, 0, iUserTaxableTotal)) Then
iTax1 = RoundCurrency((iUserTaxableTotal + IIF(cstSalesTaxIncludesShipping, iShipping, 0)) * (cstHomeStateTax / 100.0))
iTax2 = 0
Else
iTax1 = RoundCurrency((iTaxableTotal1 + IIF(cstSalesTaxIncludesShipping, iShipping, 0)) * (cstHomeStateTax / 100.0))
iTax2 = 0
End If
Else
iTax1 = 0
iTax2 = 0
End If
End If
Else
iTax1 = 0
iTax2 = 0
End If
' Save values in session for later use ...
Session("40iTax1") = iTax1
Session("40iTax2") = iTax2
' Grand total ...
iGrandTotal = iSubTotal + iShipping + iTax1 + iTax2
Session("40iGrandTotal") = iGrandTotal
End Sub
' CalculateTaxableTotals() - Calculate taxable totals ...
Public Sub CalculateTaxableTotals()
Dim i
iTaxableTotal1 = 0 : iTaxableTotal2 = 0
For i = 1 to iCount
If (cstTaxOverrideEnabled) Then
If (LCase(GetParmToken(Trim(aryCart(cartTaxOverride, i) & " "), 1, "")) <> "yes") Then
iTaxableTotal1 = iTaxableTotal1 + aryCart(cartTotalPrice, i)
End If
If (LCase(GetParmToken(Trim(aryCart(cartTaxOverride, i) & " "), 2, "")) <> "yes") Then
iTaxableTotal2 = iTaxableTotal2 + aryCart(cartTotalPrice, i)
End If
Else
iTaxableTotal1 = iTaxableTotal1 + aryCart(cartTotalPrice, i)
iTaxableTotal2 = iTaxableTotal2 + aryCart(cartTotalPrice, i)
End If
Next
iTaxableTotal1 = IIF(iTaxableTotal1 < 0, 0, iTaxableTotal1)
iTaxableTotal2 = IIF(iTaxableTotal2 < 0, 0, iTaxableTotal2)
End Sub
' SubmitNote() - Compose note for display next to Submit button ...
Public Function SubmitNote()
SubmitNote = "Pressing the ""Submit Order"" button to the right begins the processing of your order."
End Function
' Main -----------------------------------------------------------------------------------
' Cancel Request? Do it before checking session ...
If (CInt(GetURLValue("Cancel")) = 1) Then
dbClose(Conn)
Session.Abandon
Response.Redirect(NonSecureURL(cstCancelURL))
End If
' Confirm no session timeout ...
Call ConfirmSessionOk(sesItemCount)
' Get session variables
aryCart = Session(sesShoppingCart)
iCount = Session(sesItemCount)
CustomerID = Session(sesCustomerID)
' Open the database ...
Set Conn = dbOpen("rwl")
' Page errors accumulate here ...
FormErrorMsg = ""
ShipperErrorMsg = ""
' Display status on return from payment gateway ....
Select Case CInt(GetURLValue("pmtStatus"))
Case 0 : 'No payment status on URL
Case pmtApproved : FormErrorMsg = FormErrorMsg & "Payment approved.
"
Case pmtPending : FormErrorMsg = FormErrorMsg & "Payment pending approval.
"
Case pmtCancelled : FormErrorMsg = FormErrorMsg & "Payment cancelled. Reason: " & GetURLValue("pmtReason") & "
"
Case pmtDeclined : FormErrorMsg = FormErrorMsg & "Payment declined. Reason: " & GetURLValue("pmtReason") & "
"
Case pmtFailed : FormErrorMsg = FormErrorMsg & "Payment authorization failed. Reason: " & GetURLValue("pmtReason") & "
"
Case Else : FormErrorMsg = FormErrorMsg & "Payment authorization return error. Contact software vendor
"
End Select
' Load internal shipping rates table ...
Call LoadShippingRates(oShippingRates, _
GetFieldData("ShipCountry", cstOriginCountry), _
GetFieldData("ShipStateOrProvince", cstOriginState), _
GetFieldData("ShipCity", cstOriginCity), _
GetFieldData("ShipPostalCode", cstOriginCode) _
)
' Calculate taxes ...
Call CalculateTaxableTotals()
' Sub total correction ...
iSubTotal = IIF(iSubTotal < 0, 0, iSubTotal)
' Pre build shipping choice DDB so default shipping
' method will be available on first load ...
Call GetShippingDDB()
'-----------------------------------------------------------------------
' Process form events here ...
Action = LCase(GetFormAction())
If Action = "submitorder" Then
iPass = 2
' Check here for double submits ... a null session means the user
' must have used the 'back' button from 50Finish to get here.
'
' Do not submit again, 50Finish will handle error reporting.
If (Session(sesInit) = "") Then
Response.Redirect("50Finish.asp")
End If
' Validate credit card number ...
If (cstCCCollectEnabled AND (Not (gblDemoMode OR (Trim(Request.Form("ExpDate")) = "N/A")))) Then
If (cstCCValidate) Then
PaymentMethod = LCase(Request.Form("PaymentMethod"))
' Check credit card # ...
If (Not (IsCCValid(PaymentMethod, Request.Form("CreditCardNumber")))) Then
FormErrorMsg = FormErrorMsg & "Invalid credit card number.
"
End If
End If
' Check expire date format ...
If (Not IsExpireDateValid(Request.Form("ExpDate"), DateErrorMsg)) Then
FormErrorMsg = FormErrorMsg & "" & DateErrorMsg & "
"
End If
Call CheckMissingField("CardHoldersName", "Card Holder Name")
End If
' Check CSC length, if present ...
If (cstCSCEnabled) Then
If (Not (isMatch(Trim(Request.Form("CVV2")), "^\d\d\d\d?$") Or LCase(Trim(Request.Form("CVV2"))) = "n/a")) Then
FormErrorMsg = FormErrorMsg & "CSC number must be 3 or 4 digits.
"
End If
End If
' Check for missing fields ...
If (Not cstSuppressShipTo) Then
Call CheckMissingField("ShipContactFirstName", "First Name")
Call CheckMissingField("ShipContactLastName", "Last Name")
Call CheckMissingField("ShipAddress1", "Address 1")
Call CheckMissingField("ShipCity", "City")
Call CheckMissingField("ShipStateOrProvince", "State")
Call CheckMissingField("ShipPostalCode", "Postal Code")
Call CheckMissingField("ShipCountry", "Country")
Call CheckMissingField("ShipPhoneNumber", "Phone")
Call CheckMissingField("ShipOrganization", "Organization")
End If
' If No errors -- insert into database
Call CalcOrderTotals()
' Last selected shipping method no longer available due to change in ship to address, ask again ...
If (Not IsObject(oShippingRates(Trim(Request.Form("ShippingMethod"))))) Then
FormErrorMsg = FormErrorMsg & "Please reselect a shipping method.
"
End If
If ((oShippingRates.Count >= 1) AND (FormErrorMsg = "")) Then
' Insert a new order record ...
set rsOrders = Server.CreateObject("ADODB.Recordset")
rsOrders.ActiveConnection = Conn
rsOrders.LockType = adLockOptimistic
rsOrders.Source = "Orders"
rsOrders.CursorType = adOpenKeyset
If (cstServerType = "SQL") Then
rsOrders.CursorLocation = adUseServer
End If
' Lock application to ensure that this user gets the order
' number of this order.
Application.Lock
rsOrders.Open
rsOrders.AddNew
rsOrders("CustomerID") = Session(sesCustomerID)
rsOrders("OrderDate") = Now()
rsOrders("Password") = CreateRandomID(16)
rsOrders("ShipCompanyName") = stripHTML(Request.Form("ShipCompanyName"))
rsOrders("ShipContactFirstName") = stripHTML(Request.Form("ShipContactFirstName"))
rsOrders("ShipContactLastName") = stripHTML(Request.Form("ShipContactLastName"))
rsOrders("ShipAddress1") = stripHTML(Request.Form("ShipAddress1"))
rsOrders("ShipAddress2") = stripHTML(Request.Form("ShipAddress2"))
rsOrders("ShipCity") = stripHTML(Request.Form("ShipCity"))
rsOrders("ShipStateOrProvince") = stripHTML(Request.Form("ShipStateOrProvince"))
rsOrders("ShipPostalCode") = stripHTML(Request.Form("ShipPostalCode"))
rsOrders("ShipCountry") = stripHTML(Request.Form("ShipCountry"))
rsOrders("ShipPhoneNumber") = stripHTML(Request.Form("ShipPhoneNumber"))
rsOrders("ShipOrganization") = stripHTML(Request.Form("ShipOrganization"))
rsOrders("ShippingMethodDescription") = Request.Form("ShippingMethod")
rsOrders("FreeShipping") = IIF(oShippingRates(Trim(Request.Form("ShippingMethod"))).Free, "Yes", "No")
rsOrders("FreightCharge") = ToNumber(Session("40iShipping"))
rsOrders("TransitTime") = Session("40TransitTime") & " "
rsOrders("SalesTax1") = ToNumber(Session("40iTax1"))
rsOrders("SalesTax2") = ToNumber(Session("40iTax2"))
rsOrders("PaymentAmount") = ToNumber(Session("40iGrandTotal"))
rsOrders("CreditCardNumber") = Crypt(stripHTML(Request.Form("CreditCardNumber")), cstEncryptionKey, "enc")
rsOrders("CardHoldersName") = stripHTML(Request.Form("CardHoldersName"))
rsOrders("CreditCardExpDate") = Crypt(stripHTML(Request.Form("ExpDate")), cstEncryptionKey, "enc")
rsOrders("CVV2") = Crypt(stripHTML(Request.Form("CVV2")) & " ", cstEncryptionKey, "enc")
rsOrders("PurchaseOrderNumber") = stripHTML(Request.Form("PurchaseOrderNumber"))
rsOrders("PaymentMethodID") = Null ' Reserved for future use.
rsOrders("PaymentMethodDescription") = Request.Form("PaymentMethod")
rsOrders("Survey1") = stripHTML(Request.Form("Survey1")) & " "
rsOrders("Survey2") = stripHTML(Request.Form("Survey2")) & " "
rsOrders("Survey3") = stripHTML(Request.Form("Survey3")) & " "
rsOrders("IPAddress") = Left(Trim(Session("REMOTE_ADDR")), rsOrders.Fields("IPAddress").DefinedSize - 1) & " "
rsOrders("Language") = Left(Trim(Session("HTTP_ACCEPT_LANGUAGE")), rsOrders.Fields("Language").DefinedSize - 1) & " "
rsOrders("Notes") = Replace(stripHTML(Request.Form("Notes")), VbCrLf, "~")
rsOrders.Update
' Pick up order id from record just created ...
OrderId = rsOrders("OrderId")
Session("OrderID") = OrderID
Application.Unlock
' Insert new order detail records ...
set rsOrderDetails = Server.CreateObject("ADODB.Recordset")
rsOrderDetails.ActiveConnection = Conn
rsOrderDetails.LockType = adLockOptimistic
rsOrderDetails.Source = "OrderDetails"
rsOrderDetails.CursorType = adOpenKeyset
rsOrderDetails.Open
For i = 1 to iCount
rsOrderDetails.AddNew
rsOrderDetails("OrderID") = OrderId
' rsOrderDetails("ProductID") ' No longer used in OrderDetail record.
rsOrderDetails("ProductCode") = aryCart(cartProductCode, i)
rsOrderDetails("ProductName") = aryCart(cartProductName, i)
if aryCart(cartProductDescription, i) = "" then
aryCart(cartProductDescription, i) = "none"
End if
rsOrderDetails("ProductDescription") = aryCart(cartProductDescription, i)
rsOrderDetails("DownloadFileName") = aryCart(cartDownloadFileName, i)
rsOrderDetails("Quantity") = aryCart(cartItemQuantity, i)
rsOrderDetails("UnitPrice") = aryCart(cartUnitPrice, i)
rsOrderDetails("TotalPrice") = aryCart(cartTotalPrice, i)
rsOrderDetails("Options") = aryCart(cartOptions, i)
rsOrderDetails("NSN") = aryCart(cartNSN, i)
rsOrderDetails("Packaging") = aryCart(cartPackaging, i)
rsOrderDetails("SKU") = aryCart(cartSKU, i)
'************coded inserted august 27,2005**********start
rsOrderDetails("StampParams")=aryCart(larryNotes, i)
'************coded inserted august 27,2005**********end
rsOrderDetails.Update
Next
rsOrders.Close : Set rsOrders = Nothing
rsOrderDetails.Close : Set rsOrderDetails = Nothing
' Reflect shipping address changes back to customer record before closing...
rs("ShipCompanyName") = stripHTML(Request.Form("ShipCompanyName"))
rs("ShipContactFirstName") = stripHTML(Request.Form("ShipContactFirstName"))
rs("ShipContactLastName") = stripHTML(Request.Form("ShipContactLastName"))
rs("ShipAddress1") = stripHTML(Request.Form("ShipAddress1"))
rs("ShipAddress2") = stripHTML(Request.Form("ShipAddress2"))
rs("ShipCity") = stripHTML(Request.Form("ShipCity"))
rs("ShipStateOrProvince") = stripHTML(Request.Form("ShipStateorProvince"))
rs("ShipPostalCode") = stripHTML(Request.Form("ShipPostalCode"))
rs("ShipPhoneNumber") = stripHTML(Request.Form("ShipPhoneNumber"))
rs("ShipOrganization") = stripHTML(Request.Form("ShipOrganization"))
rs("ShipCountry") = stripHTML(Request.Form("ShipCountry"))
rs.Update : rs.Close : Set rs = Nothing
' Live inventory update, if installed and enabled ...
If (isInstalled("Feature:Live Inventory") And cstLiveInvEnabled) Then
For i = 1 to iCount
If (aryCart(cartItemType, i) = "usr") Then
Call FeatureInstalled("Feature:Live Inventory").AdjustByProductID( _
aryCart(cartProductID, i), "OnHandInv", aryCart(cartItemQuantity, i), "-")
End If
Next
End If
' Sale-time credit card processing ...
' Confirm that a payment gateway exists for the selected payment method ...
set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM PaymentMethods WHERE PaymentMethod = '" & CleanSQL(Request.Form("PaymentMethod"), "a") & "'"
rs.Open SQL, Conn, adOpenKeyset, adLockOptimistic
PaymentGateway = IIF(rs.RecordCount = 1, rs("PaymentGateway"), "None")
PaymentAuthTime = IIF(rs.RecordCount = 1, rs("PaymentAuthTime"), "None")
rs.Close : Set rs = Nothing
dbClose(Conn)
' Process the payment now, or leave until review time ...
If ((Trim(LCase(PaymentAuthTime)) = "sale") AND _
(Trim(LCase(PaymentGateway)) <> "cash") AND _
(Trim(LCase(PaymentGateway)) <> "none") AND _
(Session("40iGrandTotal") <> 0)) Then
Session("PmtGatewayCalledBy") = "40GetShp.asp"
Response.Redirect("45CCAuth.asp")
Else
Response.Redirect ("50Finish.asp")
End If
End If
ElseIF Action = "recalculate" Then
iPass = 2
Call CalcOrderTotals()
Else
' First pass, get ready to display customer record
iPass = 1
' Get order totals ...
Call CalcOrderTotals()
End If
%>