完整的客户数据未添加到 Quickbooks 桌面中

问题描述 投票:0回答:2

我正在使用 keith 的 codeignitor 示例从我的在线 pos 在 Quickbook 桌面中添加客户数据。

我从数据库中获取数据并创建了完美的 XML,显示了所有 5109 条记录。但是运行 Web 服务后我只能导入 165 个条目。

请牢记以下内容 - 1)没有XML损坏。 XML 没问题 2)Web服务时间设置为500分钟,因此不会中断。

附件是我的控制器和数据库文件代码 -

控制器 -

http://quicktotals.com/quickbooks.txt

SQL-

http://quicktotals.com/phppos_people.sql

  <?php

class QuickBooks extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        // QuickBooks config
        $this->load->config('quickbooks');

        // Load your other models here... 
        //$this->load->model('yourmodel1');
        //$this->load->model('yourmodel2');
        //$this->load->model('yourmodel3');
    }

    /**
     * Generate and return a .QWC Web Connector configuration file
     */
    public function config()
    {
        $name = 'CodeIgniter QuickBooks Demo';          // A name for your server (make it whatever you want)
        $descrip = 'CodeIgniter QuickBooks Demo';       // A description of your server 

        $appurl = 'https://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/qbwc';      // This *must* be httpS:// (path to your QuickBooks SOAP server)
        $appsupport = $appurl;      // This *must* be httpS:// and the domain name must match the domain name above

        //$dsn = 'mysql://quicktot_admin:hunter2001@localhost/quicktot_pointofsale';
        //QuickBooks_Utilities::createUser($dsn,'vijay','test@1234');

        $username = $this->config->item('quickbooks_user');     // This is the username you stored in the 'quickbooks_user' table by using QuickBooks_Utilities::createUser()

        $fileid = QuickBooks_WebConnector_QWC::fileID();        // Just make this up, but make sure it keeps that format
        $ownerid = QuickBooks_WebConnector_QWC::ownerID();      // Just make this up, but make sure it keeps that format

        $qbtype = QUICKBOOKS_TYPE_QBFS; // You can leave this as-is unless you're using QuickBooks POS

        $readonly = false; // No, we want to write data to QuickBooks

        $run_every_n_seconds = 600; // Run every 600 seconds (10 minutes)

        // Generate the XML file
        $QWC = new QuickBooks_WebConnector_QWC($name, $descrip, $appurl, $appsupport, $username, $fileid, $ownerid, $qbtype, $readonly, $run_every_n_seconds);
        $xml = $QWC->generate();

        // Send as a file download
        header('Content-type: text/xml');
        //header('Content-Disposition: attachment; filename="my-quickbooks-wc-file.qwc"');
        print($xml);
        exit;

    }

    /**
     * SOAP endpoint for the Web Connector to connect to
     */
    public function qbwc()
    {





    $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_ADD_CUSTOMER => array( array( $this, '_addCustomerRequest' ), array( $this, '_addCustomerResponse' )
            ),


            );




        // 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 = 'mysql://' . $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))
        {
            //echo "aaa"; die;

            // 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);
        }

        QuickBooks_Utilities::createUser($dsn, $user, $pass);
        //echo "bbb"; die;
        // 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);



        $Queue = new QuickBooks_WebConnector_Queue($dsn);

        $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER);





        $response = $Server->handle(true, true);




    }

    /**
     * Issue a request to QuickBooks to add a customer
     */
    public function _addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
    {
    // Do something to store the form data here
        $this->load->model('Myquickbooks');

        $data = $this->Myquickbooks->getCustomerData();


    $xml ='';

    $xml .= '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="11.0"?>';

        $xml .= '<QBXML>';


            $xml .= '<QBXMLMsgsRq onError="stopOnError">';


            foreach ($data as $dta)

            {



                $xml .='<CustomerAddRq requestID="' . $requestID . '">
                    <CustomerAdd>
                        <Name>'.$dta['first_name'].'_'.$dta['person_id'].'</Name>
                        <CompanyName>'.$dta['company_name'].'</CompanyName>
                        <FirstName>'.$dta['first_name'].'</FirstName>
                        <LastName>'.$dta['last_name'].'</LastName>
                        <BillAddress>
                            <Addr1>'.$dta['address_1'].'</Addr1>
                            <Addr2>'.$dta['address_2'].'</Addr2>
                            <City>'.$dta['city'].'</City>
                            <State>'.$dta['state'].'</State>
                            <PostalCode>'.$dta['zip'].'</PostalCode>
                            <Country>'.$dta['country'].'</Country>
                        </BillAddress>
                        <Phone>'.$dta['phone_number'].'</Phone>
                        <AltPhone>'.$dta['phone_number'].'</AltPhone>
                        <Fax>'.$dta['phone_number'].'</Fax>
                        <Email>'.$dta['email'].'</Email>
                        <Contact>'.$dta['phone_number'].'</Contact>
                    </CustomerAdd>
                </CustomerAddRq>';





                }

        $xml .='</QBXMLMsgsRq>';
        $xml .='</QBXML>';
        $xml = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $xml);

        return $xml;

    }

    /**
     * Handle a response from QuickBooks indicating a new customer has been added
     */ 
    public function _addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
    {


        return true; 
    }


    /**
     * Catch and handle errors from QuickBooks
     */     
    public function _catchallErrors($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;
    }


    /**
     * Whenever the Web Connector connects, do something (e.g. queue some stuff up if you want to)
     */
    public function _loginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
    {
        return true;
    }
}
    ?>
