<% searchAction=lower(ALLTRIM(TRANSFORM(NVL(orequest.form('action'),'')))) searchTerm=UPPER(ALLTRIM(TRANSFORM(NVL(orequest.form('searchTerm'),'')))) searchTerm=CHRTRAN(searchTerm,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ]) searchText=UPPER(ALLTRIM(TRANSFORM(NVL(orequest.form('searchText'),'')))) searchText=CHRTRAN(searchText,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ]) searchTerm=UPPER(ALLTRIM(TRANSFORM(NVL(orequest.form('searchTerm'),'')))) vouchertype=lower(ALLTRIM(TRANSFORM(NVL(orequest.form('vouchertype'),'')))) ojson=NEWOBJECT('json','json.fxp') ajaxResponse=CREATEOBJECT('empty') ADDPROPERTY(ajaxresponse,'searchAction',searchAction) ADDPROPERTY(ajaxresponse,'vouchertype',vouchertype) ADDPROPERTY(ajaxresponse,'searchTerm',searchTerm) resultdata='{"warning":"No action has been defined"}' DO case CASE searchAction='itemsearch' and vouchertype='sale' IF [:] $ searchterm tcode=ALLTRIM(SUBSTR(searchterm,1,AT([:],searchterm)-1)) tname=ALLTRIM(SUBSTR(searchterm,AT([:],searchterm)+1)) ELSE tcode=searchterm isitnum=.t. FOR i=1 TO LEN(tcode) IF NOT BETWEEN(ASC(SUBSTR(tcode,i,1)),48,57) isitnum=.f. exit endif ENDFOR IF isitnum tname=[] ELSE tname=tcode endif endif tsql=[SELECT distinct itemid, ALLTRIM(name) as name, sale, packing as depart, ] tsql=tsql+[ pcost as rate, taxprate as tax FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE allt(itemid)=="]+tcode+[" or ] tsql=tsql+[ allt(bar_code)=="]+tcode+[" or itemid in (select itemid from ("]+dbclocation+[asctable.dbf]+[") ] tsql=tsql+[ where ALLTRIM(bar_code)==']+tcode+[') INTO CURSOR results readwrite ] &tsql ADDPROPERTY(ajaxresponse,'recordsFound',_tally) do case case _tally=0 append blank replace itemid WITH tcode, name WITH tname ojson.keyforcursors='results' resultData=oJSON.stringify('results') case _tally=1 ojson.keyforcursors='results' resultData=oJSON.stringify('results') other endcase *** CASE searchAction='itemsearch' and vouchertype='itemmast' IF [:] $ searchterm tcode=ALLTRIM(SUBSTR(searchterm,1,AT([:],searchterm)-1)) tname=ALLTRIM(SUBSTR(searchterm,AT([:],searchterm)+1)) ELSE tcode=searchterm isitnum=.t. FOR i=1 TO LEN(tcode) IF NOT BETWEEN(ASC(SUBSTR(tcode,i,1)),48,57) isitnum=.f. exit endif ENDFOR IF isitnum tname=[] ELSE tname=tcode endif ENDIF *temptablefile=ADDBS(oprop.appstartpath)+[temp\tmptable.dbf] tsql=[SELECT packing as depart, ] tsql=tsql+[ pcost as rate, taxprate as tax,* FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE allt(itemid)=="]+tcode+[" or ] tsql=tsql+[ allt(bar_code)=="]+tcode+[" or itemid in (select itemid from ("]+dbclocation+[asctable.dbf]+[") ] tsql=tsql+[ where ALLTRIM(bar_code)==']+tcode+[') INTO cursor results readwrite ] &&+temptablefile &tsql ADDPROPERTY(ajaxresponse,'recordsFound',_tally) do case case _tally=0 append blank replace itemid WITH tcode, name WITH tname ojson.keyforcursors='results' resultData=oJSON.stringify('results') case _tally=1 *alter table (temptablefile) drop column photo ojson.keyforcursors='results' resultData=oJSON.stringify('results') other *alter table (temptablefile) drop column photo ojson.keyforcursors='results' resultData=oJSON.stringify('results') endcase *** CASE searchAction='itemsearch' and vouchertype='purchase' IF [:] $ searchterm tcode=ALLTRIM(SUBSTR(searchterm,1,AT([:],searchterm)-1)) tname=ALLTRIM(SUBSTR(searchterm,AT([:],searchterm)+1)) ELSE tcode=searchterm isitnum=.t. FOR i=1 TO LEN(tcode) IF NOT BETWEEN(ASC(SUBSTR(tcode,i,1)),48,57) isitnum=.f. exit endif ENDFOR IF isitnum tname=[] ELSE tname=tcode endif endif tsql=[SELECT distinct itemid, ALLTRIM(name) as name, sale, packing as depart, ] tsql=tsql+[ pcost as rate, taxprate as tax FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE allt(itemid)=="]+tcode+[" or ] tsql=tsql+[ allt(bar_code)=="]+tcode+[" or itemid in (select itemid from ("]+dbclocation+[asctable.dbf]+[") ] tsql=tsql+[ where ALLTRIM(bar_code)==']+tcode+[') INTO CURSOR results readwrite ] &tsql ADDPROPERTY(ajaxresponse,'recordsFound',_tally) do case case _tally=0 append blank replace itemid WITH tcode, name WITH tname ojson.keyforcursors='results' resultData=oJSON.stringify('results') case _tally=1 ojson.keyforcursors='results' resultData=oJSON.stringify('results') other endcase endcase oResponse.ContentType = "text/plan" oresponse.write(ojson.addJsonProps(ojson.stringify(ajaxResponse),resultdata)) *oresponse.write(ojson.stringify(ajaxResponse)) oresponse.flush() %>