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 依据报错在原代吗格式的基础上解决问题
  • ¥15 在虚拟机中安装flash code
  • ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
  • ¥20 verilog状态机方法流水灯
  • ¥15 pandas代码实现不了意图
  • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?