Browse Source

client has ndis and addresss

master
patrick 6 years ago
parent
commit
22e85ded33
3 changed files with 87 additions and 15 deletions
  1. +52
    -2
      Xero.php
  2. +3
    -3
      html/client.html
  3. +32
    -10
      ts.php

+ 52
- 2
Xero.php View File

@@ -3,6 +3,7 @@ namespace Biukop;

use \XeroPHP\Application\PrivateApplication;
use \XeroPHP\Remote\Exception\RateLimitExceededException;
use \XeroPHP\Remote\Exception\NotFoundException;

class Xero {
private $xero;
@@ -78,12 +79,16 @@ class Xero {
$this->logConsole($msg);
try{
//$this->sync_clients();
$this->sync_employees();
$this->sync_clients();
//$this->sync_employees();
}catch(RateLimitExceededException $e){
$msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg);
}catch(NotFoundException $e){
$msg= "Xero API resource not found rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg);
}
}
private function sync_clients(){
$contacts = $this->getClients($this->clientgroup);
@@ -111,6 +116,8 @@ class Xero {
$args = $this->xero_contact_profile($xero_contact);
$id = wp_insert_user($args);
$user = get_user_by('ID', $id);
update_user_meta($user->ID, 'address', $args['address']);
update_user_meta($user->ID, 'account', $args['account']);
}else{//update user
if ($this->is_too_close_to_sync($user)){
return;
@@ -120,6 +127,8 @@ class Xero {
$args['ID'] = $user->ID;
unset($args['user_pass']); //we don't change password
wp_update_user($args);
update_user_meta($user->ID, 'address', $args['address']);
update_user_meta($user->ID, 'account', $args['account']);
}
$this->mark_updated($user->ID);
}
@@ -133,11 +142,51 @@ class Xero {
'first_name' => $c->getFirstName(),
'last_name' => $c->getLastName(),
'nickname' => $c->getName(),
'account' => $c->getAccountNumber(),
'address'=> $this->get_post_address($c),
'role' => 'client',
];
return $args;
}
private function get_post_address($client){
$result = "";
$addr = $this->get_client_address_by_type($client, 'POBOX');
if ( $addr != false){
if ($addr->getAddressLine1() != ""){
$result .= $addr->getAddressLine1() . ";";
}
if ($addr->getAddressLine2() != ""){
$result .= $addr->getAddressLine2() . ";";
}
if ($addr->getAddressLine3() != ""){
$result .= $addr->getAddressLine3() . ";";
}
if ($addr->getAddressLine4() != ""){
$result .= $addr->getAddressLine4() . ";";
}
if ($addr->getCity() != ""){
$result .= $addr->getCity() . ";";
}
if ($addr->getPostalCode() != ""){
$result .= $addr->getPostalCode() . ";";
}
}
echo "result for client is " . $result . "\n";
return $result;
}
private function get_client_address_by_type($client, $t){
$addr = false;
foreach( $client->getAddresses() as $a){
if( $a->getAddressType() == $t){
$addr = $a;
break;
}
}
return $addr;
}
private function ensure_staff_exists($employee)
{
@@ -148,6 +197,7 @@ class Xero {
$args = $this->xero_employee_profile($xero_employee);
$id = wp_insert_user($args);
$user = get_user_by('ID', $id);
update_user_meta($user->ID, 'mobile', $args['mobile']);
}else{
if ($this->is_too_close_to_sync($user)){
return;

+ 3
- 3
html/client.html View File

@@ -2,11 +2,11 @@
<label class='peopleitem' data-id=p{{login}} > <input type="checkbox"/>
<div class="card">
<div class="front">
<span name='iccon' class='ticon ticon-user'></span> <span
<span
name='badge' class='badge blue'><a href="/pending-jobs/{{login}}"></a>{{unconfirmedjob}}</span>
<div name='title'><a href='/user/{{login}}' target="_blank"> {{firstname}},{{lastname}} </a></div>
<div name='wages'>${{wages}} ({{hour}}hr + {{OT}}hr)</div>
<div name='patrol'>petrol:{{petrol}} km</div>
<div name='account'>NDIS {{account}}</div>
<div name='address'>{{address}}</div>
</div>
<div class="back">
<span name='badge' class='badge pink'><a href="/pending-jobs/{{login}}">{{unconfirmedjob}}</a></span> <span

+ 32
- 10
ts.php View File

@@ -182,15 +182,6 @@ class AcareOffice{
function list_staff(){
check_ajax_referer('acaresydney');
return $this->list_people_by_role('staff');
}
function list_client(){
check_ajax_referer('acaresydney');
return $this->list_people_by_role('client');
}
function list_people_by_role($role){
check_ajax_referer('acaresydney');
// Handle the ajax request
$response = array(
@@ -198,7 +189,7 @@ class AcareOffice{
'users' => [],
);
//search all users that are staff
$staffq = new \WP_User_Query(array('role'=>$role));
$staffq = new \WP_User_Query(array('role'=>'staff'));
$staff = $staffq->get_results();
if (! empty($staff)){
$response['status'] = 'success';
@@ -221,6 +212,37 @@ class AcareOffice{
wp_send_json($response);
wp_die();
}
function list_client(){
check_ajax_referer('acaresydney');
// Handle the ajax request
$response = array(
'status' =>'error',
'users' => [],
);
//search all users that are staff
$clientq = new \WP_User_Query(array('role'=>'client'));
$client = $clientq->get_results();
if (! empty($client)){
$response['status'] = 'success';
foreach( $client as $s){
$response['users'][] = array(
'login' => $s->user_login,
'firstname'=> $s->first_name,
'lastname'=> $s->last_name,
'mobile'=> get_user_meta($s->ID, 'mobile', true),
'email'=> $s->user_email,
'account'=> get_user_meta($s->ID, 'account', true),
'address' => get_user_meta($s->ID, 'address', true),
'rating'=> 0,
'unconfirmedjob'=> 0,
);
}
}
wp_send_json($response);
wp_die();
}

private function get_people_by_role($role){
//search all users that are staff

Loading…
Cancel
Save