<% oresponse.expires=-1 SET NULL off SET DELETED ON pref=padl(ALLTRIM(TRANSFORM(NVL(orequest.form('txtreffid'),''))),9) fref=allt(pref) theaction=orequest.form('taction') thevoucher=orequest.form('vouchertype') thedata=orequest.form('thedata') thecommand=orequest.form('theoperation') theresponse=theaction+[ requires code ] recordsadded=0 templocation=addbs(oprop.appstartpath)+'temp\' if theaction='list' oJSON=NEWOBJECT('json','json.fxp') IF NOT [NFJSON] $ SET("Procedure") SET PROCEDURE TO (addbs(oprop.appstartpath)+[prg\nfjson.FXP]) additive endif tbl=orequest.form('tablename') dt1=orequest.form('from_dt') dt2=orequest.form('to_Dt') tsql=[select top 500 * from ("]+dbclocation+[]+tbl+[") order by date into cursor listcursor ] &tsql oResponse.ContentType = "application/xml;charset=windows-1252" CURSORTOXML('listcursor','thelist',1,0,0,'1') oresponse.write(thelist) oresponse.flush close tables close data return '' endif if inlist(theaction,[TOP],[PREV],[NEXT],[NUM],[BOTT]) if theaction="PREV" vtr='' do case case len(fref)=0 case len(fref)=1 and empty(val(fref)) VTR=[ HAVING PTRANSID<']+PTRANSID+[' ] case val(fref)<>0 vtr=allt(transform(val(fref))) VTR=[ HAVING vtr<]+allt(transform(val(fref))) otherwise for tcntr=2 to len(fref) if val(subst(fref,tcntr-1))=0 and val(subst(fref,tcntr))<>0 vtr=allt(transform(val(subst(fref,tcntr)))) cPref=left(fref,tcntr-1) VTR=[ HAVING vtr<=]+allt(transform(val(subst(fref,tcntr))))+[ and ptransid<']+pref+[' ] exit endif endfor endcase ENDIF if theaction="NEXT" vtr='' do case case len(fref)=0 case len(fref)=1 and empty(val(fref)) VTR=[ HAVING PTRANSID<']+PTRANSID+[' ] case val(fref)<>0 vtr=allt(transform(val(fref))) VTR=[ HAVING vtr>=]+allt(transform(val(fref)))+[ and ptransid>']+pref+['] otherwise for tcntr=2 to len(pref) if val(subst(pref,tcntr-1))=0 and val(subst(pref,tcntr))<>0 vtr=allt(transform(val(subst(pref,tcntr)))) cPref=left(pref,tcntr-1) VTR=[ HAVING vtr>=]+allt(transform(val(subst(pref,tcntr))))+; [ and (left(ptransid,]+transform(tcntr-1)+[))>']+cpref+[' or vtr>]+allt(transform(val(subst(pref,tcntr)))) exit endif endfor endcase ENDIF tsql=[select top 1 transid,IIF(VAL(transid)=0,VAL(SUBSTR(transid,2)),VAL(transid)) AS VTR, padl(allt(transid),9) as ptransid ] tsql=tsql+[ from ("]+dbclocation+'cashsale.dbf'+[") ] do case case theaction='TOP' or (theaction='PREV' and empty(fref)) tsql=tsql+[ order by vtr, ptransid ] case theaction='BOT' or (theaction='NEXT' and empty(fref)) tsql=tsql+[ order by vtr desc, ptransid desc ] CASE theaction='PREV' tsql=tsql+[ order by vtr desc, ptransid desc ] tsql=tsql+vtr CASE theaction='NEXT' tsql=tsql+[ order by vtr, ptransid ] tsql=tsql+vtr CASE THEACTION='NUM' tsql=tsql+[ having ptransid=']+pref+[' order by ptransid ] ENDCASE tsql=tsql+[ into cursor gotrecords ] err=.f. *try &tsql *catch * err=.t. *endtry if err theresponse=[{"transid":"","cmessage","Record not found!","cerror":"]+tsql+["}] endif if _tally=0 theresponse=[{"transid":"","cmessage","Record not found!","cerror":"","sql","]+tsql+["}] else theresponse=[{"transid":"]+transid+[","cmessage","Record found!","cerror":"","sql","]+tsql+["}] endif ENDIF if _tally>0 thetransid=transid oJSON=NEWOBJECT('json','json.fxp') IF NOT [NFJSON] $ SET("Procedure") SET PROCEDURE TO (addbs(oprop.appstartpath)+[prg\nfjson.fxp]) additive endif tsql=[select * from ("]+dbclocation+'cashsale.dbf'+[") where transid=']+thetransid+[' into cursor masterData] &tsql tsql=[select * from ("]+dbclocation+'cashdata.dbf'+[") where transid=']+thetransid+[' order by sr_no into cursor childData] &tsql childrows=_tally tsql=[select distinct accountid, name from ("]+dbclocation+'accounts.dbf'+[") where accountid ] tsql=tsql+[ in (select distinct saleman from 'childData') or inlist(accountid,"]+masterdata.customer+[","]+masterdata.depositid+[","]+masterdata.saleman+[")] tsql=tsql+[ into cursor accountData order by accountid ] &tsql ajaxresponse=CREATEOBJECT('empty') ADDPROPERTY(ajaxresponse,'masterrecs',RECCOUNT('masterData')) ADDPROPERTY(ajaxresponse,'childrecs',RECCOUNT('childData')) if .f. oResponse.ContentType = "text/plain" ojson.keyforcursors='masterData' theMaster=oJSON.stringify('masterData') ojson.keyforcursors='childData' theChild=oJSON.stringify('childData') else oResponse.ContentType = "application/xml;charset=windows-1252" CURSORTOXML('masterData','theMaster',1,0,0,'1') theMaster=chr(13)+chr(10)+"*masterDataStart*"+themaster+"*masterDataEnd*"+chr(13)+chr(10) CURSORTOXML('childData','theChild',1,0,0,'1') theChild=chr(13)+chr(10)+"*childDataStart*"+theChild+"*childDataEnd*"+chr(13)+chr(10) CURSORTOXML('accountData','theAcs',1,0,0,'1') theAcs=chr(13)+chr(10)+"*acsDataStart*"+theAcs+"*acsDataEnd*"+chr(13)+chr(10) *** endif returnstring=oJSON.AddJSONProps(theMaster,theChild) returnstring=oJSON.AddJSONProps(returnstring,theAcs) returnstring=oJSON.AddJSONProps(ojson.stringify(ajaxresponse),returnstring) oResponse.Write(oJSON.addjsonprops(theresponse,returnstring)) else oresponse.write(theresponse) endif oresponse.flush close tables close data %>