0

我正在使用 Web 连接器将发票添加到 QuickBooks v13。如果发票尚未添加到 QuickBooks,我还添加了您提供的添加发票的逻辑。

当我设置了 Web 连接器的 AutoRun 选项时,它会自动调用 API。如果我只有一张发票要添加,那么第一次运行它就可以正常工作。但是对于 webconnector 的第二次调用,QuickBooks 中发票的搜索结果会发送 statusCode="0" 的记录,这意味着它已经存在,但它仍然再次将相同的发票添加到 QuickBooks。我无法多次限制添加同一张发票

以下是将发票插入 QuickBooks 的 Rails 代码。我在 Rails 应用程序中使用 qbwc gem 发送 QBXML 请求并解析响应

def api

  if request.get?

    render :nothing => true

    return

  end

  if params["Envelope"]["Body"].keys.first =="authenticate"

    add_invoice #add invoice method will be called to 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 搜索/添加发票

def add_invoice

  #searching the invoice from QuickBooks

  QBWC.add_job('search_invoice') do

   '<QBXML>

      <QBXMLMsgsRq onError="continueOnError">

        <InvoiceQueryRq requestID="1">

          <RefNumber>58869</RefNumber>

        </InvoiceQueryRq>

      </QBXMLMsgsRq>

    </QBXML>'

  end



  #response of the search result

  QBWC.jobs['search_invoice'].set_response_proc do |r|

    if r["xml_attributes"]["statusCode"] == "500" || r["xml_attributes"]["statusCode"] == "1"

      #Add the invoice

      QBWC.add_job('add_invoice') do

        '<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

我已将 Web 连接器的 AutoRun 选项设置为 5 分钟,这样它就会以 5 分钟的间隔自动运行并调用 API。

假设带有 RefNumber#58869 的发票是新的,并且不在 QuickBooks 中。

当 WebConnector 调用 API 时,搜索带有 RefNumber#58869 的发票的 QBXML 请求将被发送到 QuickBooks。它给出了以下响应

<?xml version=\"1.0\" ?>\n<QBXML>\n<QBXMLMsgsRs>\n<InvoiceQueryRs requestID=\"1\" statusCode=\"500\" statusSeverity=\"Warn\" statusMessage=\"The query request has not been fully completed. There was a required element ("58869" that could not be found in QuickBooks.\" />\n</QBXMLMsgsRs>\n</QBXML>\n"

然后发票成功添加到 QuickBooks

当 webconnector 将在 5 分钟间隔后调用 api 时,将向 QuickBooks 发送 QBXML 请求以搜索带有 RefNumber#58869 的发票。它给出了以下响应

<?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

这里的“statusCode”为“0”表示响应表明发票已经存在于 QuickBooks 中。

但仍将相同的发票再次添加到 QuickBooks。而且我找不到任何解决方案来限制多次添加同一张发票。

我跟踪了“statusCode”,发现 QuickBooks 正在发送正确的状态码。我还在订单表中维护一个标志,以跟踪是否已为该订单添加到 QuickBooks 的发票。我认为我的问题出在 WebConnector 上。当 WebConnector 的 AutoRun 选项处于活动状态时,如果没有订单要添加到 QuickBooks,它会一次又一次地添加最后一个订单的发票。

4

0 回答 0