<% set date ymd set cent on datefrom =orequest.querystring("datefrom") dateto =orequest.querystring("dateto") reportbase =orequest.querystring("reportbase") pdate1=ctod(datefrom) pdate2=ctod(dateto) set date british counternumber =val(transform(orequest.querystring("counternumber"))) categoryname= allt(orequest.querystring("category")) classname= allt(orequest.querystring("class")) wheretext=[] reptsecline='' if reportbase='class' REPTTITLE=classname+[ ITEMS SUMMARY] else REPTTITLE=categoryname+[ ITEMS SUMMARY] endif 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 if reportbase='class' do case case empty(classname) case classname=[ALL CLASSES] case classname=[NO CLASSES] wheretext=wheretext+[ and empty(y.packing) ] REPTTITLE=REPTTITLE+' (NO CATEGORY GIVEN) ' otherwise wheretext=wheretext+[ and allt(y.ALMARA)==']+classname+['] REPTTITLE=REPTTITLE+' ('+classname+')' endcase else 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 endif 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+[
Item# | Item Name | Sales | Refunds | Net Sales | Net Cost | Net Profit | Margin
--- | --- | --- | --- | --- | --- | --- | ---
] 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+[]+iif(empty(THISitemid),[NO ITEM ID],ALLT(THISitemid))+[] tstr=tstr+[ | ]+iif(empty(THISitemname),[NO ITEM NAME],ALLT( THISitemname))+[] tstr=tstr+[ | ]+iif(empty(thissale),[ ],ALLT(transform(thissale,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(thisreturns),[ ],ALLT(transform(thisreturns,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(thissale-thisreturns),[ ],ALLT(transform(thissale-thisreturns,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(thiscostSale-thiscostRet),[ ],ALLT(transform(thiscostSale-thiscostRet,[99999999999999.99])))+[] thisprofet=thissale-thisreturns-(thiscostSale-thiscostRet) if thissale-thisreturns<>0 thisprofetMargin=round(thisprofet*100/(thissale-thisreturns),2) else thisprofetMargin=0.00 endif tstr=tstr+[ | ]+iif(empty(thisprofet),[ ],ALLT(transform(thisprofet,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(thisprofetMargin),[ ],ALLT(transform(thisprofetMargin,[99999999999999.99]))+[%])+[] tstr=tstr+[
]+chr(13) tthissale=tthissale+thissale thisreturns=thisreturns+thisreturns tthiscost=tthiscost+thiscostSale-thiscostRet tthisprofet=tthisprofet+thisprofet enddo tstr=tstr+[ | TOTALs:] tstr=tstr+[ | ]+iif(empty(tthissale),[ ],ALLT(transform(tthissale,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(tthisreturns),[ ],ALLT(transform(tthisreturns,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(tthissale-tthisreturns),[ ],ALLT(transform(tthissale-tthisreturns,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(tthiscost),[ ],ALLT(transform(tthiscost,[99999999999999.99])))+[] tthisprofet=tthissale-tthisreturns-(tthiscost) if tthissale-tthisreturns<>0 tthisprofetMargin=round(tthisprofet*100/(tthissale-tthisreturns),2) else tthisprofetMargin=0.00 endif tstr=tstr+[ | ]+iif(empty(tthisprofet),[ ],ALLT(transform(tthisprofet,[99999999999999.99])))+[] tstr=tstr+[ | ]+iif(empty(tthisprofetMargin),[ ],ALLT(transform(tthisprofetMargin,[99999999999999.99]))+[%])+[] tstr=tstr+[]+chr(13) tstr=tstr+[

] %>
Receipt
<>