Sfoglia il codice sorgente

client has ndis and addresss

master
patrick 6 anni fa
parent
commit
22e85ded33
3 ha cambiato i file con 87 aggiunte e 15 eliminazioni
  1. +52
    -2
      Xero.php
  2. +3
    -3
      html/client.html
  3. +32
    -10
      ts.php

+ 52
- 2
Xero.php Vedi File



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


class Xero { class Xero {
private $xero; private $xero;
$this->logConsole($msg); $this->logConsole($msg);
try{ try{
//$this->sync_clients();
$this->sync_employees();
$this->sync_clients();
//$this->sync_employees();
}catch(RateLimitExceededException $e){ }catch(RateLimitExceededException $e){
$msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n"; $msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg); $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(){ private function sync_clients(){
$contacts = $this->getClients($this->clientgroup); $contacts = $this->getClients($this->clientgroup);
$args = $this->xero_contact_profile($xero_contact); $args = $this->xero_contact_profile($xero_contact);
$id = wp_insert_user($args); $id = wp_insert_user($args);
$user = get_user_by('ID', $id); $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 }else{//update user
if ($this->is_too_close_to_sync($user)){ if ($this->is_too_close_to_sync($user)){
return; return;
$args['ID'] = $user->ID; $args['ID'] = $user->ID;
unset($args['user_pass']); //we don't change password unset($args['user_pass']); //we don't change password
wp_update_user($args); 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); $this->mark_updated($user->ID);
} }
'first_name' => $c->getFirstName(), 'first_name' => $c->getFirstName(),
'last_name' => $c->getLastName(), 'last_name' => $c->getLastName(),
'nickname' => $c->getName(), 'nickname' => $c->getName(),
'account' => $c->getAccountNumber(),
'address'=> $this->get_post_address($c),
'role' => 'client', 'role' => 'client',
]; ];
return $args; 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) private function ensure_staff_exists($employee)
{ {
$args = $this->xero_employee_profile($xero_employee); $args = $this->xero_employee_profile($xero_employee);
$id = wp_insert_user($args); $id = wp_insert_user($args);
$user = get_user_by('ID', $id); $user = get_user_by('ID', $id);
update_user_meta($user->ID, 'mobile', $args['mobile']);
}else{ }else{
if ($this->is_too_close_to_sync($user)){ if ($this->is_too_close_to_sync($user)){
return; return;

+ 3
- 3
html/client.html Vedi File

<label class='peopleitem' data-id=p{{login}} > <input type="checkbox"/> <label class='peopleitem' data-id=p{{login}} > <input type="checkbox"/>
<div class="card"> <div class="card">
<div class="front"> <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> 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='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>
<div class="back"> <div class="back">
<span name='badge' class='badge pink'><a href="/pending-jobs/{{login}}">{{unconfirmedjob}}</a></span> <span <span name='badge' class='badge pink'><a href="/pending-jobs/{{login}}">{{unconfirmedjob}}</a></span> <span

+ 32
- 10
ts.php Vedi File

function list_staff(){ 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'); check_ajax_referer('acaresydney');
// Handle the ajax request // Handle the ajax request
$response = array( $response = array(
'users' => [], 'users' => [],
); );
//search all users that are staff //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(); $staff = $staffq->get_results();
if (! empty($staff)){ if (! empty($staff)){
$response['status'] = 'success'; $response['status'] = 'success';
wp_send_json($response); wp_send_json($response);
wp_die(); 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){ private function get_people_by_role($role){
//search all users that are staff //search all users that are staff

Loading…
Annulla
Salva