php xml codeigniter quickbooks
2个回答
0
投票

你的代码有很多问题,对于任何人来帮助你,你必须首先解决这些问题。详情:

您使用的是 13 年版本的 qbXML。为什么?您应该使用 QuickBooks 支持的最高版本:

<?qbxml version="2.0"?>

您将多个客户捆绑到一个 qbXML 请求中。这很糟糕——它破坏了您实际跟踪和报告错误的任何能力。不要这样做。每个客户添加请求都应该是它自己的单独请求,在队列中具有它自己的特定条目。请参阅文档。

foreach ($data as $dta)

您特意绕过了所有错误检查和错误报告。为什么?这使得“不可能”知道是否出了问题。

return true;


修复您的代码,然后重新发布

实际代码

而不是.txt文件。

    


0
投票

public function sendRequestXML($param = '') { $arrs = user(); $requests = []; $xmlRequest = '<?xml version="1.0" encoding="utf-8"?> <?qbxml version="2.0"?> <QBXML> <QBXMLMsgsRq onError="stopOnError"> '; foreach ($arrs as $arr) { // Add customer data for each entry $xmlRequest .= ' <CustomerAddRq requestID="' . mt_rand() . '"> <CustomerAdd> <Name>' . $arr['uuid'] . '</Name> <CompanyName>' . $arr['uuid'] . '</CompanyName> <FirstName>' . $arr['first_name'] . '</FirstName> <LastName>' . $arr['last_name'] . '</LastName> <BillAddress> <Addr1>' . $arr['role_id'] . '</Addr1> <Addr2>134 Stonemill Road</Addr2> <City>Mansfield</City> <State>CT</State> <PostalCode>06268</PostalCode> <Country>United States</Country> </BillAddress> <Phone>860-634-1602</Phone> <AltPhone>860-429-0021</AltPhone> <Fax>860-429-5183</Fax> <Email>' . $arr['email'] . '</Email> <Contact>Keith Palmer</Contact> </CustomerAdd> </CustomerAddRq> '; } $xmlRequest .= '</QBXMLMsgsRq></QBXML>'; $this->response->sendRequestXMLResult = $xmlRequest; return $this->response; }

© www.soinside.com 2019 - 2024. All rights reserved.