diff --git a/XeroOauth2.php b/XeroOauth2.php
index 163ca8d..f5007bd 100644
--- a/XeroOauth2.php
+++ b/XeroOauth2.php
@@ -21,6 +21,8 @@ class XeroOAuth2
private $clientSecret = 'axgKF-Ri60D89conDFhqZsi1wu7uLdQFGvMpino9nI-nfO3f';
private $clientContactGroupID="48646f3d-cf5e-4fea-8c8b-5812bd540e1b";
+ private $shortcodes;
+
public $provider;
public $options = [
'scope' => ['openid email profile offline_access assets projects accounting.settings accounting.transactions accounting.contacts accounting.journals.read accounting.reports.read accounting.attachments payroll.employees payroll.payruns payroll.payslip payroll.timesheets payroll.settings files'],
@@ -54,6 +56,9 @@ class XeroOAuth2
public function __construct($office)
{
$this->office = $office;
+ $this->shortcodes = new XeroOauth2ShortCode($this);
+ $this->storage = new StorageClass();
+
add_action('init', array($this, 'init_wp'));
add_action('after_setup_theme', array($this, 'boot_carbon'));
// add_action('init', array('Carbon_Fields\\Carbon_Fields', 'boot'));
@@ -62,20 +67,10 @@ class XeroOAuth2
add_action('carbon_fields_container_activated', array($this, 'field_activated'));
add_action('parse_request', array($this, 'xero_callback'));
- 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'));
-
-
add_action('init', array($this, "xero_init"));
add_action('plugins_loaded', array($this, "load_storage"));
- // $this->xero_init();
- $this->storage = new StorageClass();
+
}
public function __call($method, $args) {
@@ -272,7 +267,7 @@ class XeroOAuth2
}
}
- private function get_accounting_instance() {
+ public function get_accounting_instance() {
$this->refresh_token();
if ($this->apiAccountingInstance == null) {
$this->config = \XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken(
@@ -285,7 +280,7 @@ class XeroOAuth2
return $this->apiAccountingInstance;
}
- private function get_payroll_au_instance() {
+ public function get_payroll_au_instance() {
$this->refresh_token();
if ($this->apiPayrollInstance == null) {
$this->config = \XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken(
@@ -300,255 +295,6 @@ class XeroOAuth2
return $this->apiPayrollInstance;
}
- public function xero_org_name()
- {
- ini_set('display_errors', 'On');
- $apiInstance = $this->get_accounting_instance();
- $apiResponse = $apiInstance->getOrganisations($this->xeroTenantId);
- return 'Organisation Name: ' . $apiResponse->getOrganisations()[0]->getName() . " ";
- }
-
- public function xero_org_contacts()
- {
- ini_set('display_errors', 'On');
- $apiInstance = $this->get_accounting_instance();
-
- $apiResponse = $apiInstance->getContacts($this->xeroTenantId);
- $contacts = $apiResponse->getContacts();
- $message = "
";
- $message .= " | # |
- unique-id |
- name |
- Supplier |
- Customer |
- Group |
- Status |
";
- $count = 1;
- foreach ($contacts as $c) {
-
- $group = "";
- foreach ($c->getContactGroups() as $g) {
- $group .= $g->getName() . " - " . $g->getStatus() . "
";
- }
-
- $message .= " | " . $count++ . " | " .
- " " . $c->getContactId() . " | " .
- " " . $c->getName() . " | " .
- " " . ($c->getIsSupplier() ? "yes" : " - ") . " | " .
- " " . ($c->getIsCustomer() ? "yes" : " - ") . " | " .
- " " . $group . " | " .
- " " . $c->getContactStatus() . " | " .
- "
";
- }
- $message .= "
";
- return $message;
-
- }
-
- public function xero_org_invoices() {
- ini_set('display_errors', 'On');
- $apiInstance = $this->get_accounting_instance();
-
- $apiResponse = $apiInstance->getInvoices($this->xeroTenantId);
- $invoices = $apiResponse->getInvoices();
-
- $message = " ";
- $message .= " | # |
- invoice num |
- date |
- contact |
- amount |
- Type |
- Status |
";
- $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 .= " | " . $count ++ . " | " .
- " " . $c->getInvoiceNumber() . " | " .
- " " . $strDate . " | " .
- " " . $c->getContact()->getName() . " | " .
- " " . $c->getTotal() . " | " .
- " " . $c->getType() . " | " .
- " " . $c->getStatus() . " | " .
- "
";
- }
- $message .= "
";
- return $message;
-
- }
-
- public function xero_org_pay_items(){
- ini_set('display_errors', 'On');
- $api = $this->get_payroll_au_instance();
-
- $xeroTenantId = $this->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 .= " | # |
- Name |
- EarningsType |
- RateType |
- AccountCode |
- Multiplier |
- IsExemptFromTax |
- IsExemptFromSuper |
- AccrueLeave |
- IsReportableAsW1 |
- UpdatedDateUTC |
- CurrentRecord |
";
- $count = 1;
-
- foreach ( $rates as $r) {
- $message .= " | " . $r->getEarningsRateId() . " | " .
- " " . $r->getName() . " | " .
- " " . $r->getEarningsType() . " | " .
- " " . $r->getRateType() . " | " .
- " " . $r->getAccountCode() . " | " .
- " " . $r->getTypeOfUnits() . " | " .
- " " . $r->getRatePerUnit() . " | " .
- " " . $r->getIsExemptFromTax() . " | " .
- " " . $r->getIsExemptFromSuper() . " | " .
- " " . $r->getIsReportableAsW1() . " | " .
- " " . $r->getUpdatedDateUtc() . " | " .
- " " . $r->getCurrentRecord() . " | " .
- "
";
- }
- $message .= "
";
- return $message;
- } catch (\Exception $e) {
- echo 'Exception when calling PayrollAuApi->getPayItems: ', $e->getMessage(), PHP_EOL;
- return;
- }
- }
-
- public function xero_org_employees(){
- ini_set('display_errors', 'On');
- $api = $this->get_payroll_au_instance();
-
- $xeroTenantId = $this->xeroTenantId;
- //$xeroTenantId = "e23fd416-3b66-43e9-b908-97fbefa24eb8"; // demo company;
- //$xeroTenantId = "4e2521ae-83e6-4895-aa90-b20aa0825ce1"; // Acaresydney ;
-
- $ifModifiedSince = date("M d Y H:i:s", strtotime("-30 days"));
- $where = "Status==\"ACTIVE\"";
- $order = null; // "EmailAddress%20DESC";
- $page = 1;
- // $result = null;
- try {
- $result = $api->getEmployees($xeroTenantId,$ifModifiedSince,$where,$order,$page);
- $employees = $result->getEmployees();
- $message = " ";
- $message .= " | # |
- First |
- Last |
- Status |
- Email |
- DOB |
- Gender |
- Phone |
- Mobile |
- Start |
- Group |
-
";
- $count = 1;
- foreach ($employees as $r){
-
- $message .= " | " . $count . " | " .
- " " . $r->getFirstName() . " | " .
- " " . $r->getLastName() . " | " .
- " " . $r->getStatus() . " | " .
- " " . $r->getEmail() . " | " .
- " " . $r->getDateOfBirthAsDate()->format("M d Y") . " | " .
- " " . $r->getGender() . " | " .
- " " . $r->getPhone() . " | " .
- " " . $r->getMobile() . " | " .
- " " . $r->getStartDateAsDate()->format("M d Y") . " | " .
- " " . $r->getEmployeeGroupName() . " | " .
- "
";
- $count ++;
- }
- $message .= "
";
- return $message;
- } catch (\Exception $e) {
- echo 'Exception when calling PayrollAuApi->getPayItems: ', $e->getMessage(), PHP_EOL;
- return;
- }
- }
-
- public function xero_org_clients(){
- ini_set('display_errors', 'On');
- try {
- $contacts = $this->getClients();
- $message = " ";
- $message .= " | # |
- Name |
- Last |
- Status |
- Email |
- AccountNumber |
- Addresses |
-
";
- $count = 1;
- foreach ($contacts as $r){
-
- $message .= " | " . $count . " - ". $r->getContactID() . " | " .
- " " . $r->getFirstName() . " | " .
- " " . $r->getLastName() . " | " .
- " " . $r->getContactStatus() . " | " .
- " " . $r->getEmailAddress() . " | " .
- " " . $r->getAccountNumber() . " | " .
- " " . $r->getAddresses() . " | " .
- "
";
- $count ++;
- }
- $message .= "
";
- return $message;
- } catch (\Exception $e) {
- echo 'Exception when calling PayrollAuApi->getPayContacts: ', $e->getMessage(), PHP_EOL;
- return;
- }
- }
-
-
- public function xero_org_payroll_calendar()
- {
- // update_option('bts_pay_roll_calendar_last_sync', time());
- try {
- $result = $this->get_payroll_calendar();
- $pc = $result->getPayrollCalendars()[0];
- $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;
-
- return print_r ($calendar);
- }catch (\Exception $e) {
- echo 'Exception when calling PayrollAuApi->getPayrollCalendar: ', $e->getMessage(), PHP_EOL;
- }
- //update_option('bts_pay_roll_calendar', $calendar);
- }
//
//TS implementation
diff --git a/XeroOauth2ShortCode.php b/XeroOauth2ShortCode.php
new file mode 100644
index 0000000..18601c9
--- /dev/null
+++ b/XeroOauth2ShortCode.php
@@ -0,0 +1,271 @@
+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->xeroTenantId);
+ 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->xeroTenantId);
+ $contacts = $apiResponse->getContacts();
+ $message = " ";
+ $message .= " | # |
+ unique-id |
+ name |
+ Supplier |
+ Customer |
+ Group |
+ Status |
";
+ $count = 1;
+ foreach ($contacts as $c) {
+
+ $group = "";
+ foreach ($c->getContactGroups() as $g) {
+ $group .= $g->getName() . " - " . $g->getStatus() . "
";
+ }
+
+ $message .= " | " . $count++ . " | " .
+ " " . $c->getContactId() . " | " .
+ " " . $c->getName() . " | " .
+ " " . ($c->getIsSupplier() ? "yes" : " - ") . " | " .
+ " " . ($c->getIsCustomer() ? "yes" : " - ") . " | " .
+ " " . $group . " | " .
+ " " . $c->getContactStatus() . " | " .
+ "
";
+ }
+ $message .= "
";
+ 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 .= " | # |
+ invoice num |
+ date |
+ contact |
+ amount |
+ Type |
+ Status |
";
+ $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 .= " | " . $count ++ . " | " .
+ " " . $c->getInvoiceNumber() . " | " .
+ " " . $strDate . " | " .
+ " " . $c->getContact()->getName() . " | " .
+ " " . $c->getTotal() . " | " .
+ " " . $c->getType() . " | " .
+ " " . $c->getStatus() . " | " .
+ "
";
+ }
+ $message .= "
";
+ 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 .= " | # |
+ Name |
+ EarningsType |
+ RateType |
+ AccountCode |
+ Multiplier |
+ IsExemptFromTax |
+ IsExemptFromSuper |
+ AccrueLeave |
+ IsReportableAsW1 |
+ UpdatedDateUTC |
+ CurrentRecord |
";
+ $count = 1;
+
+ foreach ( $rates as $r) {
+ $message .= " | " . $r->getEarningsRateId() . " | " .
+ " " . $r->getName() . " | " .
+ " " . $r->getEarningsType() . " | " .
+ " " . $r->getRateType() . " | " .
+ " " . $r->getAccountCode() . " | " .
+ " " . $r->getTypeOfUnits() . " | " .
+ " " . $r->getRatePerUnit() . " | " .
+ " " . $r->getIsExemptFromTax() . " | " .
+ " " . $r->getIsExemptFromSuper() . " | " .
+ " " . $r->getIsReportableAsW1() . " | " .
+ " " . $r->getUpdatedDateUtc() . " | " .
+ " " . $r->getCurrentRecord() . " | " .
+ "
";
+ }
+ $message .= "
";
+ return $message;
+ } catch (\Exception $e) {
+ echo 'Exception when calling PayrollAuApi->getPayItems: ', $e->getMessage(), PHP_EOL;
+ return;
+ }
+ }
+
+ public function xero_org_employees(){
+ 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 = date("M d Y H:i:s", strtotime("-30 days"));
+ $where = "Status==\"ACTIVE\"";
+ $order = null; // "EmailAddress%20DESC";
+ $page = 1;
+ // $result = null;
+ try {
+ $result = $api->getEmployees($xeroTenantId,$ifModifiedSince,$where,$order,$page);
+ $employees = $result->getEmployees();
+ $message = " ";
+ $message .= " | # |
+ First |
+ Last |
+ Status |
+ Email |
+ DOB |
+ Gender |
+ Phone |
+ Mobile |
+ Start |
+ Group |
+
";
+ $count = 1;
+ foreach ($employees as $r){
+
+ $message .= " | " . $count . " | " .
+ " " . $r->getFirstName() . " | " .
+ " " . $r->getLastName() . " | " .
+ " " . $r->getStatus() . " | " .
+ " " . $r->getEmail() . " | " .
+ " " . $r->getDateOfBirthAsDate()->format("M d Y") . " | " .
+ " " . $r->getGender() . " | " .
+ " " . $r->getPhone() . " | " .
+ " " . $r->getMobile() . " | " .
+ " " . $r->getStartDateAsDate()->format("M d Y") . " | " .
+ " " . $r->getEmployeeGroupName() . " | " .
+ "
";
+ $count ++;
+ }
+ $message .= "
";
+ return $message;
+ } catch (\Exception $e) {
+ echo 'Exception when calling PayrollAuApi->getPayItems: ', $e->getMessage(), PHP_EOL;
+ return;
+ }
+ }
+
+ public function xero_org_clients(){
+ ini_set('display_errors', 'On');
+ try {
+ $contacts = $this->oauth2->getClients();
+ $message = " ";
+ $message .= " | # |
+ Name |
+ Last |
+ Status |
+ Email |
+ AccountNumber |
+ Addresses |
+
";
+ $count = 1;
+ foreach ($contacts as $r){
+
+ $message .= " | " . $count . " - ". $r->getContactID() . " | " .
+ " " . $r->getFirstName() . " | " .
+ " " . $r->getLastName() . " | " .
+ " " . $r->getContactStatus() . " | " .
+ " " . $r->getEmailAddress() . " | " .
+ " " . $r->getAccountNumber() . " | " .
+ " " . $r->getAddresses() . " | " .
+ "
";
+ $count ++;
+ }
+ $message .= "
";
+ return $message;
+ } catch (\Exception $e) {
+ echo 'Exception when calling PayrollAuApi->getPayContacts: ', $e->getMessage(), PHP_EOL;
+ return;
+ }
+ }
+
+
+ public function xero_org_payroll_calendar()
+ {
+ update_option('bts_pay_roll_calendar_last_sync', time());
+ try {
+ $result = $this->oauth2->get_payroll_calendar();
+ $pc = $result->getPayrollCalendars()[0];
+ $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;
+
+ return print_r ($calendar);
+ }catch (\Exception $e) {
+ echo 'Exception when calling PayrollAuApi->getPayrollCalendar: ', $e->getMessage(), PHP_EOL;
+ }
+ update_option('bts_pay_roll_calendar', $calendar);
+ }
+
+}
\ No newline at end of file