<% set null off set date ymd set cent on dateto =orequest.querystring("dateto") datefrom =orequest.querystring("datefrom") pcustomer =nvl(orequest.querystring("customerid"),[]) reportbase =orequest.querystring("reportbase") wheretext=[] thecustomername=[] REPTTITLE=[PROFIT BY CUSTOMER SUMMARY] REPTSECLINE=[] if isnull(dateto) or empty(ctod(dateto)) dateto=orequest.form("dateto") endif pdate2=ctod(dateto) if isnull(dateFROM) or empty(ctod(dateFROM)) dateto=orequest.form("dateFROM") endif pdate1=ctod(dateFROM) set date british wheretext=" AND X.accountid = Y.ACCOUNTID and (x.vtype=[Invoice] or x.vtype=[CreditMemo]) and x.itemid=z.itemid " ordertext=" order by y.name,y.accountid, x.date, x.transid " Do Case Case Empty(pdate1) And Empty(pdate2) * NEEDS NO CODE Case Empty(pdate1) And Not Empty(pdate2) wheretext=Alltrim(wheretext)+" And x.Date <= PDate2 " Case Not Empty(pdate1) And Empty(pdate2) wheretext=Alltrim(wheretext)+" And x.Date >= PDate1 " Case Not Empty(pdate1) And Not Empty(pdate2) wheretext=Alltrim(wheretext)+" And BETWEEN(x.Date,pdate1,pdate2) " Endcase If Not Empty(pcustomer) wheretext=Alltrim(wheretext)+" and x.Accountid=pCustomer " Endif if not empty(wheretext) wheretext=[where ]+subst(wheretext,5) endif set decimal to 4 tstr=[

### ]+REPTTITLE+[

]+reptsecline+[

] tsql=[ Select x.transid, x.date, x.In, x.out, x.rate, x.vtype, x.accountid, x.batch, ] tsql=tsql+[ x.cost, y.Name as acname, z.name as itname, z.packing, z.itemid ] tsql=tsql+[ from (']+dbclocation+[stock') x left join (']+dbclocation+[accounts') y on (x.accountid=y.accountid) ] tsql=tsql+[ left join (']+dbclocation+[itemmast') z on (x.itemid=z.itemid) ] tsql=tsql+[ Into Cursor tempcursor ]+wheretext+ordertext &tsql tstr=tstr+[
date | Voucher | NUM# | Details | QTY | SALE | COST | PROF | MKP%
--- | --- | --- | --- | --- | --- | --- | --- | ---
] go top store 0 to sumsale, sumrefunds, sumsalecost, sumrefundcost do while not eof() thisac=accountid thisname=acname tstr=tstr+[
]+allt(thisname)+[ (]+thisac+[)
] do while accountid=thisac and not eof() THISITEM=allt(nvl(itemid,[itemid])) THISitemname=allt(NVL(itname,[nomame])) thisqty=out-in thissale=rate*thisqty thiscost=cost*thisqty thisprofit=thissale-thiscost 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)) thissale=icase(thissale=round(thissale,0),round(thissale,0),thissale=round(thissale,2),round(thissale,2),thissale=round(thissale,3),round(thissale,3),round(thissale,4)) thiscost=icase(thiscost=round(thiscost,0),round(thiscost,0),thiscost=round(thiscost,2),round(thiscost,2),thiscost=round(thiscost,3),round(thiscost,3),round(thiscost,4)) thisprofit=icase(thisprofit=round(thisprofit,0),round(thisprofit,0),thisprofit=round(thisprofit,2),round(thisprofit,2),thisprofit=round(thisprofit,3),round(thisprofit,3),round(thisprofit,4)) profitpercentage=ROUND((1-(thiscost/IIF(thissale=0,1,thissale)))*100,2) thislinestr=[
] thislinestr=thislinestr+[]+iif(empty(date),[ ],transform(date))+[] thislinestr=thislinestr+[ | ]+iif(empty(vtype),[ ],transform(vtype))+[] thislinestr=thislinestr+[ | ]+iif(empty(transid),[ ],ALLT(transid))+[] thislinestr=thislinestr+[ | ]+itname+[] thislinestr=thislinestr+[ | ]+transform(thisqty)+[] thislinestr=thislinestr+[ | ]+transform(thissale)+[] thislinestr=thislinestr+[ | ]+transform(thiscost)+[] thislinestr=thislinestr+[ | ]+transform(thisprofit)+[] thislinestr=thislinestr+[ | ]+transform(profitpercentage)+[] thislinestr=thislinestr+[
]+chr(13) tstr=tstr+nvl(thislinestr,transform(transid)+[ ]+itemid) if thisqty>0 sumsale=sumsale+thissale sumsalecost=sumsalecost+thiscost else sumrefunds=sumrefunds-thissale sumrefundcost=sumrefundcost-thiscost endif skip enddo enddo tstr=tstr+[
Sales | ]+allt(transform(sumsale))+[] tstr=tstr+[ | Refunds | ]+allt(transform(sumrefunds))+[] tstr=tstr+[ | Net Sales | ]+allt(transform(sumsale-sumrefunds))+[
] totsaleprofit=round(sumsale - sumsalecost,0) totalrefundprofit=round(sumrefunds - sumrefundcost,0) totalnetproft=round(totsaleprofit - totalrefundprofit,0) tstr=tstr+[
Sale Profit | ]+allt(transform(totsaleprofit))+[] tstr=tstr+[ | Refund Profit | ]+allt(transform(totalrefundprofit))+[] tstr=tstr+[ | Net Profit | ]+allt(transform(totalnetproft))+[
] oprofitpercentage=ROUND((1-((sumsalecost+sumrefundcost)/IIF(sumsale+sumrefunds=0,1,sumsale+sumrefunds)))*100,2) tstr=tstr+[
Overall Markup% | ]+allt(transform(oprofitpercentage))+[
] tstr=tstr+[

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