<% set null off set date ymd set cent on dateto =orequest.querystring("dateto") thecustomer =nvl(orequest.querystring("customerid"),[]) reportbase =orequest.querystring("reportbase") wheretext=[] thecustomername=[] REPTTITLE=[DEBIT SALE SUMMARY] REPTSECLINE=[] if isnull(dateto) or empty(ctod(dateto)) dateto=orequest.form("dateto") endif pdate2=ctod(dateto) set date british categoryname= allt(nvl(orequest.querystring("category"),'')) classname= allt(nvl(orequest.querystring("class"),'')) if isnull(pdate2) or empty(pdate2) tsql=[select top 1 date from (']+dbclocation+[invoice') order by date desc into cursor tmp] &tsql pdate2=date endif if not empty(pdate2) wheretext=wheretext+[and x.date=pdate2 ] REPTSECLINE=TRANSFORM(PDATE2) endif if not empty(thecustomer) wheretext=wheretext+[and x.customer=thecustomer ] tsql=[select x.name from (']+dbclocation+[accounts') x where x.accountid=']+thecustomer+[' into cursor tmp] &tsql thecustomername=allt(name) REPTSECLINE=THECUSTOMERNAME+[ (]+THECUSTOMER+[)]+[
]+REPTSECLINE endif if not empty(wheretext) wheretext=[where ]+subst(wheretext,5) endif tstr=[

### ]+REPTTITLE+[

]+reptsecline+[

] tsql=[Select z.accountid, z.name as acname, y.itemid, y.desc, y.qty, y.bonus, y.transid, y.sr_no ] tsql=tsql+[ from (']+dbclocation+[invoice') x inner join (']+dbclocation+[invdata') y on (x.transid=y.transid) ] tsql=tsql+[ left join (']+dbclocation+[accounts') z on (x.customer=z.accountid) ] tsql=tsql+wheretext+[ order by z.name, z.accountid, y.itemid, y.desc into cursor tempcursor ] && table ]+addbs(oprop.appstartpath)+[temp\tempcursor.dbf] try &tsql catch tstr=[Has error] endtry if tstr=[Has error] oresponse.write(tsql) return endif if _tally=0 return [No records found with current criteria date: ]+transform(pdate2)+[ customer: ]+thecustomername endif store 0 to tthissale, tthisreturns, tthiscost, tthisprofet select [tempcursor] hasbonus=.f. go TOP do while not eof() if not empty(bonus) hasbonus=.t. exit endif skip enddo tstr=tstr+[
Item# | Item Name | QTY]+iif(hasbonus,[ | FREE | T.QTY],[])+[
--- | --- | --- | --- | ---
] go top do while not eof() thisac=accountid thisname=acname tstr=tstr+[
]+allt(thisname)+[ (]+accountid+[)
] do while accountid=thisac and not eof() THISITEM=nvl(itemid,[itemid]) THISitemname=NVL(desc,[desc]) thisqty=0 thisbonus=0 do while nvl(itemid,[itemid])=thisitem and THISitemname=NVL(desc,[desc]) and not eof() thisqty=thisqty+nvl(QTY,0) thisbonus=thisbonus+nvl(bonus,0) skip enddo thisqty=icase(thisqty=round(thisqty,0),round(thisqty,0),thisqty=round(thisqty,2),round(thisqty,2),thisqty=round(thisqty,3),round(thisqty,3),round(thisqty,4)) thisbonus=icase(thisbonus=round(thisbonus,0),round(thisbonus,0),thisbonus=round(thisbonus,2),round(thisbonus,2),thisbonus=round(thisbonus,3),round(thisbonus,3),round(thisbonus,4)) thistotal=thisqty+thisbonus thislinestr=[
] thislinestr=thislinestr+[]+iif(empty(THISITEM),[NO ITEM ID],ALLT(THISITEM))+[] thislinestr=thislinestr+[ | ]+iif(empty(THISitemname),[NO ITEM NAME],ALLT( THISitemname))+[] thislinestr=thislinestr+[ | ]+iif(empty(thisqty),[ ],transform(thisqty))+[] if hasbonus thislinestr=thislinestr+[ | ]+iif(empty(thisbonus),[ ],transform(thisbonus))+[] thislinestr=thislinestr+[ | ]+iif(empty(thistotal),[ ],transform(thistotal))+[] endif thislinestr=thislinestr+[
]+chr(13) tstr=tstr+nvl(thislinestr,transform(transid)+[ ]+itemid) enddo enddo tstr=tstr+[

] *strtofile(tstr,(addbs(oprop.appstartpath)+[temp\debitsaleerror.txt])) %>
Receipt
<%=tstr%>