<% *This will insure to get the pending files count processedtime=datetime() bulkfolder=addbs(ADDBS(oprop.appstartpath)+'bulkdata') allfiles=0 remainingfiles=0 if directory(bulkfolder) allfiles=adir(filelist,bulkfolder+[\_*.txt]) remainingfiles=allfiles if allfiles>0 theresponse=[FOUND ]+ALLTRIM(TRANSFORM(allfiles))+[ Sale records ] *oJSON=NEWOBJECT('json','json.prg') IF TYPE([orequest])=[O] and NOT [NFJSON] $ SET("Procedure") SET PROCEDURE TO (ADDBS(oprop.appstartpath)+[prg\nfjson.FXP]) additive endif for tlst=1 to allfiles if datetime()-processedtime>3 exit endif tfile=bulkfolder+[\]+allt(filelist(tlst,1)) thefiledata=FILETOSTR(tfile) nfJsonToCursor(thefiledata, 'newtcsdata',.f.) SELECT [newtcsdata] go top ***** servicecharges=srvchgs mAccount=accountid NewNum=transid newdate=date newuser=opt newsaleman=iif(empty(saleman),[140000],saleman) newsess=sess newdtime=dtime if empty(newdtime) newdtime=datetime() endif newmemberid=invmemberid mcrit=invcrit newpayment=invpayment newtotal=invtotal newdiscount=invdiscount *newtotal=VAL(TRANSFORM(orequest.form('newtotal'))) *newdiscount=VAL(TRANSFORM(orequest.form('newdiscount'))) newname=custname newmemdisc=memdisc countersales='050000' &&TRANSFORM(orequest.form('countersales')) newspot=spot &&VAL(TRANSFORM(orequest.form('newspot'))) *mAccount=orequest.form('') usesafe([cashsale]) usesafe([cashdata]) usesafe([negatives]) usesafe([itemmast]) usesafe([accounts]) SELECT [cashsale] =SEEK(newnum,[cashsale],[transid]) IF EOF() GO bottom IF date<>DATE() salesrno=1 ELSE salesrno=daysrno+1 endif APPEND BLANK replace daysrno WITH salesrno ENDIF Replace CASHSALE.transid With NewNum,; CASHSALE.customer With COUNTERSALES,; CASHSALE.depositid With mAccount,; CASHSALE.Payment With newpayment,; CASHSALE.Date With newdate,; CASHSALE.modified With newdtime,; CASHSALE.saleman With newsaleman,; CASHSALE.Total With newtotal,; CASHSALE.discount WITH newdiscount,; cashsale.name WITH newname,; CASHSALE.crit With mcrit,; CASHSALE.opt With newuser,; CASHSALE.Sess With newsess,; CASHSALE.spot With newspot,; CASHSALE.dtime With newdtime,; CASHSALE.memdisc With newmemdisc,; cashsale.memberid WITH newmemberid,; cashsale.srvchgs WITH servicecharges,; cashsale.sql with .t. *COPY TO (TEMPLOCATION+[TMPINV.DBF]) salesrno=cashsale.daysrno TheResponse=[TRANSID:]+PADR(ALLTRIM(TRANSFORM(NewNum)),9,[ ])+ALLTRIM(TRANSFORM(salesrno)) SELECT [newtcsdata] Select "CashData" Set Order To transid =Seek(NewNum,"CashData","Transid") Do While cashdata.transid=NewNum And Not Eof("CashData") Delete If Not Eof() SKIP ELSE exit Endif Enddo SELECT [newtcsdata] totalcost=0 Scan =seek(newtcsdata.ItemID,[itemmast],[itemid]) Select "CASHDATA" Append Blank Replace cashdata.transid With NewNum,; cashdata.ItemID With newtcsdata.ItemID,; cashdata.Desc With newtcsdata.Name,; cashdata.qty With newtcsdata.qty,; cashdata.rate With newtcsdata.rate,; cashdata.dqty With newtcsdata.dqty,; cashdata.drate With newtcsdata.drate,; cashdata.discpcnt With newtcsdata.discpcnt,; cashdata.div With newtcsdata.div,; cashdata.Total With iif(empty(newtcsdata.dqty),newtcsdata.qty*newtcsdata.rate,newtcsdata.dqty*newtcsdata.drate),; cashdata.discount With newtcsdata.discount,; cashdata.sr_no With newtcsdata.no,; cashdata.saleman With newtcsdata.saleman if type([CASHDATA.vendor])=[C] and type([CASHDATA.purchase])=[C] replace CASHDATA.purchase WITH IIF(EMPTY(itemmast.pcost),itemmast.cost,itemmast.pcost),; CASHDATA.vendor WITH itemmast.vendor endif If xcompany.MEMP Replace SALEMAN With newtcsdata.SALEMAN Endif If xcompany.zerorecord And Seek(ItemID,'itemmast','itemid') And itemmast.stock0,stockdiff,0),; adjdata.out With iif(stockdiff<0,abs(stockdiff),0),; adjdata.rate With itemmast.cost,; adjdata.cost With itemmast.cost,; adjdata.Total With itemmast.cost*stockdiff,; adjdata.balance With suggestedstock select [adjust] =updatetransactions('Adjust',newtransid) endif ADDPROPERTY(ajaxresponse,'adjqty',oldadjqty) ADDPROPERTY(ajaxresponse,'oldstock',oldstock) ADDPROPERTY(ajaxresponse,'curstock',currentStock) ADDPROPERTY(ajaxresponse,'newstock',suggestedstock) ADDPROPERTY(ajaxresponse,'adjtime',processedtime) endif oResponse.ContentType = "text/plain" oresponse.write(oJson.stringify(ajaxresponse)) oresponse.flush %>