<% set date ymd set cent on datefrom =orequest.querystring("datefrom") dateto =orequest.querystring("dateto") pdate1=ctod(datefrom) pdate2=ctod(dateto) set date british counternumber =val(transform(orequest.querystring("counternumber"))) categoryname= allt(orequest.querystring("category")) wheretext=[] reptsecline='' REPTTITLE=categoryname+[ ITEMS SUMMARY] Do Case Case Empty(pdate1) And Empty(pdate2) Case Empty(pdate1) And Not Empty(pdate2) wheretext=Alltrim(wheretext)+" And x.Date <= PDate2 " reptsecline='TILL '+DTOC(PDATE2) Case Not Empty(pdate1) And Empty(pdate2) wheretext=Alltrim(wheretext)+" And x.Date >= PDate1 " reptsecline='FROM '+DTOC(PDATE1) Case Not Empty(pdate1) And Not Empty(pdate1) wheretext=Alltrim(wheretext)+" And BETWEEN(x.Date,pdate1,pdate2) " reptsecline='FROM '+DTOC(PDATE1)+' TO '+DTOC(PDATE2) Endcase do case case empty(categoryname) case categoryname=[ALL CATEGORIES] case categoryname=[NO CATEGORY] wheretext=wheretext+[ and empty(y.packing) ] REPTTITLE=REPTTITLE+' (NO CATEGORY GIVEN) ' otherwise wheretext=wheretext+[ and allt(y.packing)==']+categoryname+['] REPTTITLE=REPTTITLE+' ('+categoryname+')' endcase if not counternumber<0 wheretext=Alltrim(wheretext)+" And x.spot >= ?counternumber " REPTTITLE=REPTTITLE+' ON SPOT '+TRANSFORM(counternumber) endif wheretext=wheretext+" AND INLIST(x.vtype,[CashSale],[Invoice],[CreditMemo],[CREFUND]) " If Not(Empty(wheretext)) wheretext=" where "+Substr(wheretext,5) Endif tstr=[

]+REPTTITLE+[


]+reptsecline+[] ordertext=" order by y.name, y.itemid, x.date, x.vtype " tsql=[Select x.In, x.out, x.rate, x.transid, x.vtype, x.date, x.cost, y.Name, y.packing, y.almara, X.ItemID, z.incomep ] tsql=tsql+[ from (']+dbclocation+[stock') x LEFT JOIN (']+dbclocation+[itemmast') y ON (X.ITEMID=Y.ITEMID) ] tsql=tsql+[ LEFT JOIN (']+dbclocation+[depart') Z ON(Y.PACKING=Z.DEPART) into cursor 'tempcursor' ] tsql=tsql+wheretext+ordertext try &tsql catch tstr=[Has error] endtry if _tally=0 return [No records found with current criteria] endif tstr=tstr+[] store 0 to tthissale, tthisreturns, tthiscost, tthisprofet do while not eof() thisitemid=itemid THISitemname=NVL(name,[]) tstr=tstr+[] store 0 to thissale, thisreturns, thiscostSale,THISCOSTRET, thisprofet do while not eof() and itemid=thisitemid if in-out > 0 thisreturns=thisreturns+((in-out)*rate) thiscostRet=thiscostRet+((in-out)*cost) else thissale=thissale+((out-in)*rate) thiscostSale=thiscostSale+((out-in)*cost) endif skip enddo tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] thisprofet=thissale-thisreturns-(thiscostSale-thiscostRet) if thissale-thisreturns<>0 thisprofetMargin=round(thisprofet*100/(thissale-thisreturns),2) else thisprofetMargin=0.00 endif tstr=tstr+[] tstr=tstr+[] tstr=tstr+[]+chr(13) tthissale=tthissale+thissale thisreturns=thisreturns+thisreturns tthiscost=tthiscost+thiscostSale-thiscostRet tthisprofet=tthisprofet+thisprofet enddo tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] tstr=tstr+[] tthisprofet=tthissale-tthisreturns-(tthiscost) if tthissale-tthisreturns<>0 tthisprofetMargin=round(tthisprofet*100/(tthissale-tthisreturns),2) else tthisprofetMargin=0.00 endif tstr=tstr+[] tstr=tstr+[] tstr=tstr+[]+chr(13) tstr=tstr+[
Item#CategorySalesRefundsNet SalesNet CostNet ProfitMargin
]+iif(empty(THISitemid),[NO ITEM ID],ALLT(THISitemid))+[]+iif(empty(THISitemname),[NO ITEM NAME],ALLT( THISitemname))+[]+iif(empty(thissale),[ ],ALLT(transform(thissale,[99999999999999.99])))+[]+iif(empty(thisreturns),[ ],ALLT(transform(thisreturns,[99999999999999.99])))+[]+iif(empty(thissale-thisreturns),[ ],ALLT(transform(thissale-thisreturns,[99999999999999.99])))+[]+iif(empty(thiscostSale-thiscostRet),[ ],ALLT(transform(thiscostSale-thiscostRet,[99999999999999.99])))+[]+iif(empty(thisprofet),[ ],ALLT(transform(thisprofet,[99999999999999.99])))+[]+iif(empty(thisprofetMargin),[ ],ALLT(transform(thisprofetMargin,[99999999999999.99]))+[%])+[
TOTALs:]+iif(empty(tthissale),[ ],ALLT(transform(tthissale,[99999999999999.99])))+[]+iif(empty(tthisreturns),[ ],ALLT(transform(tthisreturns,[99999999999999.99])))+[]+iif(empty(tthissale-tthisreturns),[ ],ALLT(transform(tthissale-tthisreturns,[99999999999999.99])))+[]+iif(empty(tthiscost),[ ],ALLT(transform(tthiscost,[99999999999999.99])))+[]+iif(empty(tthisprofet),[ ],ALLT(transform(tthisprofet,[99999999999999.99])))+[]+iif(empty(tthisprofetMargin),[ ],ALLT(transform(tthisprofetMargin,[99999999999999.99]))+[%])+[
] %> SSSoft™ - <%=XCOMPANY.NAME%> Receipt
<>