Advertisement
Guest User

Untitled

a guest
Jun 16th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.1.0.0
  8. * @ Author : DeZender
  9. * @ Release on : 15.05.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class ExampleClass
  15. {
  16. public $apiInstance;
  17.  
  18. public function __construct()
  19. {
  20. }
  21.  
  22. public function init($arg)
  23. {
  24. $apiInstance = $arg;
  25. }
  26.  
  27. public function getAccount($xeroTenantId, $apiInstance, $returnObj = false)
  28. {
  29. $str = '';
  30. $result = $apiInstance->getAccounts($xeroTenantId);
  31. $where = 'Status=="ACTIVE"';
  32. $result2 = $apiInstance->getAccounts($xeroTenantId, NULL, $where);
  33.  
  34. if ($returnObj) {
  35. return $result;
  36. }
  37. else {
  38. $str = $str . 'Get accounts total: ' . count($result->getAccounts()) . '<br>';
  39. $str = $str . 'Get ACTIVE accounts total: ' . count($result2->getAccounts()) . '<br>';
  40. return $str;
  41. }
  42. }
  43.  
  44. public function createAccount($xeroTenantId, $apiInstance, $returnObj = false)
  45. {
  46. $str = '';
  47. $account = new XeroAPI\XeroPHP\Models\Accounting\Account();
  48. $account->setCode($this->getRandNum());
  49. $account->setName('Foo' . $this->getRandNum());
  50. $account->setType('EXPENSE');
  51. $account->setDescription('Hello World');
  52. $result = $apiInstance->createAccount($xeroTenantId, $account);
  53. $str = $str . 'Create Account: ' . $result->getAccounts()[0]->getName() . '<br>';
  54.  
  55. if ($returnObj) {
  56. return $result;
  57. }
  58. else {
  59. return $str;
  60. }
  61. }
  62.  
  63. public function updateAccount($xeroTenantId, $apiInstance)
  64. {
  65. $str = '';
  66. $new = $this->createAccount($xeroTenantId, $apiInstance, true);
  67. $guid = $new->getAccounts()[0]->getAccountId();
  68. $account = new XeroAPI\XeroPHP\Models\Accounting\Account();
  69. $account->setStatus(NULL);
  70. $account->setDescription('Goodbye World');
  71. $result = $apiInstance->updateAccount($xeroTenantId, $guid, $account);
  72. $str = $str . 'Update Account: ' . $result->getAccounts()[0]->getName() . '<br>';
  73. return $str;
  74. }
  75.  
  76. public function archiveAccount($xeroTenantId, $apiInstance)
  77. {
  78. $str = '';
  79. $new = $this->createAccount($xeroTenantId, $apiInstance, true);
  80. $guid = $new->getAccounts()[0]->getAccountId();
  81. $account = new XeroAPI\XeroPHP\Models\Accounting\Account();
  82. $account->setStatus('ARCHIVED');
  83. $result = $apiInstance->updateAccount($xeroTenantId, $guid, $account);
  84. $str = $str . 'Archive Account: ' . $result->getAccounts()[0]->getName() . '<br>';
  85. return $str;
  86. }
  87.  
  88. public function deleteAccount($xeroTenantId, $apiInstance)
  89. {
  90. $str = '';
  91. $new = $this->createAccount($xeroTenantId, $apiInstance, true);
  92. $guid = $new->getAccounts()[0]->getAccountId();
  93. $result = $apiInstance->deleteAccount($xeroTenantId, $guid);
  94. $str = $str . 'Deleted Account: ' . $result->getAccounts()[0]->getName() . '<br>';
  95. return $str;
  96. }
  97.  
  98. public function attachmentAccount($xeroTenantId, $apiInstance)
  99. {
  100. $str = '';
  101. $account = $this->getAccount($xeroTenantId, $apiInstance, true);
  102. $guid = $account->getAccounts()[2]->getAccountId();
  103. $filename = './helo-heros.jpg';
  104. $handle = fopen($filename, 'r');
  105. $contents = fread($handle, filesize($filename));
  106. fclose($handle);
  107. $result = $apiInstance->createAccountAttachmentByFileName($xeroTenantId, $guid, 'helo-heros.jpg', $contents);
  108. $str = 'Account (' . $result->getAttachments()[0]->getFileName() . ') attachment url:';
  109. $str = $str . $result->getAttachments()[0]->getUrl();
  110. return $str;
  111. }
  112.  
  113. public function getBankTransaction($xeroTenantId, $apiInstance)
  114. {
  115. $str = '';
  116. $result = $apiInstance->getBankTransactions($xeroTenantId);
  117. $where = 'Status=="AUTHORISED"';
  118. $result2 = $apiInstance->getBankTransactions($xeroTenantId, NULL, $where);
  119. $str = $str . 'Get BankTransaction total: ' . count($result->getBankTransactions()) . '<br>';
  120. $str = $str . 'Get ACTIVE BankTransaction total: ' . count($result2->getBankTransactions()) . '<br>';
  121. return $str;
  122. }
  123.  
  124. public function createBankTransaction($xeroTenantId, $apiInstance, $returnObj = false)
  125. {
  126. $str = '';
  127. $getContact = $this->getContact($xeroTenantId, $apiInstance, true);
  128. $contactId = $getContact->getContacts()[0]->getContactId();
  129. $getAccount = $this->getBankAccount($xeroTenantId, $apiInstance, true);
  130. $code = $getAccount->getAccounts()[0]->getCode();
  131. $accountId = $getAccount->getAccounts()[0]->getAccountId();
  132. $lineitem = $this->getLineItem();
  133. $lineitems = [];
  134. array_push($lineitems, $lineitem);
  135. $contact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
  136. $contact->setContactId($contactId);
  137. $bankAccount = new XeroAPI\XeroPHP\Models\Accounting\Account();
  138. $bankAccount->setCode($code)->setAccountId($accountId);
  139. $lineitems = [];
  140. array_push($lineitems, $lineitem);
  141. $banktransaction = new XeroAPI\XeroPHP\Models\Accounting\BankTransaction();
  142. $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);
  143. $result = $apiInstance->createBankTransaction($xeroTenantId, $banktransaction);
  144. $str = $str . 'Create Bank Transaction: ' . $result->getBankTransactions()[0]->getReference();
  145.  
  146. if ($returnObj) {
  147. return $result;
  148. }
  149. else {
  150. return $str;
  151. }
  152. }
  153.  
  154. public function updateBankTransaction($xeroTenantId, $apiInstance)
  155. {
  156. $str = '';
  157. $new = $this->createBankTransaction($xeroTenantId, $apiInstance, true);
  158. $banktransactionId = $new->getBankTransactions()[0]->getBankTransactionId();
  159. $banktransaction = new XeroAPI\XeroPHP\Models\Accounting\BankTransaction();
  160. $banktransaction->setReference('Goodbye World');
  161. $result = $apiInstance->updateBankTransaction($xeroTenantId, $banktransactionId, $banktransaction);
  162. $str = $str . 'Updated Bank Transaction: ' . $result->getBankTransactions()[0]->getReference();
  163. return $str;
  164. }
  165.  
  166. public function deleteBankTransaction($xeroTenantId, $apiInstance)
  167. {
  168. $account = $this->getBankAccount($xeroTenantId, $apiInstance, true);
  169.  
  170. if (count((array) $account)) {
  171. $str = '';
  172. $new = $this->createBankTransaction($xeroTenantId, $apiInstance, true);
  173. $banktransactionId = $new->getBankTransactions()[0]->getBankTransactionId();
  174. $banktransaction = new XeroAPI\XeroPHP\Models\Accounting\BankTransaction();
  175. $banktransaction->setStatus(XeroAPI\XeroPHP\Models\Accounting\BankTransaction::STATUS_DELETED);
  176. $result = $apiInstance->updateBankTransaction($xeroTenantId, $banktransactionId, $banktransaction);
  177. $str = $str . 'Deleted Bank Transaction';
  178. }
  179. else {
  180. $str = $str . 'No Bank Account Found - can\'t work with Transactions without it.';
  181. }
  182.  
  183. return $str;
  184. }
  185.  
  186. public function getBankTransfer($xeroTenantId, $apiInstance)
  187. {
  188. $str = '';
  189. $result = $apiInstance->getBankTransfers($xeroTenantId);
  190. $str = $str . 'Get BankTransaction total: ' . count($result->getBankTransfers()) . '<br>';
  191. return $str;
  192. }
  193.  
  194. public function createBankTransfer($xeroTenantId, $apiInstance)
  195. {
  196. $str = '';
  197. $account = $this->getBankAccount($xeroTenantId, $apiInstance);
  198.  
  199. if (1 < count((array) $account)) {
  200. $fromBankAccount = new XeroAPI\XeroPHP\Models\Accounting\Account();
  201. $fromBankAccount->setCode($account->getAccounts()[0]->getCode())->setAccountId($account->getAccounts()[0]->getAccountId());
  202. $toBankAccount = new XeroAPI\XeroPHP\Models\Accounting\Account();
  203. $toBankAccount->setCode($account->getAccounts()[1]->getCode())->setAccountId($account->getAccounts()[1]->getAccountId());
  204. $banktransfer = new XeroAPI\XeroPHP\Models\Accounting\BankTransfer();
  205. $banktransfer->setDate(new DateTime('2017-01-02'))->setToBankAccount($toBankAccount)->setFromBankAccount($fromBankAccount)->setAmount('50');
  206. $result = $apiInstance->createBankTransfer($xeroTenantId, $banktransfer);
  207. $str = $str . 'Create BankTransfer: ' . $result->getBankTransfers()[0]->getAmount();
  208. }
  209. else {
  210. $str = $str . 'Found less than 2 Bank Accounts - can\'t work with Bank Transfers without 2. ';
  211. }
  212.  
  213. return $str;
  214. }
  215.  
  216. public function getBrandingTheme($xeroTenantId, $apiInstance)
  217. {
  218. $str = '';
  219. $result = $apiInstance->getBrandingThemes($xeroTenantId);
  220. $str = $str . 'Get BrandingThemes: ' . count($result->getBrandingThemes()) . '<br>';
  221. return $str;
  222. }
  223.  
  224. public function getContact($xeroTenantId, $apiInstance, $returnObj = false)
  225. {
  226. $str = '';
  227. $result = $apiInstance->getContacts($xeroTenantId);
  228. $where = 'ContactStatus=="ACTIVE"';
  229. $result2 = $apiInstance->getContacts($xeroTenantId, NULL, $where);
  230. $str = $str . 'Get Contacts Total: ' . count($result->getContacts()) . '<br>';
  231. $str = $str . 'Get ACTIVE Contacts Total: ' . count($result2->getContacts()) . '<br>';
  232.  
  233. if ($returnObj) {
  234. return $result2;
  235. }
  236. else {
  237. return $str;
  238. }
  239. }
  240.  
  241. public function createContact($xeroTenantId, $apiInstance, $returnObj = false)
  242. {
  243. $str = '';
  244. $person = new XeroAPI\XeroPHP\Models\Accounting\ContactPerson();
  245. $person->setFirstName('John')->setLastName('Smith')->setEmailAddress('john.smith@24locks.com')->setIncludeInEmails(true);
  246. $persons = [];
  247. array_push($persons, $person);
  248. $contact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
  249. $contact->setName('FooBar' . $this->getRandNum())->setFirstName('Foo' . $this->getRandNum())->setLastName('Bar' . $this->getRandNum())->setEmailAddress('ben.bowden@24locks.com')->setContactPersons($persons);
  250. $result = $apiInstance->createContact($xeroTenantId, $contact);
  251. ........................................................................
  252. ......................................
  253. ..............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement