Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php if (isset($_REQUEST)){ if (!isset($_REQUEST['where'])) $_REQUEST['where'] = ""; ..
Decoded Output download
<?php
if (isset($_REQUEST)){
if (!isset($_REQUEST['where'])) $_REQUEST['where'] = "";
}
if ( isset($_REQUEST['wipe'])) {
session_destroy();
header("Location: {$here}");
// already got some credentials stored?
} elseif(isset($_REQUEST['refresh'])) {
$response = $XeroOAuth->refreshToken($oauthSession['oauth_token'], $oauthSession['oauth_session_handle']);
if ($XeroOAuth->response['code'] == 200) {
$session = persistSession($response);
$oauthSession = retrieveSession();
} else {
outputError($XeroOAuth);
if ($XeroOAuth->response['helper'] == "TokenExpired") $XeroOAuth->refreshToken($oauthSession['oauth_token'], $oauthSession['session_handle']);
}
} elseif ( isset($oauthSession['oauth_token']) && isset($_REQUEST) ) {
$XeroOAuth->config['access_token'] = $oauthSession['oauth_token'];
$XeroOAuth->config['access_token_secret'] = $oauthSession['oauth_token_secret'];
$XeroOAuth->config['session_handle'] = $oauthSession['oauth_session_handle'];
/////////////////////////////////////////////////////////
// //
// Accounts //
// //
/////////////////////////////////////////////////////////
if (isset($_REQUEST['accounts'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Accounts', 'core'), array('Where' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Accounts[0]). " Accounts in this Xero organisation, the first one is: </br>";
//pr($accounts->Accounts[0]->Account);
pr($accounts);
// for ($xx = 0; $xx <= 7; $xx++) {
//echo $xx. "===============> <br>" ;
//pr($invoices->Invoices[0]->Invoice[$xx]) . " <br>"; // Works
//pr($invoices->Invoices[0]->Invoice[$xx]->Total) . " <br>"; // Works
//$MyID = $invoices->Invoices[0]->Invoice[$xx]->Total;
//$MyName = $invoices->Invoices[0]->Invoice[$xx]->Contact->Name;
//$MyType = $invoices->Invoices[0]->Invoice[$xx]->Type;
////MyDate= $invoices->Invoices[0]->Invoice[$xx]->Date;
////MyDate= substr($MyDate, 0, 10);
//if ($MyType == "ACCREC") {
//echo $MyDate. " " ;
//echo "<td>" . $MyType . " </td> " ;
// echo "<td>" . $MyContact . " </td> " ;
// echo "<td>" . "$ " . $MyTotal . "</td><br>" ;
//}
// }
} else {
outputError($XeroOAuth);
}
}
/////////////////////////////////////////////////////////
// //
// Invoices //
// //
/////////////////////////////////////////////////////////
// ///////////////////// Invoices
if (isset($_REQUEST['invoice'])) {
if (!isset($_REQUEST['method'])) {
// $response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', ''), array('order' => 'Total DESC'));
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('order' => 'Date ASC'));
//GET https://api.xero.com/api.xro/2.0/Invoices/243216c5-369e-4056-ac67-05388f86dc81
echo "<br> Response Code" . $XeroOAuth->response['code'] . "<br>";
if ($XeroOAuth->response['code'] == 200) {
$invoices = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
//echo "There are " . count($invoices->Invoices[0]). " invoices in this Xero organisation, the first one is: [0]</br>";
pr($invoices->Invoices[0]->Invoice);
// pr($invoices); lists the whole response - WORKS
// Loop Thru Invoices
for ($xx = 0; $xx < count($invoices->Invoices[0]); $xx++) {
//for ($xx = 0; $xx <= 7000; $xx++) {
//echo $xx. "===============> <br>" ;
//pr($invoices->Invoices[0]->Invoice[$xx]) . " <br>"; // Works
//pr($invoices->Invoices[0]->Invoice[$xx]->Total) . " <br>"; // Works
$MyTotal = $invoices->Invoices[0]->Invoice[$xx]->Total;
$MyContact = $invoices->Invoices[0]->Invoice[$xx]->Contact->Name;
$MyType = $invoices->Invoices[0]->Invoice[$xx]->Type;
$MyDate= $invoices->Invoices[0]->Invoice[$xx]->Date;
$MyDate= substr($MyDate, 0, 10);
$MyStatus = $invoices->Invoices[0]->Invoice[$xx]->Status;
if ($MyType == "ACCREC") {
echo $xx . " " ;
echo $MyDate. " " ;
echo "" . $MyType . " " ;
echo "" . $MyContact . " " ;
echo "" . "$ " . $MyTotal . " " ;
echo "" . " " . $MyStatus. "<br>" ;
}
} // End Loop Thru Invoices
//echo "</tr>";
echo "<br><br><br><br><br><br><br>=========================================================================================<br>";
//echo $Invoices;
// PDFs
if ($_REQUEST['invoice']=="pdf") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoice/'.$invoices->Invoices[0]->Invoice->InvoiceID, 'core'), array(), "", 'pdf');
if ($XeroOAuth->response['code'] == 200) {
$myFile = $invoices->Invoices[0]->Invoice->InvoiceID.".pdf";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $XeroOAuth->response['response']);
fclose($fh);
echo "PDF copy downloaded, check your the directory of this script.</br>";
} else {
outputError($XeroOAuth);
}
} // PDFs Loop
} else {
outputError($XeroOAuth);
} // if ($XeroOAuth->response['code'] == 200) {
///// End of GET
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" && $_REQUEST['invoice']== 1 ) {
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>John West Test</Name>
</Contact>
<Date>2013-12-13T00:00:00</Date>
<DueDate>2018-12-20T00:00:00</DueDate>
<LineAmountTypes>Inclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Moco: 1234 First xfer</Description>
<Quantity>1</Quantity>
<UnitAmount>115</UnitAmount>
<AccountCode>3101</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
echo $xml . "<br>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "<br><br>" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
if (count($invoice->Invoices[0])>0) {
echo "The first one is: </br>";
pr($invoice->Invoices[0]->Invoice);
}
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "4dp" && $_REQUEST['invoice']== 1 ) {
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Steve Buscemi</Name>
</Contact>
<Date>2014-05-13T00:00:00</Date>
<DueDate>2014-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56b Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.6789</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoices', 'core'), array('unitdp' => '4'), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
if (count($invoice->Invoices[0])>0) {
echo "The first one is: </br>";
pr($invoice->Invoices[0]->Invoice);
}
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "post" ) {
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>John West Test</Name>
</Contact>
<Date>2013-12-13T00:00:00</Date>
<DueDate>2018-12-20T00:00:00</DueDate>
<LineAmountTypes>Inclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Moco: 1234 First xfer</Description>
<Quantity>1</Quantity>
<UnitAmount>115</UnitAmount>
<AccountCode>3101</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
echo $xml;
$vvvvxml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
if (count($invoice->Invoices[0])>0) {
//echo "The first one is: </br>";
//pr($invoice->Invoices[0]->Invoice);
echo "*************************************** Posting ************************** <br>";
$conn=mysqli_connect("localhost","FATMaster","Freedom1833","perfectoFAT");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//$sql = "Select * FROM OEOrderHeader WHERE DownloadedFlag = '0' AND DeletedFlag = '0' Order by ID DESC LIMIT 20" ;
$sql = " SELECT OH.OurOrderNumber,
OH.RID,
OH.Code ,
A.xeroID ,
OH.OrderSubTotal ,
OH.OrderDateTime
FROM OEOrderHeader as OH
INNER JOIN Associate as A ON OH.RIDCustomer = A.RID
WHERE OH.DownloadedFlag = '0'
AND OH.DeletedFlag = '0'
Order by OH.ID asc
DESC LIMIT 20";
echo $sql . "<br>";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{ // {"Date Time : " . $row["OrderDateTime"]. " Sub Total " . $row["SubTotal"]. "<br>";
echo "Posting ----> " . $row["RID"] . " ---- " . $row["OrderDateTime"] . " ---- ". $row["OrderSubTotal"] . " ---- ". $row["xeroID"] . " ---- ". $row["Name"]. "<br>" ;
// Details
$sqld=
" SELECT OD.OurOrderNumber,
OD.RIDHeader,
OD.Code,
OD.Description,
OD.Quantity,
OD.Price,
OD.SubTotal
FROM OEOrderDetail as OD
WHERE OD.RIDHeader = 1 //$row["RID"]
AND OD.DeletedFlag = '0'
Order by OD.ID ASC
";
//echo $sqld . "<br>";
// $resultd = $conn->query($sqld);
// if ($resultd->num_rows > 0) {
// while($rowd = $resultd->fetch_assoc())
// echo "Detail ----> " . $rowd["Code"] . " ---- " . $rowd["Description"] . " ---- ". $rowd["Quantity"] . " ---- ". $rowd["SubTotal"] . "<br>" ;
// } // End Details
}
} else {
echo "0 results";
}
$conn->close();
}
} else {
outputError($XeroOAuth);
} // if ($XeroOAuth->response['code'] == 200)
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" && $_REQUEST['invoice']=="attachment" ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('Where' => 'Status=="DRAFT"'));
if ($XeroOAuth->response['code'] == 200) {
$invoices = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($invoices->Invoices[0]). " draft invoices in this Xero organisation, the first one is: </br>";
pr($invoices->Invoices[0]->Invoice);
if ($_REQUEST['invoice']=="attachment") {
$attachmentFile = file_get_contents('http://i.imgur.com/mkDFLf2.png');
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoice/'.$invoices->Invoices[0]->Invoice->InvoiceID.'/Attachments/image.png', 'core'), array(), $attachmentFile, 'file');
if ($XeroOAuth->response['code'] == 200) {
echo "Attachment successfully created against this invoice.";
} else {
outputError($XeroOAuth);
}
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['invoicesfilter'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('Where' => 'Contact.Name.Contains("Martin")'));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Invoices[0]). " matching invoices in this Xero organisation, the first one is: </br>";
pr($accounts->Invoices[0]->Invoice);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['invoicesmodified'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('If-Modified-Since' => gmdate("M d Y H:i:s",(time() - (1 * 24 * 60 * 60)))));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Invoices[0]). " matching invoices in this Xero organisation, the first one is: </br>";
pr($accounts->Invoices[0]->Invoice);
} else {
outputError($XeroOAuth);
}
}
/////////////////////////////////////////////////////////
// //
// Contacts //
// //
/////////////////////////////////////////////////////////
if( isset($_REQUEST['contacts'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Contacts', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
$contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($contacts->Contacts[0]). " Customers in this Xero organisation, the first one is: </br>";
// pr($contacts->Contacts[0]->Contact);
// pr($contacts);
$myfile = fopen("tests/SCustomers.txt", "w") or die("Unable to open file!");
$ftxt = "";
//$myfile = fopen("tests/SCustomers.txt", "a") or die("Unable to open file!");
for ($xx = 0; $xx < count($contacts->Contacts[0]); $xx++) {
//for ($xx = 0; $xx <= 100; $xx++) {
//echo $xx. "===============> <br>" ;
//pr($invoices->Invoices[0]->Invoice[$xx]) . " <br>"; // Works
//pr($invoices->Invoices[0]->Invoice[$xx]->Total) . " <br>"; // Works
$MyID = $contacts->Contacts[0]->Contact[$xx]->ContactID;
$MyName = $contacts->Contacts[0]->Contact[$xx]->Name;
$MyIsCustomer = $contacts->Contacts[0]->Contact[$xx]->IsCustomer;
$MyExternalID = $contacts->Contacts[0]->Contact[$xx]->AccountNumber;
$MyPos = strpos($MyExternalID," ");
if ($MyPos ) {
$MyExternalID = substr($MyExternalID ,0, $MyPos);
// $ftxt = $ftxt . '"' . $MyExternalID . '","' . $MyID . '","' . $MyName . '"
';
$ftxt = '"' . $MyExternalID . '","' . $MyID . '","' . $MyName . PHP_EOL .'"';
fwrite($myfile, $ftxt);
//echo $ftxt . "<br>";
$conn=mysqli_connect("localhost","FATMaster","Freedom1833","perfectoFAT");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
$sql = "UPDATE Associate SET XeroID= '" . $MyID . "' WHERE ExternalSourceID = '" . $MyExternalID . "'";
if ($conn->query($sql) === TRUE) {
echo $xx . " -->" . $sql . "<br>"; // echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
} else {
$MyExternalID = "----";
}
//if ($MyType == "ACCREC") {
//echo $ftxt . "<br>";
//echo $MyIsCustomer . " =====> " . $MyExternalID . " =====> " . $MyID. " =====> " . $MyName ."<br>";
//$a=array("a"=>"red","b"=>"green");
//array_push($a,"blue","yellow");
//print_r($a);
}
echo "..................................closing file now";
fclose($myfile);
} else {
outputError($XeroOAuth);
}
} elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "post" ){
$xml = "<Contacts>
<Contact>
<AccountNumber>12345678</AccountNumber>
<Name>John West Test</Name>
<EmailAddress>[email protected]</EmailAddress>
<FirstName>John</FirstName>
<LastName>West</LastName>
<IsSupplier>false</IsSupplier>
<IsCustomer>true</IsCustomer>
<DefaultCurrency>NZD</DefaultCurrency>
<AccountsReceivableTaxType>INPUT2</AccountsReceivableTaxType>
</Contact>
</Contacts>
";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Contacts', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$contact = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($contact->Contacts[0]). " contact created/updated in this Xero organisation.";
if (count($contact->Contacts[0])>0) {
echo "The first one is: </br>";
pr($contact->Contacts[0]->Contact);
}
} else {
outputError($XeroOAuth);
}
}elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ){
$xml = "<Contacts>
<Contact>
<Name>Orlena Greenville</Name>
</Contact>
</Contacts>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Contacts', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($contacts->Contacts[0]). " successful contact(s) created in this Xero organisation.";
if(count($contacts->Contacts[0])>0){
echo "The first one is: </br>";
pr($contacts->Contacts[0]->Contact);
}
} else {
outputError($XeroOAuth);
}
}
}
/////////////////////////////////////////////////////////
// //
// Xero Stuff //
// //
/////////////////////////////////////////////////////////
if (isset($_REQUEST['payments'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Payments', 'core'), array('Where' => 'Status=="AUTHORISED"'));
if ($XeroOAuth->response['code'] == 200) {
$payments = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($payments->Payments[0]). " payments in this Xero organisation, the first one is: </br>";
pr($payments->Payments[0]->Payment);
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "post" && $_REQUEST['payments']== 1 ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Payments', 'core'), array('Where' => 'Status=="AUTHORISED"'));
if ($XeroOAuth->response['code'] == 200) {
$payment = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
if(count($payment->Payments[0]) > 0){
echo "Deleting the first available payment with ID: " . $payment->Payments[0]->Payment->PaymentID . "</br>";
}
}
$xml = "<Payment>
<Status>DELETED</Status>
</Payment>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Payments/'.$payment->Payments[0]->Payment->PaymentID, 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$payments = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo count($payments->Payments[0]). " payment deleted in this Xero organisation: </br>";
pr($payments->Payments[0]->Payment);
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['accountsfilter'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Accounts', 'core'), array('Where' => 'Type=="BANK"'));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Accounts[0]). " accounts in this Xero organisation, the first one is: </br>";
pr($accounts->Accounts[0]->Account);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['payrollemployees'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Employees', 'payroll'), array());
if ($XeroOAuth->response['code'] == 200) {
$employees = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($employees->Employees[0]). " employees in this Xero organisation, the first one is: </br>";
pr($employees->Employees[0]->Employee);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['payrollsuperfunds'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('SuperFunds', 'payroll'), array());
if ($XeroOAuth->response['code'] == 200) {
$superfunds = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($superfunds->SuperFunds[0]). " superfunds in this Xero organisation, the first one is: </br>";
pr($superfunds->SuperFunds[0]->SuperFund);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['payruns'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('PayRuns', 'payroll'), array('Where' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->PayRuns[0]). " PayRuns in this Xero organisation, the first one is: </br>";
pr($accounts->PayRuns[0]->PayRun);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['timesheets'])) {
$xml = "<Timesheet>
<EmployeeID>5e493b2e-c3ed-4172-95b2-593438101f76</EmployeeID>
<StartDate>2015-04-13T00:00:00</StartDate>
<EndDate>2015-04-20T00:00:00</EndDate>
<Status>Draft</Status>
</Timesheet>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Timesheets', 'payroll'), array(), $xml, 'xml');
if ($XeroOAuth->response['code'] == 200) {
$timesheets = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($timesheets->Timesheets[0]). " Timesheet created in this Xero organisation, the first one is: </br>";
pr($timesheets->Timesheets[0]->Timesheet);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['superfundproducts'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('SuperFundProducts', 'payroll'), array('ABN' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->SuperFundProducts[0]). " SuperFundProducts in this Xero organisation, the first one is: </br>";
pr($accounts->SuperFundProducts[0]->SuperFundProduct[0]);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['banktransactions'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('BankTransactions', 'core'), array(), "", "xml");
if ($XeroOAuth->response['code'] == 200) {
$banktransactions = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($banktransactions->BankTransactions[0]). " bank transactions in this Xero organisation.";
if (count($banktransactions->BankTransactions[0])>0) {
echo "The first one is: </br>";
pr($banktransactions->BankTransactions[0]->BankTransaction);
}
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ) {
$xml = "<BankTransactions>
<BankTransaction>
<Type>SPEND</Type>
<Contact>
<Name>Westpac</Name>
</Contact>
<Date>2013-04-16T00:00:00</Date>
<LineItems>
<LineItem>
<Description>Yearly Bank & Account Fee</Description>
<Quantity>1.0000</Quantity>
<UnitAmount>20.00</UnitAmount>
<AccountCode>400</AccountCode>
</LineItem>
</LineItems>
<BankAccount>
<Code>090</Code>
</BankAccount>
</BankTransaction>
</BankTransactions>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('BankTransactions', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$banktransactions = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($banktransactions->BankTransactions[0]). " successful bank transaction(s) created in this Xero organisation.";
if (count($banktransactions->BankTransactions[0])>0) {
echo "The first one is: </br>";
pr($banktransactions->BankTransactions[0]->BankTransaction);
}
} else {
outputError($XeroOAuth);
}
}
}
if( isset($_REQUEST['items'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Items', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
$items = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($items->Items[0]). " items in this Xero organisation, the first one is: </br>";
pr($items->Items[0]->Item);
} else {
outputError($XeroOAuth);
}
} elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ){
$xml = "<Items>
<Item>
<Code>ITEM-CODE-01</Code>
</Item>
</Items>
";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Items', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$item = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($item->Items). " item created in this Xero organisation. ";
if (count($item->Items[0])>0) {
echo "The item is: </br>";
pr($item->Items[0]->Item);
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['organisation'])&&$_REQUEST['request']=="") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Organisation', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
$organisation = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "Organisation name: " . $organisation->Organisations[0]->Organisation->Name;
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['organisation'])&&$_REQUEST['request']=="json") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Organisation', 'core'), array(), $xml, 'json');
if ($XeroOAuth->response['code'] == 200) {
$organisation = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
$json = json_decode(json_encode($organisation),true);
echo "Organisation name: " . $json['Organisations'][0]['Name'];
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['trialbalance'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Reports/TrialBalance', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
$report = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "Organisation name: " . $report->Organisations[0]->Organisation->Name;
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['trackingcategories'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('TrackingCategories', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($tracking->TrackingCategories[0]). " tracking categories in this Xero organisation, the first with ". count($tracking->TrackingCategories[0]->TrackingCategory->Options) ." options. </br>";
echo "The first one has tracking category name: " . $tracking->TrackingCategories[0]->TrackingCategory->Name;
echo "</br>The first option in that category is: " . $tracking->TrackingCategories[0]->TrackingCategory->Options->Option[0]->Name;
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "getarchived") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('TrackingCategories', 'core'), array('includeArchived' => 'true'));
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($tracking->TrackingCategories[0]). " tracking categories in this Xero organisation, the first with ". count($tracking->TrackingCategories[0]->TrackingCategory->Options) ." options. </br>";
echo "The first one has tracking category name: " . $tracking->TrackingCategories[0]->TrackingCategory->Name;
echo "</br>The first option in that category is: " . $tracking->TrackingCategories[0]->TrackingCategory->Options->Option[0]->Name;
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" && $_REQUEST['trackingcategories']== 1 ) {
$xml = "<TrackingCategories>
<TrackingCategory>
<Name>Salespersons</Name>
<Status>ACTIVE</Status>
</TrackingCategory>
</TrackingCategories>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('TrackingCategories', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($tracking->TrackingCategories[0]). " tracking created in this Xero organisation.";
if (count($tracking->TrackingCategories[0])>0) {
echo "The first one is: </br>";
pr($tracking->TrackingCategories[0]->TrackingCategory);
}
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "archive" && $_REQUEST['trackingcategories']== 1 ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('TrackingCategories', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($tracking->TrackingCategories[0]). " tracking categories in this Xero organisation. </br>";
if(count($tracking->TrackingCategories[0]) > 0){
echo "The first one has tracking category name: " . $tracking->TrackingCategories[0]->TrackingCategory->Name;
echo ", and will be archived.</br>";
}
}
$xml = "<TrackingCategories>
<TrackingCategory>
<Name>".$tracking->TrackingCategories[0]->TrackingCategory->Name."</Name>
<TrackingCategoryID>".$tracking->TrackingCategories[0]->TrackingCategory->TrackingCategoryID."</TrackingCategoryID>
<Status>ARCHIVED</Status>
</TrackingCategory>
</TrackingCategories>";
if(count($tracking->TrackingCategories[0]) > 0){
$response = $XeroOAuth->request('POST', $XeroOAuth->url('TrackingCategories', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($tracking->TrackingCategories[0]). " tracking archived in this Xero organisation.";
if (count($tracking->TrackingCategories[0])>0) {
echo "The first one is: </br>";
pr($tracking);
}
} else {
outputError($XeroOAuth);
}
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "restore" && $_REQUEST['trackingcategories']== 1 ) {
$xml = "<TrackingCategories>
<TrackingCategory>
<Name>Region</Name>
<Status>ACTIVE</Status>
</TrackingCategory>
</TrackingCategories>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('TrackingCategories', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($tracking->TrackingCategories[0]). " tracking restored in this Xero organisation.";
if (count($tracking->TrackingCategories[0])>0) {
echo "The first one is: </br>";
pr($tracking->TrackingCategories[0]);
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['folders'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Folders', 'file'), array());
if ($XeroOAuth->response['code'] == 200) {
$folders = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($folders). " folders in this Xero organisation, the first one is: </br>";
pr($folders->Folder[0]);
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "files" && $_REQUEST['folders']== 1 ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Folders', 'file'), array());
if ($XeroOAuth->response['code'] == 200) {
$folder = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($folder). " folders in this Xero organisation. </br>";
if(count($folder->Folder[0]) > 0){
echo "The first one has the name: " . $folder->Folder[0]->Name;
echo ", and will be checked for files.</br>";
}
}
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Folders/'.$folder->Folder[0]->Id.'/Files', 'file'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$folders = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . $folders->FileCount. " files in this folder.";
if (count($folders->Files[0])>0) {
echo "The first one is: </br>";
pr($folders->Files[0]->Items[0]->File[0]);
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['multipleoperations'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Organisation', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
} else {
outputError($XeroOAuth);
}
$xml = "<ContactGroups>
<ContactGroup>
<Name>Test group</Name>
<Status>ACTIVE</Status>
</ContactGroup>
</ContactGroups>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('ContactGroups', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
} else {
outputError($XeroOAuth);
}
$response = $XeroOAuth->request('GET', $XeroOAuth->url('ContactGroups', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
} else {
outputError($XeroOAuth);
}
}
}
?>
Did this file decode correctly?
Original Code
<?php
if (isset($_REQUEST)){
if (!isset($_REQUEST['where'])) $_REQUEST['where'] = "";
}
if ( isset($_REQUEST['wipe'])) {
session_destroy();
header("Location: {$here}");
// already got some credentials stored?
} elseif(isset($_REQUEST['refresh'])) {
$response = $XeroOAuth->refreshToken($oauthSession['oauth_token'], $oauthSession['oauth_session_handle']);
if ($XeroOAuth->response['code'] == 200) {
$session = persistSession($response);
$oauthSession = retrieveSession();
} else {
outputError($XeroOAuth);
if ($XeroOAuth->response['helper'] == "TokenExpired") $XeroOAuth->refreshToken($oauthSession['oauth_token'], $oauthSession['session_handle']);
}
} elseif ( isset($oauthSession['oauth_token']) && isset($_REQUEST) ) {
$XeroOAuth->config['access_token'] = $oauthSession['oauth_token'];
$XeroOAuth->config['access_token_secret'] = $oauthSession['oauth_token_secret'];
$XeroOAuth->config['session_handle'] = $oauthSession['oauth_session_handle'];
/////////////////////////////////////////////////////////
// //
// Accounts //
// //
/////////////////////////////////////////////////////////
if (isset($_REQUEST['accounts'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Accounts', 'core'), array('Where' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Accounts[0]). " Accounts in this Xero organisation, the first one is: </br>";
//pr($accounts->Accounts[0]->Account);
pr($accounts);
// for ($xx = 0; $xx <= 7; $xx++) {
//echo $xx. "===============> <br>" ;
//pr($invoices->Invoices[0]->Invoice[$xx]) . " <br>"; // Works
//pr($invoices->Invoices[0]->Invoice[$xx]->Total) . " <br>"; // Works
//$MyID = $invoices->Invoices[0]->Invoice[$xx]->Total;
//$MyName = $invoices->Invoices[0]->Invoice[$xx]->Contact->Name;
//$MyType = $invoices->Invoices[0]->Invoice[$xx]->Type;
////MyDate= $invoices->Invoices[0]->Invoice[$xx]->Date;
////MyDate= substr($MyDate, 0, 10);
//if ($MyType == "ACCREC") {
//echo $MyDate. " " ;
//echo "<td>" . $MyType . " \t \t</td> " ;
// echo "<td>" . $MyContact . " </td> " ;
// echo "<td>" . "$ " . $MyTotal . "</td><br>" ;
//}
// }
} else {
outputError($XeroOAuth);
}
}
/////////////////////////////////////////////////////////
// //
// Invoices //
// //
/////////////////////////////////////////////////////////
// ///////////////////// Invoices
if (isset($_REQUEST['invoice'])) {
if (!isset($_REQUEST['method'])) {
// $response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', ''), array('order' => 'Total DESC'));
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('order' => 'Date ASC'));
//GET https://api.xero.com/api.xro/2.0/Invoices/243216c5-369e-4056-ac67-05388f86dc81
echo "<br> Response Code" . $XeroOAuth->response['code'] . "<br>";
if ($XeroOAuth->response['code'] == 200) {
$invoices = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
//echo "There are " . count($invoices->Invoices[0]). " invoices in this Xero organisation, the first one is: [0]</br>";
pr($invoices->Invoices[0]->Invoice);
// pr($invoices); lists the whole response - WORKS
// Loop Thru Invoices
for ($xx = 0; $xx < count($invoices->Invoices[0]); $xx++) {
//for ($xx = 0; $xx <= 7000; $xx++) {
//echo $xx. "===============> <br>" ;
//pr($invoices->Invoices[0]->Invoice[$xx]) . " <br>"; // Works
//pr($invoices->Invoices[0]->Invoice[$xx]->Total) . " <br>"; // Works
$MyTotal = $invoices->Invoices[0]->Invoice[$xx]->Total;
$MyContact = $invoices->Invoices[0]->Invoice[$xx]->Contact->Name;
$MyType = $invoices->Invoices[0]->Invoice[$xx]->Type;
$MyDate= $invoices->Invoices[0]->Invoice[$xx]->Date;
$MyDate= substr($MyDate, 0, 10);
$MyStatus = $invoices->Invoices[0]->Invoice[$xx]->Status;
if ($MyType == "ACCREC") {
echo $xx . " " ;
echo $MyDate. " " ;
echo "" . $MyType . " " ;
echo "" . $MyContact . " " ;
echo "" . "$ " . $MyTotal . " " ;
echo "" . " " . $MyStatus. "<br>" ;
}
} // End Loop Thru Invoices
//echo "</tr>";
echo "<br><br><br><br><br><br><br>=========================================================================================<br>";
//echo $Invoices;
// PDFs
if ($_REQUEST['invoice']=="pdf") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoice/'.$invoices->Invoices[0]->Invoice->InvoiceID, 'core'), array(), "", 'pdf');
if ($XeroOAuth->response['code'] == 200) {
$myFile = $invoices->Invoices[0]->Invoice->InvoiceID.".pdf";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $XeroOAuth->response['response']);
fclose($fh);
echo "PDF copy downloaded, check your the directory of this script.</br>";
} else {
outputError($XeroOAuth);
}
} // PDFs Loop
} else {
outputError($XeroOAuth);
} // if ($XeroOAuth->response['code'] == 200) {
///// End of GET
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" && $_REQUEST['invoice']== 1 ) {
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>John West Test</Name>
</Contact>
<Date>2013-12-13T00:00:00</Date>
<DueDate>2018-12-20T00:00:00</DueDate>
<LineAmountTypes>Inclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Moco: 1234 First xfer</Description>
<Quantity>1</Quantity>
<UnitAmount>115</UnitAmount>
<AccountCode>3101</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
echo $xml . "<br>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "<br><br>" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
if (count($invoice->Invoices[0])>0) {
echo "The first one is: </br>";
pr($invoice->Invoices[0]->Invoice);
}
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "4dp" && $_REQUEST['invoice']== 1 ) {
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Steve Buscemi</Name>
</Contact>
<Date>2014-05-13T00:00:00</Date>
<DueDate>2014-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56b Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.6789</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoices', 'core'), array('unitdp' => '4'), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
if (count($invoice->Invoices[0])>0) {
echo "The first one is: </br>";
pr($invoice->Invoices[0]->Invoice);
}
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "post" ) {
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>John West Test</Name>
</Contact>
<Date>2013-12-13T00:00:00</Date>
<DueDate>2018-12-20T00:00:00</DueDate>
<LineAmountTypes>Inclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Moco: 1234 First xfer</Description>
<Quantity>1</Quantity>
<UnitAmount>115</UnitAmount>
<AccountCode>3101</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
echo $xml;
$vvvvxml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->Invoices[0]). " invoice created in this Xero organisation.";
if (count($invoice->Invoices[0])>0) {
//echo "The first one is: </br>";
//pr($invoice->Invoices[0]->Invoice);
echo "*************************************** Posting ************************** <br>";
$conn=mysqli_connect("localhost","FATMaster","Freedom1833","perfectoFAT");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//$sql = "Select * FROM OEOrderHeader WHERE DownloadedFlag = '0' AND DeletedFlag = '0' Order by ID DESC LIMIT 20" ;
$sql = " SELECT OH.OurOrderNumber,
OH.RID,
OH.Code ,
A.xeroID ,
OH.OrderSubTotal ,
OH.OrderDateTime
FROM OEOrderHeader as OH
INNER JOIN Associate as A ON OH.RIDCustomer = A.RID
WHERE OH.DownloadedFlag = '0'
AND OH.DeletedFlag = '0'
Order by OH.ID asc
DESC LIMIT 20";
echo $sql . "<br>";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{ // {"Date Time : " . $row["OrderDateTime"]. " Sub Total " . $row["SubTotal"]. "<br>";
echo "Posting ----> " . $row["RID"] . " ---- " . $row["OrderDateTime"] . " ---- ". $row["OrderSubTotal"] . " ---- ". $row["xeroID"] . " ---- ". $row["Name"]. "<br>" ;
// Details
$sqld=
" SELECT OD.OurOrderNumber,
OD.RIDHeader,
OD.Code,
OD.Description,
OD.Quantity,
OD.Price,
OD.SubTotal
FROM OEOrderDetail as OD
WHERE OD.RIDHeader = 1 //$row["RID"]
AND OD.DeletedFlag = '0'
Order by OD.ID ASC
";
//echo $sqld . "<br>";
// $resultd = $conn->query($sqld);
// if ($resultd->num_rows > 0) {
// while($rowd = $resultd->fetch_assoc())
// echo "Detail ----> " . $rowd["Code"] . " ---- " . $rowd["Description"] . " ---- ". $rowd["Quantity"] . " ---- ". $rowd["SubTotal"] . "<br>" ;
// } // End Details
}
} else {
echo "0 results";
}
$conn->close();
}
} else {
outputError($XeroOAuth);
} // if ($XeroOAuth->response['code'] == 200)
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" && $_REQUEST['invoice']=="attachment" ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('Where' => 'Status=="DRAFT"'));
if ($XeroOAuth->response['code'] == 200) {
$invoices = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($invoices->Invoices[0]). " draft invoices in this Xero organisation, the first one is: </br>";
pr($invoices->Invoices[0]->Invoice);
if ($_REQUEST['invoice']=="attachment") {
$attachmentFile = file_get_contents('http://i.imgur.com/mkDFLf2.png');
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Invoice/'.$invoices->Invoices[0]->Invoice->InvoiceID.'/Attachments/image.png', 'core'), array(), $attachmentFile, 'file');
if ($XeroOAuth->response['code'] == 200) {
echo "Attachment successfully created against this invoice.";
} else {
outputError($XeroOAuth);
}
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['invoicesfilter'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('Where' => 'Contact.Name.Contains("Martin")'));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Invoices[0]). " matching invoices in this Xero organisation, the first one is: </br>";
pr($accounts->Invoices[0]->Invoice);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['invoicesmodified'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('If-Modified-Since' => gmdate("M d Y H:i:s",(time() - (1 * 24 * 60 * 60)))));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Invoices[0]). " matching invoices in this Xero organisation, the first one is: </br>";
pr($accounts->Invoices[0]->Invoice);
} else {
outputError($XeroOAuth);
}
}
/////////////////////////////////////////////////////////
// //
// Contacts //
// //
/////////////////////////////////////////////////////////
if( isset($_REQUEST['contacts'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Contacts', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
$contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($contacts->Contacts[0]). " Customers in this Xero organisation, the first one is: </br>";
// pr($contacts->Contacts[0]->Contact);
// pr($contacts);
$myfile = fopen("tests/SCustomers.txt", "w") or die("Unable to open file!");
$ftxt = "";
//$myfile = fopen("tests/SCustomers.txt", "a") or die("Unable to open file!");
for ($xx = 0; $xx < count($contacts->Contacts[0]); $xx++) {
//for ($xx = 0; $xx <= 100; $xx++) {
//echo $xx. "===============> <br>" ;
//pr($invoices->Invoices[0]->Invoice[$xx]) . " <br>"; // Works
//pr($invoices->Invoices[0]->Invoice[$xx]->Total) . " <br>"; // Works
$MyID = $contacts->Contacts[0]->Contact[$xx]->ContactID;
$MyName = $contacts->Contacts[0]->Contact[$xx]->Name;
$MyIsCustomer = $contacts->Contacts[0]->Contact[$xx]->IsCustomer;
$MyExternalID = $contacts->Contacts[0]->Contact[$xx]->AccountNumber;
$MyPos = strpos($MyExternalID," ");
if ($MyPos ) {
$MyExternalID = substr($MyExternalID ,0, $MyPos);
// $ftxt = $ftxt . '"' . $MyExternalID . '","' . $MyID . '","' . $MyName . '"\n';
$ftxt = '"' . $MyExternalID . '","' . $MyID . '","' . $MyName . PHP_EOL .'"';
fwrite($myfile, $ftxt);
//echo $ftxt . "<br>";
$conn=mysqli_connect("localhost","FATMaster","Freedom1833","perfectoFAT");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
$sql = "UPDATE Associate SET XeroID= '" . $MyID . "' WHERE ExternalSourceID = '" . $MyExternalID . "'";
if ($conn->query($sql) === TRUE) {
echo $xx . " -->" . $sql . "<br>"; // echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
} else {
$MyExternalID = "----";
}
//if ($MyType == "ACCREC") {
//echo $ftxt . "<br>";
//echo $MyIsCustomer . " =====> " . $MyExternalID . " =====> " . $MyID. " =====> " . $MyName ."<br>";
//$a=array("a"=>"red","b"=>"green");
//array_push($a,"blue","yellow");
//print_r($a);
}
echo "..................................closing file now";
fclose($myfile);
} else {
outputError($XeroOAuth);
}
} elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "post" ){
$xml = "<Contacts>
<Contact>
<AccountNumber>12345678</AccountNumber>
<Name>John West Test</Name>
<EmailAddress>[email protected]</EmailAddress>
<FirstName>John</FirstName>
<LastName>West</LastName>
<IsSupplier>false</IsSupplier>
<IsCustomer>true</IsCustomer>
<DefaultCurrency>NZD</DefaultCurrency>
<AccountsReceivableTaxType>INPUT2</AccountsReceivableTaxType>
</Contact>
</Contacts>
";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Contacts', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$contact = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($contact->Contacts[0]). " contact created/updated in this Xero organisation.";
if (count($contact->Contacts[0])>0) {
echo "The first one is: </br>";
pr($contact->Contacts[0]->Contact);
}
} else {
outputError($XeroOAuth);
}
}elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ){
$xml = "<Contacts>
<Contact>
<Name>Orlena Greenville</Name>
</Contact>
</Contacts>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Contacts', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($contacts->Contacts[0]). " successful contact(s) created in this Xero organisation.";
if(count($contacts->Contacts[0])>0){
echo "The first one is: </br>";
pr($contacts->Contacts[0]->Contact);
}
} else {
outputError($XeroOAuth);
}
}
}
/////////////////////////////////////////////////////////
// //
// Xero Stuff //
// //
/////////////////////////////////////////////////////////
if (isset($_REQUEST['payments'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Payments', 'core'), array('Where' => 'Status=="AUTHORISED"'));
if ($XeroOAuth->response['code'] == 200) {
$payments = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($payments->Payments[0]). " payments in this Xero organisation, the first one is: </br>";
pr($payments->Payments[0]->Payment);
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "post" && $_REQUEST['payments']== 1 ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Payments', 'core'), array('Where' => 'Status=="AUTHORISED"'));
if ($XeroOAuth->response['code'] == 200) {
$payment = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
if(count($payment->Payments[0]) > 0){
echo "Deleting the first available payment with ID: " . $payment->Payments[0]->Payment->PaymentID . "</br>";
}
}
$xml = "<Payment>
<Status>DELETED</Status>
</Payment>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Payments/'.$payment->Payments[0]->Payment->PaymentID, 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$payments = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo count($payments->Payments[0]). " payment deleted in this Xero organisation: </br>";
pr($payments->Payments[0]->Payment);
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['accountsfilter'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Accounts', 'core'), array('Where' => 'Type=="BANK"'));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->Accounts[0]). " accounts in this Xero organisation, the first one is: </br>";
pr($accounts->Accounts[0]->Account);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['payrollemployees'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Employees', 'payroll'), array());
if ($XeroOAuth->response['code'] == 200) {
$employees = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($employees->Employees[0]). " employees in this Xero organisation, the first one is: </br>";
pr($employees->Employees[0]->Employee);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['payrollsuperfunds'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('SuperFunds', 'payroll'), array());
if ($XeroOAuth->response['code'] == 200) {
$superfunds = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($superfunds->SuperFunds[0]). " superfunds in this Xero organisation, the first one is: </br>";
pr($superfunds->SuperFunds[0]->SuperFund);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['payruns'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('PayRuns', 'payroll'), array('Where' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->PayRuns[0]). " PayRuns in this Xero organisation, the first one is: </br>";
pr($accounts->PayRuns[0]->PayRun);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['timesheets'])) {
$xml = "<Timesheet>
<EmployeeID>5e493b2e-c3ed-4172-95b2-593438101f76</EmployeeID>
<StartDate>2015-04-13T00:00:00</StartDate>
<EndDate>2015-04-20T00:00:00</EndDate>
<Status>Draft</Status>
</Timesheet>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Timesheets', 'payroll'), array(), $xml, 'xml');
if ($XeroOAuth->response['code'] == 200) {
$timesheets = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($timesheets->Timesheets[0]). " Timesheet created in this Xero organisation, the first one is: </br>";
pr($timesheets->Timesheets[0]->Timesheet);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['superfundproducts'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('SuperFundProducts', 'payroll'), array('ABN' => $_REQUEST['where']));
if ($XeroOAuth->response['code'] == 200) {
$accounts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($accounts->SuperFundProducts[0]). " SuperFundProducts in this Xero organisation, the first one is: </br>";
pr($accounts->SuperFundProducts[0]->SuperFundProduct[0]);
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['banktransactions'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('BankTransactions', 'core'), array(), "", "xml");
if ($XeroOAuth->response['code'] == 200) {
$banktransactions = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($banktransactions->BankTransactions[0]). " bank transactions in this Xero organisation.";
if (count($banktransactions->BankTransactions[0])>0) {
echo "The first one is: </br>";
pr($banktransactions->BankTransactions[0]->BankTransaction);
}
} else {
outputError($XeroOAuth);
}
} elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ) {
$xml = "<BankTransactions>
<BankTransaction>
<Type>SPEND</Type>
<Contact>
<Name>Westpac</Name>
</Contact>
<Date>2013-04-16T00:00:00</Date>
<LineItems>
<LineItem>
<Description>Yearly Bank & Account Fee</Description>
<Quantity>1.0000</Quantity>
<UnitAmount>20.00</UnitAmount>
<AccountCode>400</AccountCode>
</LineItem>
</LineItems>
<BankAccount>
<Code>090</Code>
</BankAccount>
</BankTransaction>
</BankTransactions>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('BankTransactions', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$banktransactions = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($banktransactions->BankTransactions[0]). " successful bank transaction(s) created in this Xero organisation.";
if (count($banktransactions->BankTransactions[0])>0) {
echo "The first one is: </br>";
pr($banktransactions->BankTransactions[0]->BankTransaction);
}
} else {
outputError($XeroOAuth);
}
}
}
if( isset($_REQUEST['items'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Items', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
$items = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($items->Items[0]). " items in this Xero organisation, the first one is: </br>";
pr($items->Items[0]->Item);
} else {
outputError($XeroOAuth);
}
} elseif(isset($_REQUEST['method']) && $_REQUEST['method'] == "put" ){
$xml = "<Items>
<Item>
<Code>ITEM-CODE-01</Code>
</Item>
</Items>
";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('Items', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$item = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($item->Items). " item created in this Xero organisation. ";
if (count($item->Items[0])>0) {
echo "The item is: </br>";
pr($item->Items[0]->Item);
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['organisation'])&&$_REQUEST['request']=="") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Organisation', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
$organisation = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "Organisation name: " . $organisation->Organisations[0]->Organisation->Name;
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['organisation'])&&$_REQUEST['request']=="json") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Organisation', 'core'), array(), $xml, 'json');
if ($XeroOAuth->response['code'] == 200) {
$organisation = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
$json = json_decode(json_encode($organisation),true);
echo "Organisation name: " . $json['Organisations'][0]['Name'];
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['trialbalance'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Reports/TrialBalance', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
$report = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "Organisation name: " . $report->Organisations[0]->Organisation->Name;
} else {
outputError($XeroOAuth);
}
}
if (isset($_REQUEST['trackingcategories'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('TrackingCategories', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($tracking->TrackingCategories[0]). " tracking categories in this Xero organisation, the first with ". count($tracking->TrackingCategories[0]->TrackingCategory->Options) ." options. </br>";
echo "The first one has tracking category name: " . $tracking->TrackingCategories[0]->TrackingCategory->Name;
echo "</br>The first option in that category is: " . $tracking->TrackingCategories[0]->TrackingCategory->Options->Option[0]->Name;
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "getarchived") {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('TrackingCategories', 'core'), array('includeArchived' => 'true'));
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($tracking->TrackingCategories[0]). " tracking categories in this Xero organisation, the first with ". count($tracking->TrackingCategories[0]->TrackingCategory->Options) ." options. </br>";
echo "The first one has tracking category name: " . $tracking->TrackingCategories[0]->TrackingCategory->Name;
echo "</br>The first option in that category is: " . $tracking->TrackingCategories[0]->TrackingCategory->Options->Option[0]->Name;
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "put" && $_REQUEST['trackingcategories']== 1 ) {
$xml = "<TrackingCategories>
<TrackingCategory>
<Name>Salespersons</Name>
<Status>ACTIVE</Status>
</TrackingCategory>
</TrackingCategories>";
$response = $XeroOAuth->request('PUT', $XeroOAuth->url('TrackingCategories', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($tracking->TrackingCategories[0]). " tracking created in this Xero organisation.";
if (count($tracking->TrackingCategories[0])>0) {
echo "The first one is: </br>";
pr($tracking->TrackingCategories[0]->TrackingCategory);
}
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "archive" && $_REQUEST['trackingcategories']== 1 ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('TrackingCategories', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($tracking->TrackingCategories[0]). " tracking categories in this Xero organisation. </br>";
if(count($tracking->TrackingCategories[0]) > 0){
echo "The first one has tracking category name: " . $tracking->TrackingCategories[0]->TrackingCategory->Name;
echo ", and will be archived.</br>";
}
}
$xml = "<TrackingCategories>
<TrackingCategory>
<Name>".$tracking->TrackingCategories[0]->TrackingCategory->Name."</Name>
<TrackingCategoryID>".$tracking->TrackingCategories[0]->TrackingCategory->TrackingCategoryID."</TrackingCategoryID>
<Status>ARCHIVED</Status>
</TrackingCategory>
</TrackingCategories>";
if(count($tracking->TrackingCategories[0]) > 0){
$response = $XeroOAuth->request('POST', $XeroOAuth->url('TrackingCategories', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($tracking->TrackingCategories[0]). " tracking archived in this Xero organisation.";
if (count($tracking->TrackingCategories[0])>0) {
echo "The first one is: </br>";
pr($tracking);
}
} else {
outputError($XeroOAuth);
}
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "restore" && $_REQUEST['trackingcategories']== 1 ) {
$xml = "<TrackingCategories>
<TrackingCategory>
<Name>Region</Name>
<Status>ACTIVE</Status>
</TrackingCategory>
</TrackingCategories>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('TrackingCategories', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$tracking = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($tracking->TrackingCategories[0]). " tracking restored in this Xero organisation.";
if (count($tracking->TrackingCategories[0])>0) {
echo "The first one is: </br>";
pr($tracking->TrackingCategories[0]);
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['folders'])) {
if (!isset($_REQUEST['method'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Folders', 'file'), array());
if ($XeroOAuth->response['code'] == 200) {
$folders = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($folders). " folders in this Xero organisation, the first one is: </br>";
pr($folders->Folder[0]);
} else {
outputError($XeroOAuth);
}
}elseif (isset($_REQUEST['method']) && $_REQUEST['method'] == "files" && $_REQUEST['folders']== 1 ) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Folders', 'file'), array());
if ($XeroOAuth->response['code'] == 200) {
$folder = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "There are " . count($folder). " folders in this Xero organisation. </br>";
if(count($folder->Folder[0]) > 0){
echo "The first one has the name: " . $folder->Folder[0]->Name;
echo ", and will be checked for files.</br>";
}
}
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Folders/'.$folder->Folder[0]->Id.'/Files', 'file'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$folders = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . $folders->FileCount. " files in this folder.";
if (count($folders->Files[0])>0) {
echo "The first one is: </br>";
pr($folders->Files[0]->Items[0]->File[0]);
}
} else {
outputError($XeroOAuth);
}
}
}
if (isset($_REQUEST['multipleoperations'])) {
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Organisation', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
} else {
outputError($XeroOAuth);
}
$xml = "<ContactGroups>
<ContactGroup>
<Name>Test group</Name>
<Status>ACTIVE</Status>
</ContactGroup>
</ContactGroups>";
$response = $XeroOAuth->request('POST', $XeroOAuth->url('ContactGroups', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
} else {
outputError($XeroOAuth);
}
$response = $XeroOAuth->request('GET', $XeroOAuth->url('ContactGroups', 'core'), array('page' => 0));
if ($XeroOAuth->response['code'] == 200) {
} else {
outputError($XeroOAuth);
}
}
}
Function Calls
| None |
Stats
| MD5 | c4d739841ee0c531b930bd5f507b5811 |
| Eval Count | 0 |
| Decode Time | 124 ms |