如何使用 Web 连接器从 QuickBooks Desktop 获取每日销售详细信息?
How I can get Daily Sale Detail from QuickBooks Desktop using web connector?
我想从 Quickbooks Desktop 获取所有销售数据。我有以下代码。
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<GeneralSummaryReportQueryRq requestID="' . $requestID . '">
<GeneralSummaryReportType>SalesByCustomerSummary</GeneralSummaryReportType>
<DisplayReport>false</DisplayReport>
<ReportPeriod>
<FromReportDate>2011-01-01</FromReportDate>
<ToReportDate>2017-09-15</ToReportDate>
</ReportPeriod>
</GeneralSummaryReportQueryRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
当我将 SalesByCustomerSummary 替换为
DailySalesDetail,然后是 return 错误,我的第二个问题是如何停止 Web 连接器和 quicksbook 之间的通信,因为它多次插入相同的记录。
提前致谢
------------ 代码------------
我有这两个功能:
public function _quickbooks_import_daily_sale_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<GeneralDetailReportQueryRq>
<GeneralDetailReportType>SalesByItemDetail</GeneralDetailReportType>
<DisplayReport>false</DisplayReport>
<ReportPeriod>
<FromReportDate>2011-01-01</FromReportDate>
<ToReportDate>2017-09-15</ToReportDate>
</ReportPeriod>
</GeneralDetailReportQueryRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
public function _quickbooks_import_daily_sale_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
$array = array(
'text' => $requestID.' <br />'.$xml
);
$this->db->insert('save_response', $array);
// echo "done";
return false;
}
---------------- FOR 队列---------------------
//echo (__FILE__); exit;
$user = $this->config->item('quickbooks_user');
$pass = $this->config->item('quickbooks_pass');
// Memory limit
ini_set('memory_limit', $this->config->item('quickbooks_memorylimit'));
// We need to make sure the correct timezone is set, or some PHP installations will complain
if (function_exists('date_default_timezone_set'))
{
// * MAKE SURE YOU SET THIS TO THE CORRECT TIMEZONE! *
// List of valid timezones is here: http://us3.php.net/manual/en/timezones.php
date_default_timezone_set($this->config->item('quickbooks_tz'));
}
// Map QuickBooks actions to handler functions
$map = array(
//QUICKBOOKS_IMPORT_CUSTOMER => array( array( $this, '_quickbooks_customer_import_request' ), array( $this, '_quickbooks_customer_import_response' ) ),
/*QUICKBOOKS_IMPORT_EMPLOYEE => array( array( $this, '_quickbooks_employee_import_request' ), array( $this, '_quickbooks_employee_import_response' ) ),*/
QUICKBOOKS_QUERY_INVOICE => array( array( $this, '_quickbooks_import_daily_sale_request' ), array( $this, '_quickbooks_import_daily_sale_response' ) ),
//QUICKBOOKS_IMPORT_CUSTOMER => array( '_quickbooks_customer_import_request', '_quickbooks_customer_import_response' ),
);
// Catch all errors that QuickBooks throws with this function
$errmap = array(
'*' => array( $this, '_catchallErrors' ),
);
// Call this method whenever the Web Connector connects
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => array( array( $this, '_loginSuccess' ) ), // Run this function whenever a successful login occurs
);
// An array of callback options
$callback_options = array();
// Logging level
$log_level = $this->config->item('quickbooks_loglevel');
// What SOAP server you're using
//$soapserver = QUICKBOOKS_SOAPSERVER_PHP; // The PHP SOAP extension, see: www.php.net/soap
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN; // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
$soap_options = array( // See http://www.php.net/soap
);
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
); // See the comments in the QuickBooks/Server/Handlers.php file
$driver_options = array( // See the comments in the QuickBooks/Driver/<YOUR DRIVER HERE>.php file ( i.e. 'Mysql.php', etc. )
'max_log_history' => 32000, // Limit the number of quickbooks_log entries to 1024
'max_queue_history' => 1024, // Limit the number of *successfully processed* quickbooks_queue entries to 64
);
// Build the database connection string
$dsn = 'mysqli://' . $this->db->username . ':' . $this->db->password . '@' . $this->db->hostname . '/' . $this->db->database;
// Check to make sure our database is set up
if (!QuickBooks_Utilities::initialized($dsn))
{
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
// This creates a username and password which is used by the Web Connector to authenticate
QuickBooks_Utilities::createUser($dsn, $user, $pass);
}
// Set up our queue singleton
QuickBooks_WebConnector_Queue_Singleton::initialize($dsn);
// Create a new server and tell it to handle the requests
// __construct($dsn_or_conn, $map, $errmap = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_PHP, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $callback_options = array()
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
$response = $Server->handle();
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_QUERY_INVOICE);
//exit;
//echo "<pre>"; print_r($response);
//echo "Mujtaba";
这是你的问题:
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_QUERY_INVOICE);
Web 连接器的工作方式,每次 Web 连接器连接到 QuickBooks 时,它都会发出 至少 2 个 HTTP 请求。因此,每次尝试与 QuickBooks 同步时,您拥有的这个脚本将 运行 至少 两次。
这意味着每次您尝试与 QuickBooks 同步时,您都在排队至少 两个请求来做同样的事情。
Web 连接器执行此操作:
- HTTP 请求 #1 - 验证
- (如果有事情要做)HTTP 请求 #2 - 要求做第一件事
- (如果我们从上一步得到响应)HTTP 请求 #3 - 将来自 QuickBooks 的响应发送回给您
- (如果还有更多事情要做)返回步骤 2。
- HTTP 请求 #N - 关闭 connection/log 关闭
因此,您需要更改代码,以便 仅在首次连接时排队 而不是在每个 HTTP 请求时排队。
这里有一个这样做的例子:
基本上,您需要注册一个回调函数,以便在 Web 连接器进行身份验证时调用:
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess', // call this whenever a successful login occurs
);
然后在该函数中进行排队:
function _quickbooks_hook_loginsuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
// For new users, we need to set up a few things
// Fetch the queue instance
$Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
$Queue->enqueue(... whatever you want to do here ...)
}
我想从 Quickbooks Desktop 获取所有销售数据。我有以下代码。
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<GeneralSummaryReportQueryRq requestID="' . $requestID . '">
<GeneralSummaryReportType>SalesByCustomerSummary</GeneralSummaryReportType>
<DisplayReport>false</DisplayReport>
<ReportPeriod>
<FromReportDate>2011-01-01</FromReportDate>
<ToReportDate>2017-09-15</ToReportDate>
</ReportPeriod>
</GeneralSummaryReportQueryRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
当我将 SalesByCustomerSummary 替换为 DailySalesDetail,然后是 return 错误,我的第二个问题是如何停止 Web 连接器和 quicksbook 之间的通信,因为它多次插入相同的记录。
提前致谢
------------ 代码------------ 我有这两个功能:
public function _quickbooks_import_daily_sale_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<GeneralDetailReportQueryRq>
<GeneralDetailReportType>SalesByItemDetail</GeneralDetailReportType>
<DisplayReport>false</DisplayReport>
<ReportPeriod>
<FromReportDate>2011-01-01</FromReportDate>
<ToReportDate>2017-09-15</ToReportDate>
</ReportPeriod>
</GeneralDetailReportQueryRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
public function _quickbooks_import_daily_sale_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
$array = array(
'text' => $requestID.' <br />'.$xml
);
$this->db->insert('save_response', $array);
// echo "done";
return false;
}
---------------- FOR 队列---------------------
//echo (__FILE__); exit;
$user = $this->config->item('quickbooks_user');
$pass = $this->config->item('quickbooks_pass');
// Memory limit
ini_set('memory_limit', $this->config->item('quickbooks_memorylimit'));
// We need to make sure the correct timezone is set, or some PHP installations will complain
if (function_exists('date_default_timezone_set'))
{
// * MAKE SURE YOU SET THIS TO THE CORRECT TIMEZONE! *
// List of valid timezones is here: http://us3.php.net/manual/en/timezones.php
date_default_timezone_set($this->config->item('quickbooks_tz'));
}
// Map QuickBooks actions to handler functions
$map = array(
//QUICKBOOKS_IMPORT_CUSTOMER => array( array( $this, '_quickbooks_customer_import_request' ), array( $this, '_quickbooks_customer_import_response' ) ),
/*QUICKBOOKS_IMPORT_EMPLOYEE => array( array( $this, '_quickbooks_employee_import_request' ), array( $this, '_quickbooks_employee_import_response' ) ),*/
QUICKBOOKS_QUERY_INVOICE => array( array( $this, '_quickbooks_import_daily_sale_request' ), array( $this, '_quickbooks_import_daily_sale_response' ) ),
//QUICKBOOKS_IMPORT_CUSTOMER => array( '_quickbooks_customer_import_request', '_quickbooks_customer_import_response' ),
);
// Catch all errors that QuickBooks throws with this function
$errmap = array(
'*' => array( $this, '_catchallErrors' ),
);
// Call this method whenever the Web Connector connects
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => array( array( $this, '_loginSuccess' ) ), // Run this function whenever a successful login occurs
);
// An array of callback options
$callback_options = array();
// Logging level
$log_level = $this->config->item('quickbooks_loglevel');
// What SOAP server you're using
//$soapserver = QUICKBOOKS_SOAPSERVER_PHP; // The PHP SOAP extension, see: www.php.net/soap
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN; // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
$soap_options = array( // See http://www.php.net/soap
);
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
); // See the comments in the QuickBooks/Server/Handlers.php file
$driver_options = array( // See the comments in the QuickBooks/Driver/<YOUR DRIVER HERE>.php file ( i.e. 'Mysql.php', etc. )
'max_log_history' => 32000, // Limit the number of quickbooks_log entries to 1024
'max_queue_history' => 1024, // Limit the number of *successfully processed* quickbooks_queue entries to 64
);
// Build the database connection string
$dsn = 'mysqli://' . $this->db->username . ':' . $this->db->password . '@' . $this->db->hostname . '/' . $this->db->database;
// Check to make sure our database is set up
if (!QuickBooks_Utilities::initialized($dsn))
{
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
// This creates a username and password which is used by the Web Connector to authenticate
QuickBooks_Utilities::createUser($dsn, $user, $pass);
}
// Set up our queue singleton
QuickBooks_WebConnector_Queue_Singleton::initialize($dsn);
// Create a new server and tell it to handle the requests
// __construct($dsn_or_conn, $map, $errmap = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_PHP, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $callback_options = array()
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
$response = $Server->handle();
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_QUERY_INVOICE);
//exit;
//echo "<pre>"; print_r($response);
//echo "Mujtaba";
这是你的问题:
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_QUERY_INVOICE);
Web 连接器的工作方式,每次 Web 连接器连接到 QuickBooks 时,它都会发出 至少 2 个 HTTP 请求。因此,每次尝试与 QuickBooks 同步时,您拥有的这个脚本将 运行 至少 两次。
这意味着每次您尝试与 QuickBooks 同步时,您都在排队至少 两个请求来做同样的事情。
Web 连接器执行此操作:
- HTTP 请求 #1 - 验证
- (如果有事情要做)HTTP 请求 #2 - 要求做第一件事
- (如果我们从上一步得到响应)HTTP 请求 #3 - 将来自 QuickBooks 的响应发送回给您
- (如果还有更多事情要做)返回步骤 2。
- HTTP 请求 #N - 关闭 connection/log 关闭
因此,您需要更改代码,以便 仅在首次连接时排队 而不是在每个 HTTP 请求时排队。
这里有一个这样做的例子:
基本上,您需要注册一个回调函数,以便在 Web 连接器进行身份验证时调用:
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess', // call this whenever a successful login occurs
);
然后在该函数中进行排队:
function _quickbooks_hook_loginsuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
// For new users, we need to set up a few things
// Fetch the queue instance
$Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
$Queue->enqueue(... whatever you want to do here ...)
}