%
'******************************************************
' VP-ASP 6.50 RMA Emailing
' Subroutines include"
' shoprmaemailtocustomer mail on creation
' shoprmaemailtomerchant mail on creation
'
' Nov 18, 2006 HK Created
'*****************************************************
dim rmacustomercomment
dim rmamerchantcomment
dim rmamerchantnotes
dim rmacustomeraction
dim rmamerchantaction
dim rmarefundamount
dim rmamerchantname
dim rmacustomername
dim rmacustomeremail
dim rmamerchantemail
dim rmacustomerid
dim rmaother1
dim rmaother2
dim rmaproductname
dim rmaorderid
'*******************************************************************************
' mail to customer on rma request
'******************************************************************************
Sub ShopRMAEmailToCustomer (dbc, oid, rmaid)
dim template, rs, mysql, trackid, bodymessage, emailformat
dim strname, stremail, CR
dim acount, attachments
acount=0
CR=getmailCR
template=getconfig("xrmacustomertemplate")
template="tmp_rmacustomer.txt"
mysql="SELECT orders.*, shoprma.* FROM orders INNER JOIN shoprma ON orders.orderid = shoprma.rmaorderid"
mysql= mysql & " WHERE shoprma.rmaid=" & rmaid
set rs=dbc.execute(mysql)
if rs.eof then
closerecordset rs
exit sub
end if
body=""
FormatOtherMail Template, RS, Body
strname=rs("rmacustomername")
stremail=rs("rmacustomeremail")
SetupEmailformat template,emailformat
if emailformat<>"HTML" then
body=replace(body,"
", CR)
end if
mailtype=getconfig("xemailtype")
my_from=getconfig("xemailname")
my_fromaddress=getconfig("xemail")
my_toaddress=strEmail
my_to=strname
my_system=getconfig("xemailsystem")
my_subject= getlang("LangRMA") & " " & getlang("langproductorderNumber") & " " & oid
closerecordset rs
ExecuteMail mailtype,My_from,my_fromaddress,my_to,my_toaddress,my_subject,body,emailformat,attachments, acount
ShopWriteheader getlang("LangMailMailing") & my_to & " " & my_toaddress
end sub
'***********************************************************************
' email merchant on rma creation
'***********************************************************************
Sub ShopRMAEmailToMerchant (dbc, oid, rmaid)
dim template, rs, mysql, trackid, bodymessage
dim strname, stremail, CR
dim acount, attachments
acount=0
CR=getmailCR
template=getconfig("xrmamerchnattemplate")
template="tmp_rmamerchant.txt"
mysql="SELECT orders.*, shoprma.* FROM orders INNER JOIN shoprma ON orders.orderid = shoprma.rmaorderid"
mysql= mysql & " WHERE shoprma.rmaid=" & rmaid
set rs=dbc.execute(mysql)
if rs.eof then
closerecordset rs
exit sub
end if
FormatOtherMail Template, RS, BodyMessage
strname=rs("rmacustomername")
stremail=rs("rmacustomeremail")
SetupEmailformat template,emailformat
Closerecordset rs
body=bodymessage & "
" & Body
if emailformat<>"HTML" then
body=replace(body,"
", CR)
end if
mailtype=getconfig("xemailtype")
my_to=getconfig("xemailname")
my_toaddress=getconfig("xemail")
my_fromaddress=strEmail
my_from=strname
my_system=getconfig("xemailsystem")
my_subject= getlang("LangRMA") & " " & getlang("langproductorderNumber") & " " & oid
'
ExecuteMail mailtype,My_from,my_fromaddress,my_to,my_toaddress,my_subject,body,emailformat,attachments, acount
shopwriteheader getlang("LangMailMailing") & my_to & " " & my_toaddress
end sub
'***********************************************************************************
' format all rmas for a specific order
'***********************************************************************************
Sub ShopRMAformat (dbc,customerid)
dim tsql, fields(10),fieldcount, tRs, iadminflag
tsql="select * from shoprma where rmacustomerid=" & customerid
tsql=tsql & " order by rmaid desc"
set trs=dbc.execute(tsql)
If trs.eof then
closerecordset trs
shopwriteheader getlang("langrmanone")
exit sub
end if
DisplayRMAHeader fields,fieldcount
Do While Not tRS.EOF
DisplayRMARow tRS, fields, fieldcount, iadminflag
tRS.MoveNext
Loop
Response.write reporttableend
closerecordset trs
end sub
'
Sub DisplayRMARow (trs, fields, fieldcount,adminflag)
dim fieldvalue, fieldcomment, i, name, emailaddr
dim editresponder, my_link, rmaid
editresponder="shopa_editrecord.asp"
fieldcomment=trs("rmacustomercomment")
response.write "
"
for i = 0 to fieldcount
'debugwrite trs("trackdate")
Select Case ucase(fields(i))
Case "RMA"
fieldvalue=trs(fields(i))
rmaid=trs("rmaid")
my_link="shoprmalist.asp?rmaid=" & rmaid
fieldvalue="" & fieldvalue & ""
Case "RMACREATIONDATE","RMAMERCHANTDATE"
fieldvalue=trs(fields(i))
if fieldvalue > "" then
fieldvalue=shopdateformat(fieldvalue, getconfig("xdateformat"))
end if
Case else
fieldvalue=trs(fields(i))
end select
response.write ReportDetailColumn & fieldvalue & ReportDetailcolumnEnd
next
response.write "
"
end sub
'
'*************************************************************************
' header for report
'************************************************************************
Sub DisplayRMAHeader (fields, fieldcount)
dim captions(10)
dim i
Fields(0)="rma"
Fields(1)="rmacreationdate"
Fields(2)="rmacustomername"
Fields(3)="rmacustomeraction"
Fields(4)="rmacustomercomment"
Fields(5)="rmamerchantaction"
Fields(6)="rmamerchantdate"
Fields(7)="rmamerchantcomment"
Captions(0)=getlang("langrma")
Captions(1)= getlang("LangDisplayDate")
captions(2)= getlang("Langcommonname")
Captions(3)= "Customer Action"
Captions(4)= "Customer Comment"
Captions(5)= "Merchant Action"
Captions(6)= "Merchant Date"
Captions(7)= "Merchant Comment"
fieldcount=7
response.write "" & vbCrLf
response.write ReportHeadRow
for i = 0 to fieldcount
Response.write ReportHeadColumn & Captions(i) & ReportHeadColumnEnd
next
response.write ReportRowEnd
end sub
'*******************************************************************************
' format an rma for merchant based on a template
'*******************************************************************************
sub FormatRmaMerchant (rmars)
dim template, rc
template=getconfig("xrmamerchantformattemplate")
ShopTemplateWrite template, rmaRS, rc
end sub
'******************************************************************
' format rma for merchnat by template
'******************************************************************
sub FormatRmaCustomer (rmars)
dim template, rc
template=getconfig("xrmacustomerformattemplate")
ShopTemplateWrite template, rmaRS, rc
end sub
'****************************************************************************************
' get rma and order record as a recordset for later use by called
'****************************************************************************************
Sub GetRmaRecordset (myconn, rmaid, rmars, rc)
dim mysql
mysql="SELECT orders.*, shoprma.* FROM orders INNER JOIN shoprma ON orders.orderid = shoprma.rmaorderid"
mysql= mysql & " WHERE shoprma.rmaid=" & rmaid
set rmars=myconn.execute(mysql)
if rmars.eof then
rc=4
closerecordset rmars
exit sub
end if
rc=0
end sub
'****************************************************************************
' get values from rmars and store into variables
'***************************************************************************
Sub Setuprmavalues (rmars)
rmacustomercomment=rmars("rmacustomercomment")
rmamerchantcomment=rmars("rmamerchantcomment")
rmamerchantnotes=rmars("rmamerchantnotes")
rmamerchantaction=rmars("rmamerchantaction")
rmacustomeraction=rmars("rmacustomeraction")
rmarefundamount=rmars("rmarefundamount")
rmamerchantname=rmars("rmamerchantname")
rmacustomername=rmars("rmacustomername")
rmamerchantemail=rmars("rmamerchantemail")
rmacustomeremail=rmars("rmacustomeremail")
rmaorderid=rmars("rmaorderid")
rmacustomerid=rmars("rmacustomerid")
end sub
'*******************************************************************
' used for both customer and merchnat forms
'*******************************************************************
sub RmaGetFormvalues
rmacustomercomment=cleanchars(request.form("rmacustomercomment"))
rmamerchantcomment=cleanchars(request.form("rmamerchantcomment"))
rmamerchantnotes=cleanchars(request.form("rmamerchantnotes"))
rmamerchantaction=cleanchars(request.form("rmamerchantaction"))
rmacustomeraction=cleanchars(request.form("rmacustomeraction"))
rmarefundamount=cleanchars(request.form("rmarefundamount"))
rmamerchantname=cleanchars(request.form("rmamerchantname"))
rmacustomername=cleanchars(request.form("rmacustomername"))
rmamerchantemail=cleanchars(request.form("rmamerchantemail"))
rmacustomeremail=cleanchars(request.form("rmacustomeremail"))
end sub
'*******************************************************************************
' mail to customer on rma request
'******************************************************************************
Sub RMAEmailToCustomerFromMerchant (dbc, rmaid)
dim template, rs, mysql, trackid, bodymessage, emailformat
dim strname, stremail, CR
dim acount, attachments
template=getconfig("xrmacustomerfrommerchanttemplate")
acount=0
CR=getmailCR
mysql="SELECT orders.*, shoprma.* FROM orders INNER JOIN shoprma ON orders.orderid = shoprma.rmaorderid"
mysql= mysql & " WHERE shoprma.rmaid=" & rmaid
set rs=dbc.execute(mysql)
if rs.eof then
closerecordset rs
exit sub
end if
body=""
FormatOtherMail Template, RS, Body
strname=rs("rmacustomername")
stremail=rs("rmacustomeremail")
SetupEmailformat template,emailformat
if emailformat<>"HTML" then
body=replace(body,"
", CR)
end if
mailtype=getconfig("xemailtype")
my_from=rs("rmamerchantname")
my_fromaddress=rs("rmamerchantemail")
my_toaddress=strEmail
my_to=strname
my_system=getconfig("xemailsystem")
my_subject= getlang("LangRMA") & " " & getlang("langproductorderNumber") & " " & oid
closerecordset rs
ExecuteMail mailtype,My_from,my_fromaddress,my_to,my_toaddress,my_subject,body,emailformat,attachments, acount
ShopWriteheader getlang("LangMailMailing") & my_to & " " & my_toaddress
end sub
Sub RmaGetProductname (myconn, itemid, rmaproductname)
dim sql, rs
sql="select * from oitems where orderitemid=" & itemid
set rs=myconn.execute(sql)
if not rs.eof then
rmaproductname=rs("itemname")
If len (rmaproductname)>250 then
rmaproductname=left(rmaproductname,250) & "..."
end if
end if
closerecordset rs
end sub
'******************************************************************************
' create gft ceriftificate
'****************************************************************************
Sub RMACreateGiftCertificate (myconn,rmaid, certificate)
dim name, dbc, gsql, giftid, sqlo
dim rs, mysql, amount
Dim giftexpires, today
mysql="SELECT orders.*, shoprma.* FROM orders INNER JOIN shoprma ON orders.orderid = shoprma.rmaorderid"
mysql= mysql & " WHERE shoprma.rmaid=" & rmaid
set rs=myconn.execute(mysql)
if rs.eof then
closerecordset rs
exit sub
end if
Setuprmavalues rmars ' get values from recordser
RMABuildGiftDetails certificate
name=rmacustomername ' customer
stremail=rmacustomeremail ' email
amount=rmarefundamount
today=date()
shopopendatabase dbc
giftexpires=dateadd("d",date(),getconfig("xgiftexpirydays"))
gsql="insert into gifts (giftnumber) values('" & certificate & "')"
dbc.execute(gsql)
gsql="select max(giftid) from gifts where giftnumber='" & certificate & "'"
set objrs=dbc.execute(gsql)
giftid=objrs(0)
objrs.close
set objrs=nothing
sqlo=""
rmasqltextfield sqlo,"giftnumber", certificate
rmasqltextfield sqlo,"giftissuedate", datenormalize(date())
rmasqltextfield sqlo,"giftexpirydate", datenormalize(giftexpires)
rmasqlnumbfield sqlo,"giftamount", amount
rmasqltextfield sqlo,"gifttoname", name
rmasqltextfield sqlo,"giftfromname", getconfig("xemailname")
rmasqltextfield sqlo,"gifttoemail", stremail
rmasqltextfield sqlo,"giftfromemail", getconfig("xemail")
rmasqltextfield sqlo,"giftmessage", getlang("RMA")
rmasqltextfield sqlo,"giftorderid", 0
rmasqltextfield sqlo,"giftcustomerid", rmacustomerid
mysqlnumbfield sqlo,"giftamountremaining", amount
rmasqltextfield sqlo,"giftauthorized", getconfig("Langcommonyes")
gsql="update gifts " & sqlo & " where giftid=" & giftid
dbc.execute(gsql)
shopclosedatabase dbc
end sub
'***************************************************************************
' add sql to sql string if the value is something otherwise set to null
'**************************************************************************
Sub rmasqlnumbfield (isql,fieldname,fieldvalue)
if fieldvalue="" then
exit sub
end if
if isql="" then
isql="SET "
else
isql=isql &","
end if
isql=isql & fieldname & "=" & fieldvalue
end Sub
'***************************************************************************
' add sql to sql string if the value is something otherwise set to null
'**************************************************************************
Sub rmasqltextfield (isql,fieldname,fieldvalue)
dim tfieldvalue
if fieldvalue="" then
tfieldvalue="NULL"
else
tfieldvalue=replace(fieldvalue,"'","''")
end if
if isql="" then
isql="SET "
else
isql=isql &","
end if
If tfieldvalue="NULL" then
isql=isql & fieldname & "=" & tfieldvalue
else
isql=isql & fieldname & "='" & tfieldvalue & "'"
end if
end Sub
'***********************************************************
' gift certificate is
' RMA-hhmmss-0yyy
' yyy is the rmaid if the rma
'**********************************************************
Sub RMABuildGiftDetails (giftnum)
dim oid, prefix, mytime, mm,hh,ss
prefix=getlang("langrma")
oid=rmaid
mytime=now()
hh=hour(mytime)
mm=minute(mytime)
ss=Second(mytime)
Giftnum=prefix &"-" & hh &mm &ss & "0" & "-" & Oid
end sub
'
Sub RMAMailGiftCertificate (certificate)
'************************************************************
' mail to message to customer and Merchant
' database is assumed opened with dbc=open database
'************************************************************
Dim oid, giftsql, giftmessage, gifts(50), i, giftcount
dim template,giftid, giftrs, myconn, emailformat
Dim strgifttoname,strgiftfromname,strgifttoemail,strgiftfromemail
dim attachyesno, subject
attachyesno="No"
Shopopendatabase myconn
template=getconfig("xrmagifttemplate")
if template="" then exit sub
giftsql="select * from gifts where giftnumber='" & certificate & "'"
set giftrs=myconn.execute(Giftsql)
FormatOtherMail template, giftrs, GiftMessage
strgifttoname = giftrs("gifttoname")
strgiftfromname = giftrs("giftfromname")
strgifttoemail = giftrs("gifttoemail")
strgiftfromemail = giftrs("giftfromemail")
subject=getlang("langrma") & " " & getlang("LangGiftCertificate") & " " & certificate
' mail to customer
RMAmailPerson strGiftToname, strgifttoemail, strgiftfromname, strgiftfromemail, subject, GiftMessage,attachyesno
' mail to merchant
RMAmailPerson strgiftfromname, strgiftfromemail,strGiftToname, strgifttoemail, subject, GiftMessage,attachyesno
'Debugwrite strGifttoname & " " & Giftmessage
If getconfig("xdebug")="Yes" then
Debugwrite "Gift certificate send to " & strGifttoemail & " from " & strgiftfromemail
end if
giftrs.close
set giftrs=nothing
shopclosedatabase myconn
end sub
Sub RMAMailPerson (toname, toaddress, fromname, fromaddress, subject, tobody,attachmentYesNo)
dim acount, body, htmlformat, attachmentarray(5)
SetSess "mailerror",""
my_system=getconfig("xemailsystem") ' mail.mysystem.com
mailtype=getconfig("xemailtype") ' aspmail, jmail, cdonts
my_subject=subject
my_to=toname
my_toAddress=toaddress
my_from=fromname
my_fromAddress=fromaddress
if my_toAddress= "" then
exit sub
end if
if my_from = "" then
my_from="Unknown"
end if
if my_fromAddress="" then
my_fromAddress="unknown@unknown.com"
end if
body=tobody
if getconfig("xDebug")="Yes" then
debugwrite "mailing to " & toname & " " & toaddress
end if
htmlformat=Getsess("EmailFormat")
If attachmentYesNo="Yes" then
acount=attachmentcount
else
acount=0
end if
ExecuteMail mailtype,My_from,my_fromaddress,my_to,my_toaddress,my_subject,body,htmlformat,attachmentarray,acount
end sub
%>