oauth2 = $oauth2; add_shortcode('xero_org_name', array($this, 'xero_org_name')); add_shortcode('xero_org_contacts', array($this, 'xero_org_contacts')); add_shortcode('xero_org_invoices', array($this, 'xero_org_invoices')); add_shortcode('xero_org_pay_items', array($this, 'xero_org_pay_items')); add_shortcode('xero_org_employees', array($this, 'xero_org_employees')); add_shortcode('xero_org_clients', array($this, 'xero_org_clients')); add_shortcode('xero_org_payroll_calendar', array($this, 'xero_org_payroll_calendar')); } public function xero_org_name() { ini_set('display_errors', 'On'); $apiInstance = $this->oauth2->get_accounting_instance(); $apiResponse = $apiInstance->getOrganisations($this->oauth2->getTenantId()); return 'Organisation Name: ' . $apiResponse->getOrganisations()[0]->getName() . " "; } public function xero_org_contacts() { ini_set('display_errors', 'On'); $apiInstance = $this->oauth2->get_accounting_instance(); $apiResponse = $apiInstance->getContacts($this->oauth2->getTenantId()); $contacts = $apiResponse->getContacts(); $message = " "; $message .= " "; $count = 1; foreach ($contacts as $c) { $group = ""; foreach ($c->getContactGroups() as $g) { $group .= $g->getName() . " - " . $g->getStatus() . "
"; } $message .= " " . " " . " " . " " . " " . " " . " " . ""; } $message .= "
# unique-id name Supplier Customer Group Status
" . $count++ . " " . $c->getContactId() . " " . $c->getName() . " " . ($c->getIsSupplier() ? "yes" : " - ") . " " . ($c->getIsCustomer() ? "yes" : " - ") . " " . $group . " " . $c->getContactStatus() . "
"; return $message; } public function xero_org_invoices() { ini_set('display_errors', 'On'); $apiInstance = $this->oauth2->get_accounting_instance(); $apiResponse = $apiInstance->getInvoices($this->xeroTenantId); $invoices = $apiResponse->getInvoices(); $message = " "; $message .= " "; $count = 1; foreach ( $invoices as $c) { $strDate = ""; $d = $c->getDate(); if ( $d != null) { $da = $c->getDateAsDate(); $strDate = $da->format("Y-m-d"); } else { $strDate = $d; } $message .= " " . " " . " " . " " . " " . " " . " " . ""; } $message .= "
# invoice num date contact amount Type Status
" . $count ++ . " " . $c->getInvoiceNumber() . " " . $strDate . " " . $c->getContact()->getName() . " " . $c->getTotal() . " " . $c->getType() . " " . $c->getStatus() . "
"; return $message; } public function xero_org_pay_items(){ ini_set('display_errors', 'On'); $api = $this->oauth2->get_payroll_au_instance(); $xeroTenantId = $this->oauth2->xeroTenantId; //$xeroTenantId = "e23fd416-3b66-43e9-b908-97fbefa24eb8"; // demo company; //$xeroTenantId = "4e2521ae-83e6-4895-aa90-b20aa0825ce1"; // Acaresydney ; $ifModifiedSince = null; $where = null; // "Status==\"ACTIVE\""; $order = null; // "EmailAddress%20DESC"; $page = 1; // $result = null; try { $result = $api->getPayItems ($xeroTenantId, $ifModifiedSince, $where, $order, $page); $rates = $result->getPayItems()->getEarningsRates(); $message = " "; $message .= " "; $count = 1; foreach ( $rates as $r) { $message .= " " . " " . " " . " " . " " . " " . " " . " " . " " . " " . " " . " " . ""; } $message .= "
# Name EarningsType RateType AccountCode Multiplier IsExemptFromTax IsExemptFromSuper AccrueLeave IsReportableAsW1 UpdatedDateUTC CurrentRecord
" . $r->getEarningsRateId() . " " . $r->getName() . " " . $r->getEarningsType() . " " . $r->getRateType() . " " . $r->getAccountCode() . " " . $r->getTypeOfUnits() . " " . $r->getRatePerUnit() . " " . $r->getIsExemptFromTax() . " " . $r->getIsExemptFromSuper() . " " . $r->getIsReportableAsW1() . " " . $r->getUpdatedDateUtc() . " " . $r->getCurrentRecord() . "
"; return $message; } catch (\Exception $e) { echo 'Exception when calling PayrollAuApi->getPayItems: ', $e->getMessage(), PHP_EOL; return; } } public function xero_org_employees(){ // $this->oauth2->getEmployees(); //$this->oauth2->devGetEmployees(); return get_option('bts_employees_updated_desc'); } public function xero_org_clients(){ //$this->oauth2->getClients(); return get_option('bts_clients_updated_desc'); } public function xero_org_payroll_calendar() { update_option('bts_pay_roll_calendar_last_sync', time()); try { $pc = $this->oauth2->get_payroll_calendar(); $start = $pc->getStartDateAsDate()->format('Y-m-d'); $finish = new \DateTime($start); $finish = $finish->modify("+13 days")->format('Y-m-d'); $paydate = $pc->getPaymentDateAsDate()->format('Y-m-d'); $calendar["start"] = $start; $calendar["finish"] = $finish; $calendar["paydate"] = $paydate; update_option('bts_pay_roll_calendar', $calendar); return "start = $start, finish=$finish, paydate=$paydate"; }catch (\Exception $e) { echo 'Exception when calling PayrollAuApi->getPayrollCalendar: ', $e->getMessage(), PHP_EOL; } } public function updateClientsShortCode($allClients) { // ini_set('display_errors', 'On'); try { $contacts = $allClients; $message = " "; $message .= " "; $count = 1; foreach ($contacts as $r){ $message .= " " . " " . " " . " " . " " . " " . " " . " " . ""; $count ++; } $message .= "
# Name Last Status Email AccountNumber Addresses Updated (UTC)
" . $count . " " . $r->getFirstName() . " " . $r->getLastName() . " " . $r->getContactStatus() . " " . $r->getEmailAddress() . " " . $r->getAccountNumber() . " " . $this->oauth2->getClientAddress($r) . " " . $r->getUpdatedDateUtcAsDate()->format("Y-m-d") . "
"; update_option('bts_clients_updated_desc', $message); return $message; } catch (\Exception $e) { echo 'Exception when calling PayrollAuApi->getPayContacts: ', $e->getMessage(), PHP_EOL; return; } } public function updateEmployeeShortCode($allEmployees) { ini_set('display_errors', 'On'); try { $employees = $allEmployees; $message = " "; $message .= " "; $count = 1; foreach ($employees as $r){ if ($r->getEmployeeGroupName() !== "Web-Employee" ){ continue; //dont include them; } $message .= " " . " " . " " . " " . " " . " " . " " . " " . " " . " " . ""; $count ++; } $message .= "
# First Last Status Email DOB Gender Mobile Start Updated(UTC)
" . $count . " " . $r->getFirstName() . " " . $r->getLastName() . " " . $r->getStatus() . " " . $r->getEmail() . " " . $r->getDateOfBirthAsDate()->format("M d Y") . " " . $r->getGender() . " " . $r->getMobile() . " " . $r->getStartDateAsDate()->format("M d Y") . " " . $r->getUpdatedDateUtcAsDate()->format("Y-m-d") . "
"; update_option('bts_employees_updated_desc', $message); return $message; } catch (\Exception $e) { echo 'Exception when calling PayrollAuApi->getPayItems: ', $e->getMessage(), PHP_EOL; return; } } }