WebConnector with Auto-Run checked, inserting Duplicate Invoice to the QuickBooks with Rails 3.2.9 -
i using web connector add invoice quickbooks v13. have added provided logic add invoice if invoice not added quickbooks.
when have set autorun option of web connector automatically call api. if have 1 invoice add, first run working fine. second call webconnector, search result invoice in quickbooks sends record statuscode="0" means exist still once again added same invoice quickbooks. not able restrict adding of same invoice multiple time
following rails code insert invoice quickbooks. using qbwc gem in rails application send qbxml request , parse response
def api if request.get? render :nothing => true return end if params["envelope"]["body"].keys.first =="authenticate" add_invoice #add invoice method called search/add invoice end req = request rails.logger.info "=== #{ params["envelope"]["body"].keys.first} ===" res = qbwc::soapwrapper.route_request(req) rails.logger.info render :xml => res, :content_type => 'text/xml' end
#action search/add invoice
def add_invoice #searching invoice quickbooks qbwc.add_job('search_invoice') '<qbxml> <qbxmlmsgsrq onerror="continueonerror"> <invoicequeryrq requestid="1"> <refnumber>58869</refnumber> </invoicequeryrq> </qbxmlmsgsrq> </qbxml>' end #response of search result qbwc.jobs['search_invoice'].set_response_proc |r| if r["xml_attributes"]["statuscode"] == "500" || r["xml_attributes"]["statuscode"] == "1" #add invoice qbwc.add_job('add_invoice') '<qbxml> <qbxmlmsgsrq onerror="continueonerror"> <invoiceaddrq requestid="58869"> <invoiceadd> <customerref> <listid>8000000d-1365397507</listid> <fullname>john.doe@test.com</fullname> </customerref> <txndate>2013-04-08</txndate> <refnumber>58869</refnumber> <billaddress> <addr1>n dallas parkway</addr1> <city>addison</city> <state>tx</state> <postalcode>75001</postalcode> <country>united states</country> </billaddress> <shipaddress> <addr1>n dallas parkway</addr1> <city>addison</city> <state>tx</state> <postalcode>75001</postalcode> <country>united states</country> </shipaddress> <ispending>true</ispending> <ponumber>test qb</ponumber> <termsref> <fullname>visa</fullname> </termsref> <shipdate>2013-04-15</shipdate> <invoicelineadd> <itemref> <fullname>test invoice</fullname> </itemref> <desc>test description</desc> <quantity>1</quantity> <rate>1000</rate> </invoicelineadd> </invoiceadd> </invoiceaddrq> </qbxmlmsgsrq> </qbxml>' end end end end
i have set autorun option of web connector 5 min, automatically run 5 minute interval , call api.
let's invoice refnumber#58869 new , not present in quickbooks.
when webconnector call api, qbxml request search invoice refnumber#58869 sent quickbooks. gives following response
<?xml version=\"1.0\" ?>\n<qbxml>\n<qbxmlmsgsrs>\n<invoicequeryrs requestid=\"1\" statuscode=\"500\" statusseverity=\"warn\" statusmessage=\"the query request has not been completed. there required element ("58869" not found in quickbooks.\" />\n</qbxmlmsgsrs>\n</qbxml>\n"
and invoice added quickbooks
when webconnector call api after 5 min interval, qbxml request search invoice refnumber#58869 sent quickbooks. gives following response
<?xml version=\"1.0\" ?>\n<qbxml>\n<qbxmlmsgsrs>\n<invoicequeryrs requestid=\"1\" statuscode=\"0\" statusseverity=\"info\" statusmessage=\"status ok\">\n<invoiceret>\n<txnid>15f-1365397789</txnid>\n<timecreated>2013-04-08t10:39:49+05:30</timecreated>\n<timemodified>2013-04-08t10:39:49+05:30</timemodified>\n<editsequence>1365397789</editsequence>\n<txnnumber>62</txnnumber>\n<customerref>\n<listid>8000000d-1365397507</listid>\n<fullname>john.doe@test.com</fullname>\n</customerref>\n<araccountref>\n<listid>8000001e-1364292331</listid>\n<fullname>john doe</fullname>\n</araccountref>\n<templateref>\n<listid>80000001-1364291996</listid>\n<fullname>intuit product invoice</fullname>\n</templateref>\n<txndate>2013-04-08</txndate>\n<refnumber>58869</refnumber>\n<billaddress>\n<addr1>16001 n dallas parkway</addr1>\n<city>addison</city>\n<state>tx</state>\n<postalcode>75001</postalcode>\n<country>usa</country>\n</billaddress>\n<billaddressblock>\n<addr1>16001 n dallas parkway</addr1>\n<addr2>addison, tx 75001</addr2>\n<addr3>united states</addr3>\n</billaddressblock>\n<shipaddress>\n<addr1>16001 n dallas parkway</addr1>\n<city>addison</city>\n<state>tx</state>\n<postalcode>75001</postalcode>\n<country>usa</country>\n</shipaddress>\n<shipaddressblock>\n<addr1>16001 n dallas parkway</addr1>\n<addr2>addison, tx 75001</addr2>\n<addr3>united states</addr3>\n</shipaddressblock>\n<ispending>true</ispending>\n<isfinancecharge>false</isfinancecharge>\n<ponumber>united way</ponumber>\n<termsref>\n<listid>8000000c-1364361757</listid>\n<fullname>visa</fullname>\n</termsref>\n<duedate>2013-04-08</duedate>\n<shipdate>2013-04-15</shipdate>\n<subtotal>67.24</subtotal>\n<itemsalestaxref>\n<listid>80000012-1364967363</listid>\n<fullname>sales tax</fullname>\n</itemsalestaxref>\n<salestaxpercentage>0.00</salestaxpercentage>\n<salestaxtotal>0.00</salestaxtotal>\n<appliedamount>0.00</appliedamount>\n<balanceremaining>67.24</balanceremaining>\n<ispaid>false</ispaid>\n<istobeprinted>true</istobeprinted>\n<istobeemailed>false</istobeemailed>\n<customersalestaxcoderef>\n<listid>80000001-1364291997</listid>\n<fullname>tax</fullname>\n</customersalestaxcoderef>\n</invoicequeryrs>\n</qbxmlmsgsrs>\n</qbxml>\n
here 'statuscode' "0" means response says invoice present in quickbooks.
but still same invoice again added quickbooks. , not able find solution restrict adding of same invoice multiple time.
i have tracked "statuscode" , found quickbooks sending correct status code. maintaining flag in order table track invoice added order quickbooks or not. think problem webconnector. when webconnector's autorun option active, adding last order's invoice again , again if there no order left add quickbooks.
Comments
Post a Comment