<% '****************************************************************** ' VP-ASP 6.50 ' Reads and formats the affiliate log records ' October 27, 2005 ' Display all orders for affiliate over a certain period ' October 31, add check for ocardtype '******************************************************************* dim totalproductprice, totalshipprice,totalamount, totalordercount, totalcommissionamount dim Gtotalproductprice, Gtotalshipprice,Gtotalamount, Gtotalordercount, Gtotalcommissionamount dim ordercount dim reportcount dim reporttype dim pconn ' product database dim ors ' order record set dim oaffid ' current affiliate dim decimalpoint dim recordcount ' list report dim reportadmin ' null if customer others yes dim cardtypearray(20), cardtypecount ' valid card types '******************************************************************* ' start of report logic '****************************************************************** sub affiliateOrderReport (dbc,fromdate, todate, affid, itype) reporttype=ucase(Itype) shopopendatabaseP pconn generatesql fromdate, todate, affid 'ShopOpenRecordSet SQL,ors, mypagesize, mypage set ors=dbc.execute(sql) ' no paging in this program if ors.eof then shopwriteError getlang("LangReportNoSales") else InitializeTotals ' initial total values GenerateOrderReport end if closerecordset ors shopclosedatabase pconn end sub '**************************************************************************** ' affiliate totals and grans totals '*************************************************************************** Sub Initializetotals totalproductprice=0 totalshipprice=0 totalamount=0 totalordercount=0 totalcommissionamount=0 ordercount=0 If reportcount="" then reportcount=1 Gtotalproductprice=0 Gtotalshipprice=0 Gtotalamount=0 Gtotalordercount=0 Gtotalcommissionamount=0 else reportcount=reportcount+1 ' number of times we have entered end if decimalpoint=getconfig("xdecimalpoint") Getvalidcardtypes ' get valid card types end sub '***************************************************************************** ' put out header of report, xheaderlist has list of headers ' also affiliate number '***************************************************************************** Sub FormatReportHeader const XHeaderList="No,Orderid,Date,Last Name, First Name,Productid, Product Name, Product Price, Shipping Cost, Total Price, Commission" dim captions(20), captioncount, i dim my_link parserecord xheaderlist,captions,captioncount,"," my_link="shopa_affformataffiliate.asp?affid=" & oaffid If reportadmin="" then shopwriteheader "
Affiiate # " & oaffid & "
" else shopwriteheader "
Affiiate # " & oaffid & "
" end if response.write "" response.write ReportHeadRow for i = 0 to captioncount-1 Response.write ReportHeadColumn & Captions(i) & ReportHeadColumnEnd next response.write ReportRowEnd end sub '********************************************************************** ' Order Recordset has the orders to format '********************************************************************** sub GenerateOrderreport dim rc oaffid=ors("oaffid") maxrecs=clng(mypagesize) recordcount=0 If reporttype<>"SUMMARY" Then Formatreportheader ' wrie affilaite number else response.write ReportTableDef end if Do While Not oRS.EOF validatepurchase ors, rc if rc=0 then FormatOrderRecord recordcount=recordcount+1 end if ors.movenext loop If reporttype<>"SUMMARY" Then GenerateSummaryReport end if Response.write tabledefend ' we cannot double page so if in admin, we do not have page navigation If Reportadmin="" then If recordcount>= maxrecs then ' PageNavBar SQL ' no paging in this program end if end if end sub Sub FormatOrderRecord '********************************************************************** ' get fields and then display then '********************************************************************** dim strlastname, strfirstname, productname, productcode, productprice, commission dim decimalcount, shipcost, orderid, totalprice, orderdate dim my_link, listorder ordercount=ordercount+1 shipcost=ors("oshipcost") commission=ors("commission") orderid=ors("orderid") strfirstname=ors("ofirstname") strlastname=ors("olastname") orderdate=ors("odate") productname="" productcode="" my_link="shopa_formatorder.asp?oid=" & orderid listorder="" & orderid & "" GetProductdetails orderid, productname, productcode, productprice totalprice=productprice+shipcost If reporttype<>"SUMMARY" Then response.write reportdetailrow Writereportcolumn ordercount & "." if reportadmin="" then Writereportcolumn orderid else writereportcolumn listorder ' create hyperlink to format order end if Writereportcolumn orderdate Writereportcolumn strlastname Writereportcolumn strfirstname Writereportcolumn productcode Writereportcolumn productname Writereportcolumn shopformatcurrency(productprice, decimalpoint) Writereportcolumn shopformatcurrency(shipcost,decimalpoint) writereportcolumn shopformatcurrency(totalprice,decimalpoint) writereportcolumn shopformatcurrency(commission,decimalpoint) end if AddTotals totalproductprice, Gtotalproductprice,productprice addtotals totalshipprice,Gtotalshipprice, shipcost addtotals totalamount, Gtotalamount, totalprice Totalordercount=totalordercount+1 GTotalordercount=Gtotalordercount+1 'VP-ASP 6.50 if (commission <> "") and ( not isnull(commission)) then addtotals totalcommissionamount, Gtotalcommissionamount, commission else addtotals totalcommissionamount, Gtotalcommissionamount, 0 end if end sub sub AddTotals (total, Gtotal,fieldvalue) total=total+ fieldvalue gtotal=gtotal+fieldvalue end sub Sub WriteReportColumn (fieldvalue) response.write ""' & reportdetailrow response.write "" response.write "" ' last name response.write "" response.write "" ' last name response.write "" ' first name response.write "" ' product code response.write "" ' product name response.write "" response.write "" response.write "" response.write "" end sub '******************************************************************** ' there was originally going be be paging but because ' it is used in admin also, removed paging logic ' so mypage should always be empty '******************************************************************** Sub generatesql (fromdate, todate, lngaffid) dim addsql dim mysql dim sqlproc dim datesql dim fromdatex, todatex if reportadmin="" then if mypage<>"" then sql=GetSess("affSqlquery") ' on recursive calls we stored sql in sessikon variable fromdate=getsess("Fromdate") todate=GetSess("Todate") If sql<>"" then exit sub end if else mypage=1 end if end if addsql=" AND " MySql = "SELECT * from orders " sqlproc ="" addsql=" WHERE " Mysql=MySql & sqlproc If fromdate<>"" then fromdatex = DateDelimit (fromdate) todatex = dateDelimit (todate) datesql = " odate>= " & fromDatex datesql = datesql & " AND odate<= " & todatex mysql = mysql & addsql & "(" & datesql & ")" Addsql=" AND " end if mysql = mysql & addsql & " oaffid=" & lngaffid mysql=mysql & " order by orderid desc" SQL=Mysql setsess "affsqlquery",sql ' for paging end sub sub GetProductdetails (orderid, productname, productcode, productprice) dim sql, rs, catalogid, cname, ccode, unitprice, quantity dim tempname, tempcode dim psql, prs productprice=0 sql="Select * from oitems where orderid=" & orderid set rs=dbc.execute(sql) ' get all order items do while not rs.eof quantity=rs("numitems") ' quantity catalogid=rs("catalogid") ' catalogid tempname=rs("itemname") ' name in cart tempcode="" unitprice=rs("unitprice") ' unit prive productprice=productprice+unitprice*quantity psql="Select cname, ccode from products where catalogid=" & catalogid set prs=pconn.execute(psql) if not prs.eof then tempname=prs("cname") tempcode=prs("ccode") end if closerecordset prs if productname<>"" then productname=productname & "
" productcode=productcode & "
" end if productname=productname & tempname productcode=productcode & tempcode rs.movenext loop closerecordset rs end sub Sub GenerateGrandtotals Response.write "
" & fieldvalue & ReportDetailColumnEnd end sub Sub GenerateSummaryReport response.write "
TOTALS      " & shopformatcurrency(totalproductprice, decimalpoint) & "" & shopformatcurrency(totalshipprice,decimalpoint) & "" & shopformatcurrency(totalamount,decimalpoint) & "" & shopformatcurrency(totalcommissionamount,decimalpoint) & "
" WriteGrandRow "Total Orders", Gtotalordercount WriteGrandRow "Total Product Price", shopformatcurrency(Gtotalproductprice,decimalpoint) WriteGrandRow "Total Ship Cost", shopformatcurrency(Gtotalshipprice, decimalpoint) WriteGrandRow "Total Order Amount", shopformatcurrency(gtotalamount,decimalpoint) Writegrandrow "Total Commission", shopformatcurrency(Gtotalcommissionamount, decimalpoint) response.write tabledefend & "" end sub Sub WriteGrandRow (caption, ivalue) Response.write "" response.write "" end sub ' Sub ValidatePurchase (orderRS, rc) '******************************************************* ' See if payment type matches any of the valid payments allowed ' '******************************************************* dim i rc=0 dim paymenttype Paymenttype =ucase(OrderRS("ocardtype")) if cardtypecount=0 then exit sub if OrderRS("oprocessed")=TRUE then exit sub for i = 0 to cardtypecount-1 If ucase(cardtypearray(i))=paymenttype then exit sub end if next rc=4 end sub '*********************************************************************** ' done once per report '*********************************************************************** Sub Getvalidcardtypes dim cardtype if cardtypecount<>"" then exit sub CardType=Getconfig("xendofordervalidpayments") cardtypecount=0 If cardtype="" then exit sub end if parserecord cardtype, cardtypearray,cardtypecount,"," end sub %>
" response.write caption & "" response.write ivalue response.write "