gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:35:47 25 4
gpt4 key购买 nike

我正在使用 Consolibyte 的 PHP/QB 集成在本地计算机上将客户插入/更新到 QB。

当我最初运行 PHP 脚本以将信息从 mysql 数据库插入到 QB 时,一切顺利——太棒了。

但是,当我将新客户添加到 mysql 数据库并再次运行 consolibyte 脚本时,我收到以下错误:

描述:通过 getLastError() 从应用程序收到错误消息:3100:列表元素的名称“John Smith”已被使用。

我知道我不能插入重复的名字,但有没有办法让脚本跳过 QB 数据库中已有的名字,而不是因为重复错误而中止脚本?

根据文档,我可以将唯一标识符传递给 QB 并使其唯一,但我的目标是整体跳过此过程

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

函数.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!');

最佳答案

框架/Web 连接器的默认行为是报告错误,并在发生错误时停止进程。

但是,您当然可以调整默认行为并忽略/处理遇到的任何错误。

设置一个错误处理程序 ( documentation here ) 来处理您看到的错误 (3100, ...)。确保您的错误处理程序在其末尾有 return true;,以便您从错误处理程序返回 true

返回 true 会告诉 Web 连接器继续处理,即使出现错误/警告也是如此。返回 false(默认值)使其停止处理。

所以你最终应该得到这样的东西:

$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;
}

关于php - 在使用 Consolibyte/QB PHP 集成更新 mysql 表时,是否可以跳过已添加到 QuickBooks 数据库中的现有客户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21884240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com