php - 在现有发票中添加新的发票行不起作用

标签 php mysql quickbooks

我面临着一个问题,同时添加一个新的发票线在现有的发票从MySQL数据库。
我已将发票从quickbook同步到MySql。quickbook和mysql之间正在进行双向同步。
问题是,当我在qb_invoice_invoicline表中添加新的invoicline时,它与Quickbook不同步。以下是我在qb_发票表中收到的错误。qbsql_last_errnum 320 last_error_消息
找不到请求中指定的对象“64-1518123234”。(这里64-1518123234是qb_invoice_invoicelineTxnLineIDcoulmn中的值)如果我将此字段留空,则同步时存在解析错误。
下面是我用来同步的代码。

<?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)列中输入什么值?

最佳答案

如果您只想添加一行,请将所有新行项目的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>

关于php - 在现有发票中添加新的发票行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49403262/

相关文章:

php - 使用 jQuery 将值发送到另一个页面

mysql - 在MySQL中隐藏别名列

MySQL 函数返回多于 1 行

sdk - Intuit 合作伙伴平台 - QuickBooks OSR 网站就是个笑话

java - 在 Lotus Notes Xpages 按钮中调用 Java MVC View 方法时出错 单击

javascript - 电子表格中的单个动态模式/JS(如概述)(而不是每个单元格一个)

php - Laravel 和 Eloquent - 应用不同的过滤器

mysql - 使用wp-cli和xampp建立数据库连接时出错

php - 是否可以将我的 opencart 应用程序与 Quickbook 桌面软件集成?

php - PHP后台作业到ubuntu xampp服务器,服务器在60-70分钟后中断