function _quickbooks_purchaseorder_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents) { try { $arrID = explode("_", $ID); $query = "update purchase_order\r\n set status='S'\r\n where id='" . $arrID[2] . "'"; mysql_query($query); $query = "select sum(quantity) as quantity\r\n from purchase_order_item\r\n where idpurchase_order='" . $arrID[2] . "'"; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { if ($row = mysql_fetch_array($result)) { if ($row['quantity'] > 0) { $Parser = new QuickBooks_XML_Parser($xml); if ($Doc = $Parser->parse($errnum, $errmsg)) { $Root = $Doc->getRoot(); $List = $Root->getChildAt('QBXML/QBXMLMsgsRs/PurchaseOrderAddRs'); foreach ($List->children() as $item) { $idPO = $item->getChildDataAt('PurchaseOrderRet TxnID'); } $Queue = new QuickBooks_Queue(QB_QUICKBOOKS_DSN); $Queue->enqueue(QUICKBOOKS_ADD_INVENTORYITEM, $idPO, 4, $arrID[0]); } } } } } catch (Exception $e) { QuickBooks_Utilities::log(QB_QUICKBOOKS_DSN, "purchaseorder_response " . $e->getMessage()); } }
<?php /** * Example integration with an application * * @author Keith Palmer <*****@*****.**> * * @package QuickBooks * @subpackage Documentation */ // Require the queueuing class require_once 'QuickBooks.php'; // QuickBooks queueing class $queue = new QuickBooks_Queue('mysql://*****:*****@localhost/your_database_name'); /* * What I want to happen is this: * * Assuming the Web Connector is scheduled to run every 10 minutes, I want to * make sure that once per every 24 hours we run a CustomerQuery to get new * customers. * * To make this happen, I'm going to register a recurring event. You only need * to register this event *once* and it will automatically insert a * CustomerQuery request into the queue every 24 hours for you from then on. */ // Register the recurring event $queue->recurring('24 hours', 'CustomerQuery', 'get-new-customers'); // You can use other intervals too, these should all work as well: // $queue->recurring(600, 'CustomerQuery', 'get-old-customers'); // 600 seconds (10 minutes) // $queue->recurring('7 days', 'CustomerQuery', 'get-old-customers'); // $queue->recurring('2 weeks', 'CustomerQuery', 'get-old-customers');
// Remember that for each action type you queue up, you should have a // request and a response function registered by using the $map parameter // to the QuickBooks_Server class. The request function will accept a list // of parameters (one of them is $ID, which will be passed the value of // $primary_key_of_new_customer/order that you passed to the ->enqueue() // method and return a qbXML request. So, your request handler for adding // customers might do something like this: // // $arr = mysql_fetch_array(mysql_query("SELECT * FROM my_customer_table WHERE ID = " . (int) $ID)); // // build the qbXML CustomerAddRq here // return $qbxml; // // We're going to queue up a request to add a customer, just as a demo... // NOTE: You would *never* want to do this in this file *unless* it's for testing. See example_integration.php for more details! $primary_key_of_your_customer = 5; $Queue = new QuickBooks_Queue($dsn); $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer); // Also note the that ->enqueue() method supports some other parameters: // string $action The type of action to queue up // mixed $ident = null Pass in the unique primary key of your record here, so you can pull the data from your application to build a qbXML request in your request handler // $priority = 0 You can assign priorities to requests, higher priorities get run first // $extra = null Any extra data you want to pass to the request/response handler // $user = null If you're using multiple usernames, you can pass the username of the user to queue this up for here // $qbxml = null // $replace = true // // Of particular importance and use is the $priority parameter. Say a new // customer is created and places an order on your website. You'll want to // send both the customer *and* the sales receipt to QuickBooks, but you // need to ensure that the customer is created *before* the sales receipt, // right? So, you'll queue up both requests, but you'll assign the
function _quickbooks_vendor_query_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents) { try { $errnum = 0; $errmsg = ''; $Parser = new QuickBooks_XML_Parser($xml); if ($Doc = $Parser->parse($errnum, $errmsg)) { $Root = $Doc->getRoot(); $List = $Root->getChildAt('QBXML/QBXMLMsgsRs/VendorQueryRs'); foreach ($List->children() as $Vendor) { $arr = array('idvendor' => $Vendor->getChildDataAt('VendorRet ListID'), 'name' => html_entity_decode($Vendor->getChildDataAt('VendorRet Name'), ENT_NOQUOTES, 'UTF-8')); foreach ($Vendor->children("DataExtRet") as $customField) { if (strtoupper($customField->getChildDataAt('DataExtRet DataExtName')) == "CATEGORY") { $arr["type"] = strtoupper($customField->getChildDataAt('DataExtRet DataExtValue')); } } foreach ($arr as $key => $value) { $arr[$key] = mysql_real_escape_string($value); } $sql = "INSERT INTO\r\n vendor\r\n (\r\n " . implode(", ", array_keys($arr)) . ", creation_date, last_update\r\n ) VALUES (\r\n '" . implode("', '", array_values($arr)) . "', now(), now()\r\n )\r\n ON DUPLICATE KEY UPDATE name=values(name), type=values(type), active=true, last_update=now();"; mysql_set_charset('utf8'); mysql_query($sql); if (mysql_error()) { QuickBooks_Utilities::log(QB_QUICKBOOKS_DSN, "_quickbooks_vendor_query_response " . mysql_error() . ". Query:" . $sql); } } } else { QuickBooks_Utilities::log(QB_QUICKBOOKS_DSN, "_quickbooks_vendor_query_response ERROR EN PARSER " . $errnum . $errmsg); } if (!empty($idents['iteratorRemainingCount'])) { $Queue = new QuickBooks_Queue(QB_QUICKBOOKS_DSN); $Queue->enqueue(QUICKBOOKS_QUERY_VENDOR, null, 3, array('iteratorID' => $idents['iteratorID'])); } else { $sql = "update vendor set active=false, last_update=now() where cast(last_update as date) != cast(now() as date);"; mysql_query($sql); if (mysql_error()) { QuickBooks_Utilities::log(QB_QUICKBOOKS_DSN, "_quickbooks_vendor_query_response " . mysql_error() . ". Query:" . $sql); } } } catch (Exception $e) { QuickBooks_Utilities::log(QB_QUICKBOOKS_DSN, "vendor_query_response " . $e->getMessage()); } }
$Queue = new QuickBooks_Queue(QB_QUICKBOOKS_DSN); $Queue->enqueue(QUICKBOOKS_ADD_INVOICE, $row["idcustomer_order"], 6, $row["idcustomer"]); } } } catch (Exception $e) { QuickBooks_Utilities::log(QB_QUICKBOOKS_DSN, "enqueueInvoices " . $e->getMessage()); } } function _quickbooks_purchaseorder_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale) { $items = array(); $arrID = explode("_", $ID); $fp = fopen('error.log', 'a+'); $query = "select * from purchase_order_item \r\r where order_no='" . $arrID[1] . "'\r\r and idvendor='" . $arrID[0] . "'"; fwrite($fp, $query); $result = mysql_query($query); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $items[] = array("iditem" => $row['iditem'], "price" => $row['price'], "quantity" => $row['quantity']); } } $xml = '<?xml version="1.0" encoding="utf-8"?> <?qbxml version="5.0"?> <QBXML> <QBXMLMsgsRq onError="continueOnError"> <PurchaseOrderAddRq> <PurchaseOrderAdd> <VendorRef>
<?php ini_set('display_errors', 1); error_reporting(E_ALL | E_STRICT); require_once '../QuickBooks.php'; $dsn = 'mysqli://*****:*****@localhost/quickbooks_server'; $Queue = new QuickBooks_Queue($dsn); $Queue->user('quickbooks'); for ($i = 1; $i <= 3; $i++) { $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $i); } print 'Current queue size for user: '******': ' . $Queue->size() . "\n"; $Queue->user('demo'); print 'Current queue size for user: '******': ' . $Queue->size() . "\n"; $Queue->user('quickbooks'); $Queue->remove(QUICKBOOKS_ADD_CUSTOMER, 2); print 'Current queue size for user: '******' after removing an item: ' . $Queue->size() . "\n";
/** * Example integration with an application * * @author Keith Palmer <*****@*****.**> * * @package QuickBooks * @subpackage Documentation */ // Require the queueuing class require_once 'QuickBooks.php'; if ($_POST['customer']) { // Oooh, here's a new customer, let's do some stuff with them // Connect to your own MySQL server.... $link = mysql_connect('localhost', 'your_mysql_username', 'your_mysql_password'); if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); } // ... and use the correct database $selected = mysql_select_db('your_database_name', $link); if (!$selected) { die('Could not select database: ' . mysql_error()); } // Insert into our local MySQL database mysql_query("INSERT INTO my_customer_table ( name, phone, email ) VALUES ( '" . $_POST['customer']['name'] . "', '" . $_POST['customer']['phone'] . "', '" . $_POST['customer']['email'] . "' ) "); $id_value = mysql_insert_id(); // QuickBooks queueing class $queue = new QuickBooks_Queue('mysql://*****:*****@localhost/my_database'); // Queue it up! $queue->enqueue('CustomerAdd', $id_value); }
$selected = mysql_select_db('your_database_name', $link); if (!$selected) { die ('Could not select database: ' . mysql_error()); } // Insert into our local MySQL database mysql_query("INSERT INTO my_customer_table ( name, phone, email ) VALUES ( '" . $_POST['customer']['name'] . "', '" . $_POST['customer']['phone'] . "', '" . $_POST['customer']['email'] . "' ) "); $id_value = mysql_insert_id(); // QuickBooks queueing class $queue = new QuickBooks_Queue('mysql://*****:*****@localhost/my_database'); // Queue it up! $queue->enqueue('CustomerAdd', $id_value); */ } $id_value = mt_rand(); // QuickBooks queueing class $queue = new QuickBooks_Queue('mysql://*****:*****@localhost/quickbooks'); // Queue it up! $queue->enqueue(QUICKBOOKS_ADD_SALESRECEIPT, $id_value); ?> <html> <head> <title>Prueba</title> </head> <body> Se ha agregado a la cola QUICKBOOKS_ADD_SALESRECEIPT </body> </html>