我正在尝试创建一个将数据同步到QuickBooks的php应用程序。我正在使用consolibyte PHP框架/示例。这些例子非常好,但我很难理解如何查询客户数据并打印客户的账单地址。
以下是适用于打印客户姓名和ID的示例代码。如果您有使用此框架的经验,我将非常感谢任何帮助!
$clientName = $_POST["clientName"];
// Set the IPP version to v3
$IPP->version(QuickBooks_IPP_IDS::VERSION_3);
$CustomerService = new QuickBooks_IPP_Service_Customer();
$customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer WHERE CompanyName like '%$clientName%'");
print '~{"response":[';
foreach ($customers as $Customer)
{
$customerID = str_replace("{-", "", $Customer->getId());
$customerID = str_replace("}", "", $customerID);
print('{"QB_customerAddress":"'.$Customer->SHOW BILLING ADDRESS HERE.'", "QB_customerId":"' . $customerID . '", "QB_customerName":"' . $Customer->getFullyQualifiedName().'"},');
}
print ']}~=';
答案 0 :(得分:1)
对象模型完全遵循Intuit XML / JSON模式。
所以,首先来看看Intuit的文档:
您将从文档中注意到Customer对象具有BillAddr
对象。例如,引用Intuit文档:
BillAddr
data type: PhysicalAddress
description: Default billing address.
因此,毫不奇怪,你会发现你的QuickBooks_IPP_Object_Customer对象会有一些方法,如:
// This returns a QuickBooks_IPP_Object_BillAddr object
$BillAddr = $Customer->getBillAddr();
// This accepts a QuickBooks_IPP_Object_BillAddr object as a parameter
$Customer->setBillAddr($BillAddr);
如果你进一步深入了解Intuit的文档,你会注意到BillAddr节点中包含这些数据:
Line1
data type: String
description: First line of the address.
City
data type: string
description: City name.
etc. etc. etc. ...
所以...当然,上面提到的地址对象有以下方法:
$line1 = $BillAddr->getLine1(); // Get the first line of the address
$BillAddr->setLine1($line1); // Set the first line of the address
$city = $BillAddr->getCity(); // Get the city name
$BillAddr->setCity($city); // Set the city name
etc. etc. etc. ...
对象字面上完全遵循Intuit的文档中显示的内容。
另外,你试过print_r($Customer);
吗? print_r()将向您显示对象通常包含的所有内容。
因此,要获得完整的地址,您最终会得到类似的结果:
$billaddr = $Customer->getBillAddr();
$addr = '';
$addr .= $billaddr->getLine1() . "\n<br>";
$addr .= $billaddr->getLine2() . "\n<br>";
$addr .= $billaddr->getLine3() . "\n<br>";
$addr .= $billaddr->getCity() . ', ' . $billaddr->getCountrySubDivisionCode() . ' ' . $billaddr->getPostalCode() . "\n<br>";
$addr .= $billaddr->getCountry();
print($addr);