Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.1.0.0
- * @ Author : DeZender
- * @ Release on : 15.05.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class ExampleClass
- {
- public $apiInstance;
- public function __construct()
- {
- }
- public function init($arg)
- {
- $apiInstance = $arg;
- }
- public function getAccount($xeroTenantId, $apiInstance, $returnObj = false)
- {
- $str = '';
- $result = $apiInstance->getAccounts($xeroTenantId);
- $where = 'Status=="ACTIVE"';
- $result2 = $apiInstance->getAccounts($xeroTenantId, NULL, $where);
- if ($returnObj) {
- return $result;
- }
- else {
- $str = $str . 'Get accounts total: ' . count($result->getAccounts()) . '<br>';
- $str = $str . 'Get ACTIVE accounts total: ' . count($result2->getAccounts()) . '<br>';
- return $str;
- }
- }
- public function createAccount($xeroTenantId, $apiInstance, $returnObj = false)
- {
- $str = '';
- $account = new XeroAPI\XeroPHP\Models\Accounting\Account();
- $account->setCode($this->getRandNum());
- $account->setName('Foo' . $this->getRandNum());
- $account->setType('EXPENSE');
- $account->setDescription('Hello World');
- $result = $apiInstance->createAccount($xeroTenantId, $account);
- $str = $str . 'Create Account: ' . $result->getAccounts()[0]->getName() . '<br>';
- if ($returnObj) {
- return $result;
- }
- else {
- return $str;
- }
- }
- public function updateAccount($xeroTenantId, $apiInstance)
- {
- $str = '';
- $new = $this->createAccount($xeroTenantId, $apiInstance, true);
- $guid = $new->getAccounts()[0]->getAccountId();
- $account = new XeroAPI\XeroPHP\Models\Accounting\Account();
- $account->setStatus(NULL);
- $account->setDescription('Goodbye World');
- $result = $apiInstance->updateAccount($xeroTenantId, $guid, $account);
- $str = $str . 'Update Account: ' . $result->getAccounts()[0]->getName() . '<br>';
- return $str;
- }
- public function archiveAccount($xeroTenantId, $apiInstance)
- {
- $str = '';
- $new = $this->createAccount($xeroTenantId, $apiInstance, true);
- $guid = $new->getAccounts()[0]->getAccountId();
- $account = new XeroAPI\XeroPHP\Models\Accounting\Account();
- $account->setStatus('ARCHIVED');
- $result = $apiInstance->updateAccount($xeroTenantId, $guid, $account);
- $str = $str . 'Archive Account: ' . $result->getAccounts()[0]->getName() . '<br>';
- return $str;
- }
- public function deleteAccount($xeroTenantId, $apiInstance)
- {
- $str = '';
- $new = $this->createAccount($xeroTenantId, $apiInstance, true);
- $guid = $new->getAccounts()[0]->getAccountId();
- $result = $apiInstance->deleteAccount($xeroTenantId, $guid);
- $str = $str . 'Deleted Account: ' . $result->getAccounts()[0]->getName() . '<br>';
- return $str;
- }
- public function attachmentAccount($xeroTenantId, $apiInstance)
- {
- $str = '';
- $account = $this->getAccount($xeroTenantId, $apiInstance, true);
- $guid = $account->getAccounts()[2]->getAccountId();
- $filename = './helo-heros.jpg';
- $handle = fopen($filename, 'r');
- $contents = fread($handle, filesize($filename));
- fclose($handle);
- $result = $apiInstance->createAccountAttachmentByFileName($xeroTenantId, $guid, 'helo-heros.jpg', $contents);
- $str = 'Account (' . $result->getAttachments()[0]->getFileName() . ') attachment url:';
- $str = $str . $result->getAttachments()[0]->getUrl();
- return $str;
- }
- public function getBankTransaction($xeroTenantId, $apiInstance)
- {
- $str = '';
- $result = $apiInstance->getBankTransactions($xeroTenantId);
- $where = 'Status=="AUTHORISED"';
- $result2 = $apiInstance->getBankTransactions($xeroTenantId, NULL, $where);
- $str = $str . 'Get BankTransaction total: ' . count($result->getBankTransactions()) . '<br>';
- $str = $str . 'Get ACTIVE BankTransaction total: ' . count($result2->getBankTransactions()) . '<br>';
- return $str;
- }
- public function createBankTransaction($xeroTenantId, $apiInstance, $returnObj = false)
- {
- $str = '';
- $getContact = $this->getContact($xeroTenantId, $apiInstance, true);
- $contactId = $getContact->getContacts()[0]->getContactId();
- $getAccount = $this->getBankAccount($xeroTenantId, $apiInstance, true);
- $code = $getAccount->getAccounts()[0]->getCode();
- $accountId = $getAccount->getAccounts()[0]->getAccountId();
- $lineitem = $this->getLineItem();
- $lineitems = [];
- array_push($lineitems, $lineitem);
- $contact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
- $contact->setContactId($contactId);
- $bankAccount = new XeroAPI\XeroPHP\Models\Accounting\Account();
- $bankAccount->setCode($code)->setAccountId($accountId);
- $lineitems = [];
- array_push($lineitems, $lineitem);
- $banktransaction = new XeroAPI\XeroPHP\Models\Accounting\BankTransaction();
- $banktransaction->setReference('Ref-' . $this->getRandNum())->setDate(new DateTime('2017-01-02'))->setLineItems($lineitems)->setType('RECEIVE')->setLineAmountTypes(XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::EXCLUSIVE)->setBankAccount($bankAccount)->setContact($contact);
- $result = $apiInstance->createBankTransaction($xeroTenantId, $banktransaction);
- $str = $str . 'Create Bank Transaction: ' . $result->getBankTransactions()[0]->getReference();
- if ($returnObj) {
- return $result;
- }
- else {
- return $str;
- }
- }
- public function updateBankTransaction($xeroTenantId, $apiInstance)
- {
- $str = '';
- $new = $this->createBankTransaction($xeroTenantId, $apiInstance, true);
- $banktransactionId = $new->getBankTransactions()[0]->getBankTransactionId();
- $banktransaction = new XeroAPI\XeroPHP\Models\Accounting\BankTransaction();
- $banktransaction->setReference('Goodbye World');
- $result = $apiInstance->updateBankTransaction($xeroTenantId, $banktransactionId, $banktransaction);
- $str = $str . 'Updated Bank Transaction: ' . $result->getBankTransactions()[0]->getReference();
- return $str;
- }
- public function deleteBankTransaction($xeroTenantId, $apiInstance)
- {
- $account = $this->getBankAccount($xeroTenantId, $apiInstance, true);
- if (count((array) $account)) {
- $str = '';
- $new = $this->createBankTransaction($xeroTenantId, $apiInstance, true);
- $banktransactionId = $new->getBankTransactions()[0]->getBankTransactionId();
- $banktransaction = new XeroAPI\XeroPHP\Models\Accounting\BankTransaction();
- $banktransaction->setStatus(XeroAPI\XeroPHP\Models\Accounting\BankTransaction::STATUS_DELETED);
- $result = $apiInstance->updateBankTransaction($xeroTenantId, $banktransactionId, $banktransaction);
- $str = $str . 'Deleted Bank Transaction';
- }
- else {
- $str = $str . 'No Bank Account Found - can\'t work with Transactions without it.';
- }
- return $str;
- }
- public function getBankTransfer($xeroTenantId, $apiInstance)
- {
- $str = '';
- $result = $apiInstance->getBankTransfers($xeroTenantId);
- $str = $str . 'Get BankTransaction total: ' . count($result->getBankTransfers()) . '<br>';
- return $str;
- }
- public function createBankTransfer($xeroTenantId, $apiInstance)
- {
- $str = '';
- $account = $this->getBankAccount($xeroTenantId, $apiInstance);
- if (1 < count((array) $account)) {
- $fromBankAccount = new XeroAPI\XeroPHP\Models\Accounting\Account();
- $fromBankAccount->setCode($account->getAccounts()[0]->getCode())->setAccountId($account->getAccounts()[0]->getAccountId());
- $toBankAccount = new XeroAPI\XeroPHP\Models\Accounting\Account();
- $toBankAccount->setCode($account->getAccounts()[1]->getCode())->setAccountId($account->getAccounts()[1]->getAccountId());
- $banktransfer = new XeroAPI\XeroPHP\Models\Accounting\BankTransfer();
- $banktransfer->setDate(new DateTime('2017-01-02'))->setToBankAccount($toBankAccount)->setFromBankAccount($fromBankAccount)->setAmount('50');
- $result = $apiInstance->createBankTransfer($xeroTenantId, $banktransfer);
- $str = $str . 'Create BankTransfer: ' . $result->getBankTransfers()[0]->getAmount();
- }
- else {
- $str = $str . 'Found less than 2 Bank Accounts - can\'t work with Bank Transfers without 2. ';
- }
- return $str;
- }
- public function getBrandingTheme($xeroTenantId, $apiInstance)
- {
- $str = '';
- $result = $apiInstance->getBrandingThemes($xeroTenantId);
- $str = $str . 'Get BrandingThemes: ' . count($result->getBrandingThemes()) . '<br>';
- return $str;
- }
- public function getContact($xeroTenantId, $apiInstance, $returnObj = false)
- {
- $str = '';
- $result = $apiInstance->getContacts($xeroTenantId);
- $where = 'ContactStatus=="ACTIVE"';
- $result2 = $apiInstance->getContacts($xeroTenantId, NULL, $where);
- $str = $str . 'Get Contacts Total: ' . count($result->getContacts()) . '<br>';
- $str = $str . 'Get ACTIVE Contacts Total: ' . count($result2->getContacts()) . '<br>';
- if ($returnObj) {
- return $result2;
- }
- else {
- return $str;
- }
- }
- public function createContact($xeroTenantId, $apiInstance, $returnObj = false)
- {
- $str = '';
- $person = new XeroAPI\XeroPHP\Models\Accounting\ContactPerson();
- $person->setFirstName('John')->setLastName('Smith')->setEmailAddress('john.smith@24locks.com')->setIncludeInEmails(true);
- $persons = [];
- array_push($persons, $person);
- $contact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
- $contact->setName('FooBar' . $this->getRandNum())->setFirstName('Foo' . $this->getRandNum())->setLastName('Bar' . $this->getRandNum())->setEmailAddress('ben.bowden@24locks.com')->setContactPersons($persons);
- $result = $apiInstance->createContact($xeroTenantId, $contact);
- ........................................................................
- ......................................
- ..............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement