<% oJSON=NEWOBJECT('json','json.prg') oresponse.expires=-1 SET NULL off SET DELETED ON headdata=orequest.form('headdata') headdata=STRTRAN(headdata,[aaaa],[&]) ttype=orequest.form('thevtype') thetransid=orequest.form('thetransid') masterfile=lower(orequest.form('masterfile')) childfile=nvl(orequest.form('childfile'),'') if not empty(childfile) griddata=nvl(orequest.form('griddata'),'') if not empty(griddata) griddata=STRTRAN(griddata,[aaaa],[&]) endif endif theresponse='No Action' recordsadded=0 templocation=addbs(oprop.appstartpath)+'temp\' IF NOT [NFJSON] $ SET("Procedure") SET PROCEDURE TO (addbs(oprop.appstartpath)+[prg\nfjson.FXP]) additive endif nfJsonToCursor(headdata, 'newheaddata',.f.) select [newheaddata] scatter name mastervar if type([mastervar.sql])=[L] mastervar.sql=.t. endif usesafe('itemmast') usesafe(masterfile) newnum=[] *If uniquetr exists and not empty we should check the transaction and update if it exists *No matter any master file it may be if type([mastervar.uniquetr])=[C] newuniquetr=mastervar.uniquetr if not empty(newuniquetr) *We will add new record *If it is not we will add new record locate for uniquetr=newuniquetr if not eof() newnum=transid mastervar.transid=newnum gather name mastervar if not empty(childfile) tsql=[delete from (']+dbclocation+childfile+[') where transid=newnum ] &tsql tsql=[delete from (']+dbclocation+[stock') where transid=newnum and vtype=ttype] &tsql tsql=[delete from (']+dbclocation+[acctran') where transid=newnum and vtype=ttype] &tsql endif endif endif endif if empty(newnum) and (masterfile='cashsale' or masterfile='rcinvoice') *** If mastervar.spot>0 spotchar=Chr(mastervar.spot+64) Else spotchar=[] Endif SELECT (masterfile) MAXN=1 IF NOT EMPTY(SPOTCHAR) tsql=[SELECT TOP 1 TRANSID,VAL(SUBSTR(TRANSID,2)) AS VTR FROM (']+DBCLOCATION+masterfile+[') WHERE TRANSID=SPOTCHAR ORDER BY VTR DESC INTO CURSOR TX] &tsql IF EMPTY(VTR) NEWNUM=PADR(SPOTCHAR+[1],9) ELSE NEWNUM=PADR(SPOTCHAR+ALLTRIM(STR(VTR)),9) MAXN=VTR ENDIF ELSE tsql=[SELECT TOP 1 TRANSID,VAL(TRANSID) AS VTR FROM (']+DBCLOCATION+masterfile+[') WHERE BETWEEN(ASC(ALLTRIM(TRANSID)),48,57) ORDER BY VTR DESC INTO CURSOR TX] &tsql IF EMPTY(VTR) NEWNUM=PADR([1],9) ELSE NEWNUM=PADR(ALLTRIM(STR(VTR)),9) MAXN=VTR ENDIF ENDIF SELECT (masterfile) yestry=0 starttime=Seconds() servertime=datetime() NEWNUM=[] DO WHILE SEEK(NEWNUM,masterfile,[TRANSID]) MAXN=MAXN+1 NEWNUM=PADR(SPOTCHAR+ALLTRIM(STR(MAXN)),9) ENDDO if not empty(newnum) APPEND BLANK mastervar.transid=newnum *mastervar.uniquetr=newuniquetr gather name mastervar endif *UNLOCK *** endif if empty(newnum) and not (masterfile='cashsale' or masterfile='rcinvoice') usesafe(masterfile) tsql=[SELECT TOP 1 TRANSID,VAL(SUBSTR(TRANSID,2)) AS VTR FROM (']+DBCLOCATION+masterfile+[') ORDER BY VTR DESC INTO CURSOR TX] *return tsql &tsql MAXN=1 IF EMPTY(VTR) NEWNUM=PADR([1],9) ELSE NEWNUM=PADR(ALLTRIM(STR(VTR)),9) MAXN=VTR ENDIF SELECT (masterfile) *lockSuccess=.F. *yestry=0 starttime=Seconds() servertime=datetime() DO WHILE SEEK(NEWNUM,masterfile,[TRANSID]) MAXN=MAXN+1 NEWNUM=PADR(ALLTRIM(STR(MAXN)),9) ENDDO append BLANK mastervar.transid=newnum gather name mastervar if not empty(bk1loc) and directory(bk1loc,1) DELETE FROM (bk1loc+masterfile) WHERE transid=newnum INSERT INTO (bk1loc+masterfile) SELECT * FROM (dbclocation+masterfile) WHERE transid=newnum endif if not empty(bk2loc) and directory(bk2loc,1) DELETE FROM (bk2loc+masterfile) WHERE transid=newnum INSERT INTO (bk2loc+masterfile) SELECT * FROM (dbclocation+masterfile) WHERE transid=newnum endif endif if not empty(childfile) and not empty(griddata) nfJsonToCursor(griddata, 'newgriddata',.f.) usesafe(childfile) select 'newgriddata' scan scatter name gridvar if type([gridvar.sql])=[L] gridvar.sql=.t. endif gridvar.transid=newnum if inlist(lower(childfile),"cbilldata","billdata") =seek(gridvar.itemid,'itemmast','itemid') if eof('itemmast') select 'itemmast' append blank replace itemid with gridvar.itemid, name with gridvar.desc, pcost with gridvar.rate, ; stock with gridvar.qty, sale with gridvar.sale, cost with gridvar.rate endif endif select (childfile) append blank gather name gridvar select 'newgriddata' endscan if not empty(bk1loc) and directory(bk1loc,1) DELETE FROM (bk1loc+childfile) WHERE transid=newnum INSERT INTO (bk1loc+childfile) SELECT * FROM (dbclocation+childfile) WHERE transid=newnum endif if not empty(bk2loc) and directory(bk2loc,1) DELETE FROM (bk2loc+childfile) WHERE transid=newnum INSERT INTO (bk2loc+childfile) SELECT * FROM (dbclocation+childfile) WHERE transid=newnum endif endif if not empty(newnum) *if type([mastervar.sql])="U" or not mastervar.sql theresult=updatetransactions(ttype, newnum) * else * theresult=ttype+[: ]+newnum *endif ELSE theresult=[] endif return theresult %>