<% set date ymd set century on set hours to 24 set mark to [-] expires=-1 ajaxresponse=CREATEOBJECT('empty') oJSON=NEWOBJECT('json','json.fxp') respmsg=[] hasdatainside=.f. m_transid=UPPER(ALLTRIM(NVL(orequest.form('m_transid'),'AUTO'))) m_saleman=UPPER(ALLTRIM(NVL(orequest.form('m_msaleman'),''))) m_salemanname=UPPER(ALLTRIM(NVL(orequest.form('m_msalemanname'),''))) m_tblid=UPPER(ALLTRIM(TRANSFORM(orequest.form('m_tblid')))) m_saveonly=UPPER(ALLTRIM(TRANSFORM(orequest.form('saveonly')))) m_date=orequest.form('m_date') if isnull(m_date) m_date=dtoc(date()) endif isadding=orequest.form('isadding') errormessage=[] IF m_saleman==m_salemanname && Add new vendor USEsafe([accounts]) FOR i=1 TO 9999 newvendor=[14]+PADL(ALLTRIM(TRANSFORM(i)),4,[0]) IF NOT SEEK(newvendor,[accounts],[accountid]) APPEND BLANK replace accountid WITH newvendor, name WITH m_salemanname exit endif endfor endif IF EMPTY(m_transid) or m_transid=[AUTO] tsql=[SELECT TOP 1 VAL(kotid) as vid FROM (']+dbclocation+[kot') ORDER BY vid DESC INTO CURSOR X] &tsql valkotid=vid+1 ordertime=datetime() ELSE valkotid=VAL(transform(m_transid)) ordertime=datetime() ENDIF tsql=[DELETE FROM (']+dbclocation+[kot') WHERE VAL(kotid)=valkotid] &tsql jsondata=orequest.Form('data-area') *Strtofile(jsondata,addbs(oprop.appstartpath)+[temp\jsondata.json]) Set Procedure To (addbs(oprop.appstartpath)+'json_new.fxp') Additive jsonObject=json_decode(jsondata) ** *tsql=[select top 1 * from (']+dbclocation+'kot'+[') where allt(transid)=='xxxxxx' order by transid into cursor griddatacursor readwrite] *&tsql usesafe('kot') tcounter=0 newitemidsadded=0 if type([jsonObject._1])=[O] do while .t. tcounter=tcounter+1 noerror=.t. c_param=[jsonObject._]+allt(transform(tcounter)) IF type(c_param)<>[O] exit endif with &c_param titemid=allt(upper(.get(1))) if empty(.get(1)) Loop endif tname=ALLTRIM(upper(.get(2))) tsaleintax=.get(3) ttotal=.get(4) tqty=val(ttotal)/val(tsaleintax) ENDWITH *Check if itemid exists. If not add the next itemid USEsafe('asctable') usesafe('itemmast') thisitemid=PADR(ALLTRIM(titemid),LEN(itemid)) itemnotfound=.f. DO case CASE SEEK(thisitemid,[asctable],[bar_code]) titemid=asctable.itemid CASE SEEK(thisitemid,[itemmast],[bar_code]) titemid=itemmast.itemid CASE SEEK(thisitemid,[itemmast],[itemid]) titemid=itemmast.itemid OTHERWISE itemnotfound=.t. endcase SELECT [itemmast] itisownitem=.f. if itemnotfound *first to check if itemid is a number itisanumber=.t. for tc=1 to len(titemid) if not between(asc(subst(titemid,tc,1)),48,57) itisanumber=.f. exit endif endfor willadd=.t. if not itisanumber tsql=[select itemid from itemmast where allt(name)==allt(tname) into cursor x] &tsql if _tally>0 titemid=itemid else newitemidsadded=newitemidsadded+1 *** If Not Empty(xcompany.itemstrt) cbstart=xcompany.itemstrt Else cbstart=100 Endif cbend=9999999999999 If Empty(xcompany.secstart) secstart='' Else secstart=ALLTRIM(xcompany.secstart) Endif * secstart='' lentcode=Len(secstart+Alltrim(Str(cbend,16,0))) Local myI SELECT [itemmast] SET ORDER TO valitemid DESCENDING GO top LOCATE FOR isown IF NOT EOF() vitem=VAL(itemid) else SELECT TOP 1 itemid, VAL(itemid) as tvitem FROM itemmast WHERE isown ORDER BY tvitem DESC INTO CURSOR xc vitem=tvitem endif IF EMPTY(vitem) secstart=[] ENDIF IF VAL(secstart)>0 secstart=[] endif cbstart=MAX(100,vitem,cbstart) USE IN SELECT('xc') SELECT [itemmast] For myI=cbstart To cbend newbarCode=secstart+Alltrim(Str(myI,lentcode,0)) If Not Seek(newbarCode,[itemmast],"itemid") And Not Seek(newbarCode,[itemmast],"Bar_code") Locate For Val(ItemID)=Val(newbarCode) And Val(newbarCode)<>0 If Not Eof() Loop Endif newisown=newbarcode Exit Endif ENDFOR *** titemid=newbarcode itisownitem=.t. ENDIF endif select [itemmast] if not seek(titemid,[itemmast],[itemid]) respmsg=respmsg+transform(lineno())+[ adding new item to data. ]+titemid+[ ] append blank replace itemid with titemid, name with tname, sale with val(tsaleintax), type with 'Inventory',; saleac with '090001', costac with '120001', stockac with '020001', isown WITH itisownitem else replace itemid with titemid, name with tname, sale with val(tsaleintax), type with 'Inventory',; saleac with '090001', costac with '120001', stockac with '020001', isown WITH itisownitem endif use in select([itemmast]) ENDIF *Now adding data if tqty<>0 hasdatainside=.t. SELECT [kot] APPEND BLANK replace ordtime with ordertime, date with ctod(m_date), no WITH tcounter, kotid with allt(transform(valkotid)), ; itemid WITH titemid , name WITH tname, ; rate WITH VAL(tsaleintax), qty WITH tqty, ; dtime with ordertime, saleman with m_saleman, opt with m_tblid,; modified with datetime() endif enddo if not empty(bk1loc) and directory(bk1loc,1) tsql=[insert into (']+bk1loc+[kot') (ordtime, date, no, kotid, itemid, name, rate, qty, dtime, saleman, opt, modified) select ] tsql=tsql+[ ordtime, date, no, kotid, itemid, name, rate, qty, dtime, saleman, opt, modified from (']+dbclocation+[kot') ] tsql=tsql+[ where val(kotid)=valkotid] &tsql endif if not empty(bk2loc) and directory(bk2loc,1) tsql=[insert into (']+bk2loc+[kot') (ordtime, date, no, kotid, itemid, name, rate, qty, dtime, saleman, opt, modified) select ] tsql=tsql+[ ordtime, date, no, kotid, itemid, name, rate, qty, dtime, saleman, opt, modified from (']+dbclocation+[kot') ] tsql=tsql+[ where val(kotid)=valkotid] &tsql endif ENDIF ** if hasdatainside if m_saveonly=[PRINT] if not directory(addbs(oprop.appstartpath)+'kots',1) md (addbs(oprop.appstartpath)+'kots') endif tsql=[SELECT distinct x.kotid,y.extra FROM (']+dbclocation+[kot') x LEFT JOIN (']+dbclocation+[itemmast') y ON (x.itemid=y.itemid) ] tsql=tsql+[ WHERE VAL(kotid)=valkotid AND NOT EMPTY(y.extra) ORDER BY y.extra INTO CURSOR theprinterlist] &tsql printouts=_tally IF printouts>0 strtofile(tsql,addbs(oprop.appstartpath)+'kots\'+allt(transform(valkotid))+'.txt') endif endif ADDPROPERTY(ajaxresponse,'terror','') else ADDPROPERTY(ajaxresponse,'terror','true') errormessage=errormessage+[ no valid data!] endif ADDPROPERTY(ajaxresponse,'m_transid',m_transid) ADDPROPERTY(ajaxresponse,'m_saleman',m_saleman) ADDPROPERTY(ajaxresponse,'m_salemanname',m_salemanname) ADDPROPERTY(ajaxresponse,'m_tblid',m_tblid) SET DATE BRITISH ADDPROPERTY(ajaxresponse,'tmessage',errormessage+respmsg) TheResponse=[TRANSID:]+PADR(ALLTRIM(TRANSFORM(valkotid)),9,[ ]) ADDPROPERTY(ajaxresponse,'updateresponse',theresponse) oresponse.write(ojson.stringify(ajaxresponse)) oresponse.flush() %>