forked from mamchyts/quickbooks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqb_clients.php
135 lines (119 loc) · 4.13 KB
/
qb_clients.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* File contains class Qb_Clients() extends Qb()
*/
/**
* Include base class for SOAP SERVER
*/
require 'qb.php';
/**
* Class for import all clients from Qb
*
* @package QB SOAP
* @version 2013-10-20
*/
class Qb_Clients extends Qb
{
/**
* Function send request for Quickbooks
*
* @return string
* @param object $param
* @access public
* @version 2013-10-20
*/
public function sendRequestXML($param = '')
{
$id = requestId();
// <!-- ActiveStatus may have one of the following values: ActiveOnly [DEFAULT], InactiveOnly, All -->
if($param->ticket == QB_TICKET){
$request = $xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>Test -4 (' . mt_rand() . ')</Name>
<CompanyName>Test -4 </CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE, LLC</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>Keith@ConsoliBYTE.com</Email>
<Contact>Keith Palmer</Contact>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>';
$this->response->sendRequestXMLResult = $request;
}
else
$this->response->sendRequestXMLResult = "E: Invalid ticket.";
return $this->response;
}
/**
* Function get response from QB
*
* @return string
* @param object $param
* @access public
* @version 2013-03-15
*/
public function receiveResponseXML($param = '')
{
$response = simplexml_load_string($param->response);
$iteratorID = trim($response->QBXMLMsgsRs->CustomerQueryRs->attributes()->iteratorID);
// set new iteratorID
requestId($iteratorID);
if( ($param->ticket == QB_TICKET) && isset($response->QBXMLMsgsRs->CustomerQueryRs->CustomerRet) ){
$rows = $response->QBXMLMsgsRs->CustomerQueryRs;
settype($rows, 'array');
// if list contain only one item row
if(isset($rows['CustomerRet']->ListID))
$rows = array($rows['CustomerRet']);
else
$rows = $rows['CustomerRet'];
$data = array();
foreach ($rows as $i=>$r) {
settype($r, 'array');
$data[] = array(
'qb_id' => trim($r['ListID']),
'qb_es' => trim($r['EditSequence']),
'is_active' => trim($r['IsActive']),
'phone' => trim($r['Phone']),
'notes' => trim($r['Notes']),
'fax' => trim($r['Fax']),
'company_name' => trim($r['Name']),
'b_email' => trim($r['Email']),
'b_email_other' => trim($r['Cc']),
'b_phone' => trim($r['AltPhone']),
'b_salutation' => trim($r['Salutation']),
'b_fname' => trim($r['FirstName']),
'b_lname' => trim($r['LastName']),
'b_address' => trim($r['BillAddress']->Addr1),
'b_address2' => trim($r['BillAddress']->Addr2),
'b_address3' => trim($r['BillAddress']->Addr3),
'b_city' => trim($r['BillAddress']->City),
'b_state' => trim($r['BillAddress']->State),
'b_country' => trim($r['BillAddress']->Country),
'b_zip' => trim($r['BillAddress']->PostalCode),
);
}
// echo data into log file
_log(print_r($data,1));
$this->response->receiveResponseXMLResult = '30';
}
else
$this->response->receiveResponseXMLResult = '100';
return $this->response;
}
}