我在Mysql数据库的现有发票中添加新发票行时遇到问题。
我已将发票从quickbook同步到MySql。在quickbook和mysql之间进行双向同步。
问题是当我在qb_invoice_invoicline表中添加新的invoicline时,它不会与Quickbook同步。
我在qb_invoice表中收到以下错误。
qbsql_last_errnum 320
last_error_msg
请求中指定的对象“64-1518123234”无法找到。(此处64-1518123234是qb_invoice_invoiceline
中的值。TxnLineID
coulmn)。
如果我将此字段留空,然后在同步时出现解析错误。
以下是我用来同步的代码。
<?php
error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 1);
require_once dirname(__FILE__) . '/QuickBooks.php';
require_once 'Common/Constants.php';
require_once 'Common/Utility.php';
require_once 'Common/Hook.php';
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set(TIMEZONE);
}
if(!isset($_GET['companyId'])) {
trigger_error('Error! Parameter "CompanyId" missing in API.', E_USER_ERROR);
return;
}
$companyId = $_GET['companyId'];
$companyConfig = file_get_contents('config.json');
$companyData = json_decode($companyConfig, true);
if(!isset($companyData['company'][$companyId])) {
trigger_error('Error! Company detail not found in config file.', E_USER_ERROR);
return;
}
// The username and password the Web Connector will use to connect with
$username = $companyData['company'][$companyId]['web_connector_username'];
$password = $companyData['company'][$companyId]['web_connector_password'];
// get Company Database credentials
$db = $companyData['company'][$companyId];
$dsn = 'mysqli://' . $db['username'] . ':' . $db['password'] . '@' . $db['host'] . '/' . $db['db_name'];
// If the database has not been initialized, we need to initialize it (create
// schema and set up the username/password, etc.)
if (!QuickBooks_Utilities::initialized($dsn))
{
header('Content-Type: text/plain');
// It takes a really long time to build the schema...
set_time_limit(0);
$driver_options = array(
);
$init_options = array(
'quickbooks_sql_enabled' => true,
);
QuickBooks_Utilities::initialize($dsn, $driver_options, $init_options);
QuickBooks_Utilities::createUser($dsn, $username, $password);
exit;
}
$mode = QuickBooks_WebConnector_Server_SQL::MODE_READWRITE;
$conflicts = QuickBooks_WebConnector_Server_SQL::CONFLICT_LOG;
$delete = QuickBooks_WebConnector_Server_SQL::DELETE_FLAG; // Just flag it as deleted
$hook_obj = Hook::getInstance($companyId);
$hooks = array(
QuickBooks_SQL::HOOK_SQL_INSERT => array(
'preHookHandler',
array( $hook_obj, 'insertHook' ),
),
QuickBooks_SQL::HOOK_SQL_UPDATE => array(
'preHookHandler',
array( $hook_obj, 'updateHook' ),
),
);
function preHookHandler($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
return true;
}
$soap_options = array();
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
);
$driver_options = array();
$ops = array(
QUICKBOOKS_OBJECT_ACCOUNT,
QUICKBOOKS_OBJECT_SALESTAXITEM,
QUICKBOOKS_OBJECT_SALESTAXCODE,
QUICKBOOKS_OBJECT_CUSTOMER,
QUICKBOOKS_OBJECT_VENDOR,
QUICKBOOKS_OBJECT_INVENTORYITEM,
QUICKBOOKS_OBJECT_TEMPLATE,
QUICKBOOKS_OBJECT_CUSTOMERTYPE,
QUICKBOOKS_OBJECT_VENDORTYPE,
QUICKBOOKS_OBJECT_ESTIMATE,
QUICKBOOKS_OBJECT_INVOICE,
QUICKBOOKS_OBJECT_CLASS,
QUICKBOOKS_OBJECT_UNITOFMEASURESET,
QUICKBOOKS_ADD_UNITOFMEASURESET,
QUICKBOOKS_MOD_UNITOFMEASURESET,
QUICKBOOKS_QUERY_UNITOFMEASURESET,
QUICKBOOKS_IMPORT_UNITOFMEASURESET,
QUICKBOOKS_OBJECT_STANDARDTERMS,
QUICKBOOKS_OBJECT_INVENTORYITEM,
QUICKBOOKS_OBJECT_NONINVENTORYITEM,
QUICKBOOKS_OBJECT_SERVICEITEM,
QUICKBOOKS_OBJECT_SHIPMETHOD,
QUICKBOOKS_OBJECT_PAYMENTMETHOD,
QUICKBOOKS_OBJECT_TERMS,
QUICKBOOKS_OBJECT_PRICELEVEL,
QUICKBOOKS_OBJECT_ITEM,
QUICKBOOKS_ADD_SERVICEITEM,
QUICKBOOKS_MOD_SERVICEITEM,
QUICKBOOKS_QUERY_SERVICEITEM,
QUICKBOOKS_IMPORT_SERVICEITEM,
QUICKBOOKS_OBJECT_RECEIVEPAYMENT,
QUICKBOOKS_ADD_RECEIVE_PAYMENT,
QUICKBOOKS_MOD_RECEIVE_PAYMENT,
QUICKBOOKS_QUERY_RECEIVE_PAYMENT,
QUICKBOOKS_IMPORT_RECEIVE_PAYMENT,
QUICKBOOKS_DERIVE_RECEIVE_PAYMENT,
QUICKBOOKS_OBJECT_PAYMENTMETHOD,
QUICKBOOKS_OBJECT_COMPANY,
QUICKBOOKS_OBJECT_HOST,
QUICKBOOKS_OBJECT_PREFERENCES,
QUICKBOOKS_QUERY_DELETEDTRANSACTIONS,
QUICKBOOKS_OBJECT_SALESREP,
QUICKBOOKS_OBJECT_DATAEXT,
QUICKBOOKS_ADD_DATAEXT,
QUICKBOOKS_MOD_DATAEXT,
QUICKBOOKS_OBJECT_DATAEXTDEF,
QUICKBOOKS_ADD_DATAEXTDEF,
QUICKBOOKS_MOD_DATAEXTDEF
);
$ops_misc = array( // For fetching inventory levels, deleted transactions, etc.
QUICKBOOKS_DERIVE_INVENTORYLEVELS,
QUICKBOOKS_QUERY_DELETEDLISTS,
QUICKBOOKS_QUERY_DELETEDTRANSACTIONS
// 'nothing',
);
//
$sql_options = array(
'only_import' => $ops,
'only_add' => $ops,
'only_modify' => $ops,
'only_misc' => $ops_misc,
);
//
$callback_options = array();
$Server = new QuickBooks_WebConnector_Server_SQL(
$dsn,
'1 minute',
$mode,
$conflicts,
$delete,
$username,
array(),
array(),
$hooks,
QUICKBOOKS_LOG_DEVELOP,
QUICKBOOKS_SOAPSERVER_BUILTIN,
QUICKBOOKS_WSDL,
$soap_options,
$handler_options,
$driver_options,
$sql_options,
$callback_options);
$Server->handle(true, true);
总结问题在(qb_invoice_invoiceline.TxnLineID)列中应添加新的发票线的值是什么?
答案 0 :(得分:1)
如果您只想添加一行,请为所有新订单项将TxnLineID
设置为-1。
例如,如果您的发票包含ID为A / B / C的订单项,并且您想要追加另一行,那么您的mod应该是这样的:
...
<InvoiceLineMod><TxnLineID>A</TxnLineID><InvoiceLineMod>
<InvoiceLineMod><TxnLineID>B</TxnLineID><InvoiceLineMod>
<InvoiceLineMod><TxnLineID>C</TxnLineID><InvoiceLineMod>
<InvoiceLineMod>
<TxnLineID>-1</TxnLineID>
< ... other required values... >
<InvoiceLineMod>
...
如果您想删除B行,只需发送
即可<InvoiceLineMod><TxnLineID>A</TxnLineID><InvoiceLineMod>
<InvoiceLineMod><TxnLineID>C</TxnLineID><InvoiceLineMod>