<% fbrlog=[Starting: ] STRTOFILE(fbrlog,addbs(oprop.appstartpath)+[temp\fbrlog.txt]) invoicenumber=orequest.form('invoicenumber') cFBRPOSID=allt(transform(nvl(orequest.form('cFBRPOSID'),''))) if empty(cFBRPOSID) cFBRPOSID=allt(xcompany.fbrposid) endif oldmark=SET("Mark") olddate=SET("Date") oldhours=SET("Hours") SET DATE ymd SET MARK TO [-] SET HOURS TO 24 *createtime=TTOC(newdtime) senderpc=orequest.form('senderpc') newnum=padr(allt(transform(invoicenumber)),9,[ ]) usesafe([cashsale]) usesafe([cashdata]) usesafe([itemmast]) SELECT [cashsale] =SEEK(newnum,[cashsale],[transid]) **** newdtime=dtime if empty(newdtime) newdtime=datetime() endif thisdate=newdtime numformated=[] IF EOF() OR EMPTY(fbrpost) yearstr=[CS]+SUBSTR(ALLTRIM(TRANSFORM(YEAR(thisdate))),3,2) monthstr=PADL(ALLTRIM(TRANSFORM(MONTH(thisdate))),2,[0]) daystr=PADL(ALLTRIM(TRANSFORM(day(thisdate))),2,[0]) FOR i=1 TO 9999 numstr=PADL(ALLTRIM(TRANSFORM(i)),4,[0]) numformated=yearstr+monthstr+daystr+numstr IF NOT indexSEEK(numformated,.f.,'cashsale','fbrpost') EXIT endif ENDFOR SELECT [cashsale] Else numformated=fbrpost ENDIF ***** SELECT [cashsale] =SEEK(newnum,[cashsale],[transid]) replace fbrpost with numformated SET HOURS TO 24 createtime=TTOC(newdtime) SET HOURS TO &oldhours *TheResponse=[TRANSID:]+PADR(ALLTRIM(TRANSFORM(NewNum)),9,[ ])+ALLTRIM(TRANSFORM(salesrno)) Select "CashData" Set Order To transid =Seek(NewNum,"CashData","Transid") TotalBillAmount=0 TotalTaxCharged=0 totalquantity=0 TotalSaleValue=0 TotalDiscount=0 **** totalcost=0 invtxttop=[{] ismore=0 fbrlog=fbrlog+CHR(13)+[before data ] STRTOFILE(fbrlog,addbs(oprop.appstartpath)+[temp\fbrlog.txt]) do while not eof() and transid=newnum IF ismore>0 invtxttop=invtxttop+[,{] ELSE ismore=ismore+1 endif **** titem=cashdata.itemid =seek(titem,[itemmast],[itemid]) thetaxAmount=NVL(itemmast.taxRate,0.00) thetaxRate=NVL(itemmast.taxprate,0.00) billAmount=ROUND((cashdata.Dqty*cashdata.Drate),2) TotalBillAmount=TotalBillAmount+billAmount IF NOT EMPTY(thetaxRate) TaxPercentage=thetaxRate SaleExcludingTax=ROUND(billAmount/(1+(TaxPercentage/100)),2) TaxCharged=BillAmount-SaleExcludingTax ELSE TaxCharged=ROUND(qty*theTaxAmount,2) SaleExcludingTax=billAmount-TaxCharged TaxPercentage=ROUND(TaxCharged*100/SaleExcludingTax,2) endif TotalSaleValue=TotalSaleValue+SaleExcludingTax totalquantity=totalquantity+ROUND(cashdata.Dqty,2) TotalDiscount=TotalDiscount+ROUND(cashdata.discount,2) TotalTaxCharged=TotalTaxCharged+TaxCharged invtxttop=invtxttop+["ItemCode":"]+allt(itemid)+[",] invtxttop=invtxttop+["ItemName":"]+allt(desc)+[",] invtxttop=invtxttop+["Quantity":]+allt(transform(cashdata.Dqty,'99999999.99'))+[,] invtxttop=invtxttop+["PCTCode":"11001010",] invtxttop=invtxttop+["TaxRate":]+allt(transform(TaxPercentage,'99999999.99'))+[,] invtxttop=invtxttop+["SaleValue":]+allt(transform(SaleExcludingTax,'99999999.99'))+[,] invtxttop=invtxttop+["TotalAmount":]+allt(transform(TotalBillAmount,'99999999.99'))+[,] invtxttop=invtxttop+["TaxCharged":]+allt(transform(TaxCharged,'99999999.99'))+[,] invtxttop=invtxttop+["Discount":]+allt(transform(cashdata.discount,'99999999.99'))+[,] invtxttop=invtxttop+["FurtherTax":0.00,] invtxttop=invtxttop+["InvoiceType":1,] invtxttop=invtxttop+["RefUSIN":null] invtxttop=invtxttop+[}] *if type([fbr])=[L] replace fbr with .t., tax1 WITH taxCharged *endif skip ENDdo fbrlog=fbrlog+CHR(13)+[after data ] STRTOFILE(fbrlog,addbs(oprop.appstartpath)+[temp\fbrlog.txt]) SELECT [cashdata] use **** invTxtJson=[] invtxtJson=invTxtJson+[{"InvoiceNumber":"",] invtxtJson=invTxtJson+["POSID":"]+alltrim(cFBRPOSID)+[",] invtxtJson=invTxtJson+["USIN":"USIN]+allt(numformated)+[",] invtxtJson=invTxtJson+["DateTime":"]+createtime+[",] invtxtJson=invTxtJson+["BuyerNTN":"",] invtxtJson=invTxtJson+["BuyerCNIC":"",] invtxtJson=invTxtJson+["BuyerName":"",] invtxtJson=invTxtJson+["BuyerPhoneNumber":"",] invtxtJson=invTxtJson+["TotalBillAmount":]+allt(transform(TotalBillAmount,'9999999999.99'))+[,] invtxtJson=invTxtJson+["TotalQuantity":]+allt(transform(TotalQuantity,'9999999999.99'))+[,] invtxtJson=invTxtJson+["TotalSaleValue":]+allt(transform(TotalSaleValue,'9999999999.99'))+[,] invtxtJson=invTxtJson+["TotalTaxCharged":]+allt(transform(TotalTaxCharged,'9999999999.99'))+[,] invtxtJson=invTxtJson+["Discount":]+allt(transform(TotalDiscount,'9999999999.99'))+[,] invtxtJson=invTxtJson+["FurtherTax":0.00,] invtxtJson=invTxtJson+["PaymentMode":1,] invtxtJson=invTxtJson+["RefUSIN":null,] invtxtJson=invTxtJson+["InvoiceType":1,] invtxtJson=invTxtJson+["Items":]+'[' invtxtJson=invTxtJson+invtxttop+']}' CLOSE TABLES close DATA fbrlog=fbrlog+CHR(13)+[before send ] STRTOFILE(fbrlog,addbs(oprop.appstartpath)+[temp\fbrlog.txt]) msxml=CREATEOBJECT('msxml2.xmlhttp') *lhost=[http://localhost:8524/api/IMSFiscal/Get] lhost=[http://localhost:8524/api/IMSFiscal/GetInvoiceNumberByModel] sandbox=[https://esp.fbr.gov.pk:8244/FBR/v1/api/Live/PostData] livebox=[https://gw.fbr.gov.pk/imsp/v1/api/Live/PostData] if type([xcompany.fbrlhost])=[L] and xcompany.fbrlhost livebox=lhost endif response=[] STRTOFILE(invtxtJson,addbs(oprop.appstartpath)+[temp\fbrrequest]+allt(newnum)+[.txt]) response=[Error while sending to ]+lhost try msxml.open('post',livebox,.f.) msxml.setRequestHeader("Authorization","Bearer 1298b5eb-b252-3d97-8622-a4a69d5bf818") msxml.setRequestHeader("Content-Type","application/json") msxml.send(invtxtJson) response=msxml.responseText CATCH response=[ERROR WHILE CONNECTING] ENDTRY fbrlog=fbrlog+CHR(13)+response STRTOFILE(fbrlog,addbs(oprop.appstartpath)+[temp\fbrlog.txt]) fbrlog=fbrlog+CHR(13)+[after send ] STRTOFILE(fbrlog,addbs(oprop.appstartpath)+[temp\fbrlog.txt]) STRTOFILE(response,addbs(oprop.appstartpath)+[temp\fbrresponse]+allt(newnum)+[.txt]) newfbrnumber=STREXTRACT(response,["InvoiceNumber":"],[","Code"]) *TheResponse=[TRANSID:]+PADR(ALLTRIM(TRANSFORM(NewNum)),9,[ srno: ])+[ ]+[ FBR: ]+newfbrnumber+[:END POST: ]+numformated+[ENDPOST] TheResponse=[TransidStart]+PADR(ALLTRIM(TRANSFORM(NewNum)),9)+[TransidEnd SerialNumberStartSerialNumberEnd FBRStart]+newfbrnumber+[FBREnd POSTStart]+numformated+[PostEnd] *TRANSID:22214 srn FBR: 144452EI1U34418350:END POST: CS2509010006ENDPOST usesafe([cashsale]) SELECT [cashsale] =SEEK(PADR(ALLTRIM(TRANSFORM(NewNum)),9,[ ]),'cashsale','transid') IF NOT EOF() AND UPPER(newfbrnumber)<>[NOT AV] replace fbrinv WITH newfbrnumber, fbrposid WITH cFBRPOSID endif CLOSE TABLES SET DATE BRITISH SET MARK TO [/] SET HOURS TO 12 return theresponse %>