dsm13698679318 2014-02-19 14:59
浏览 33
已采纳

在使用Consolibyte / QB PHP集成更新mysql表时,是否可以跳过已在QuickBooks数据库中添加的现有客户?

I am using Consolibyte's PHP/QB integration to insert/update customers to QB on a local machine.

When I initially run the PHP script to insert information from mysql DB to QB, everything went through--GREAT.

However, when I added a new customer into the mysql DB and ran the consolibyte script again, I received the following error:

Description: Error message received from application via getLastError(): 3100: The name "John Smith" of the list element is already in use.

I know that I can't insert a duplicate name, but is there a way I can tell the script to skip names that are already in the QB database, instead of aborting the script due to a duplication error?

According to the documentation, I can pass a unique identifier into QB and make it unique, but my objective is to skip this process as a whole

http://www.consolibyte.com/wiki/doku.php/quickbooks_error_codes

FUNCTION.PHP

function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    /*
        <CustomerRef>
            <ListID>80003579-1231522938</ListID>
        </CustomerRef>  
    */

    $customer = mysql_fetch_assoc(mysql_query("SELECT * FROM qb_cust_test WHERE cust_id = " . (int) $ID));

    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <CustomerAddRq requestID="' . $requestID . '">
                    <CustomerAdd>
                        <Name>'.$customer['f_name'].' '.$customer['l_name'].'</Name>
                        <FirstName>'.$customer['f_name'].'</FirstName>
                        <LastName>'.$customer['l_name'].'</LastName>
                        <Phone>'.$customer['phone'].'</Phone>
                        <Email>'.$customer['email'].'</Email>
                    </CustomerAdd>
                </CustomerAddRq>
            </QBXMLMsgsRq>
        </QBXML>';

    return $xml;
}

/**
 * Receive a response from QuickBooks 
 */
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{   
    mysql_query("
        UPDATE 
            qb_cust_test 
        SET 
            quickbooks_listid = '" . mysql_real_escape_string($idents['ListID']) . "', 
            quickbooks_editsequence = '" . mysql_real_escape_string($idents['EditSequence']) . "'
        WHERE 
            id = " . (int) $ID);
}

//continue if error is 3100
$errmap = array(
        '*' => 'catch_all_errors'
);


function catch_all_errors($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    if ($action == QUICKBOOKS_ADD_CUSTOMER and $errnum == 3100)
    {
        return true; // Ignore this error, all is OK - customer already exists
    }

    // Some other error occurred, stop processing

return false;

}

ADD_CUSTOMER.php

<?php
/**
 * Require some configuration stuff
 */ 
require_once dirname(__FILE__) . '/config.php';
// Queue up the customer add 

// Select all customers first
$customers = mysql_query("SELECT * FROM qb_cust_test");

while($customer = mysql_fetch_assoc($customers)) {
    $Queue = new QuickBooks_WebConnector_Queue($dsn);
    $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $customer['cust_id']);
}

    die('Customer submitted!');
  • 写回答

1条回答 默认 最新

  • duanmei1930 2014-02-19 16:32
    关注

    The default behavior of the framework/Web Connector is to report errors, and stop the process if an error occurs.

    However, you can certainly adjust the default behavior and ignore/handle any errors that come across.

    Set up an error handler (documentation here) to handle the error you're seeing (3100, ...). Make sure that your error handler has return true; at the end of it, so that you're returning true from the error handler.

    Returning true tells the Web Connector to continue processing, even if an error/warning occurs. Returning false (the default) makes it stop processing.

    So you should end up with something like:

    $errmap = array(
        '*' => 'catch_all_errors' 
    );
    
    ...
    
    function catch_all_errors($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
    {
        if ($action == QUICKBOOKS_ADD_CUSTOMER and $errnum == 3100)
        {
            return true; // Ignore this error, all is OK - customer already exists
        }
    
        // Some other error occurred, stop processing 
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题