|
|
|
@@ -18,10 +18,14 @@ class AcareOffice{ |
|
|
|
private $nonce; //for ajax verification |
|
|
|
private $pages = array('time-sheets', 'user-list'); |
|
|
|
private $acaresydney_userid = 0; |
|
|
|
|
|
|
|
private $xero ; |
|
|
|
private $xero ; |
|
|
|
private $db; |
|
|
|
private $table_name; |
|
|
|
|
|
|
|
public function __construct() { |
|
|
|
add_option( "acare_ts_db_version", "1.0" ); |
|
|
|
register_activation_hook( __FILE__, array($this, 'db_install') ); |
|
|
|
|
|
|
|
add_action('init', array($this, 'class_loader')); |
|
|
|
add_action('wp', array($this, 'check_auth')); |
|
|
|
add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); |
|
|
|
@@ -34,17 +38,24 @@ class AcareOffice{ |
|
|
|
add_shortcode( 'bts_staff_item', array($this, 'bts_staff_item')); |
|
|
|
add_shortcode( 'bts_client_item', array($this, 'bts_client_item')); |
|
|
|
add_shortcode( 'bts_job_item', array($this, 'bts_job_item')); |
|
|
|
add_shortcode( 'bts_hours_options', array($this, 'bts_hours_options')); |
|
|
|
add_shortcode( 'bts_rate_options', array($this, 'bts_rate_options')); |
|
|
|
add_shortcode( 'bts_select_staff', array($this, 'bts_select_staff')); |
|
|
|
add_shortcode( 'bts_select_client', array($this, 'bts_select_client')); |
|
|
|
|
|
|
|
add_action('wp_ajax_list_staff', array($this,'list_staff' )); |
|
|
|
add_action('wp_ajax_list_client', array($this,'list_client' )); |
|
|
|
add_action('wp_ajax_save_job', array($this,'save_job' )); |
|
|
|
add_action('wp_ajax_list_job', array($this,'list_job' )); |
|
|
|
add_action('wp_ajax_delete_job', array($this,'delete_job' )); |
|
|
|
|
|
|
|
add_action('wp_ajax_earnings_rate', array($this,'get_payitem_earnings_rate' )); |
|
|
|
add_action('wp_ajax_nopriv_earnings_rate', array($this,'get_payitem_earnings_rate' )); |
|
|
|
|
|
|
|
|
|
|
|
global $wpdb; |
|
|
|
$this->db = $wpdb; |
|
|
|
$this->table_name = $wpdb->prefix . 'acare_ts'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -66,6 +77,51 @@ class AcareOffice{ |
|
|
|
$this->xero->init_wp(); |
|
|
|
} |
|
|
|
|
|
|
|
//init database |
|
|
|
public function db_install () { |
|
|
|
global $wpdb; |
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
|
|
|
|
|
|
|
//table name: broker transactions |
|
|
|
$table_name = $this->table_name; |
|
|
|
|
|
|
|
$sql = "CREATE TABLE $table_name ( |
|
|
|
id INT NOT NULL AUTO_INCREMENT, |
|
|
|
tos VARCHAR(45) NULL, |
|
|
|
start DATETIME NULL, |
|
|
|
finish DATETIME NULL, |
|
|
|
rate VARCHAR(45) NULL, |
|
|
|
staff VARCHAR(45) NULL, |
|
|
|
client VARCHAR(45) NULL, |
|
|
|
ack TINYINT(4) NULL, |
|
|
|
rating INT NULL DEFAULT 0, |
|
|
|
PRIMARY KEY (id) |
|
|
|
) $charset_collate;"; |
|
|
|
|
|
|
|
// $sql = "CREATE TABLE $table_name ( |
|
|
|
// id int(64) NOT NULL AUTO_INCREMENT, |
|
|
|
// paid tinyint(4) DEFAULT NULL, |
|
|
|
// referal varchar(45) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, |
|
|
|
// clientid int(64) NOT NULL, |
|
|
|
// loanamount float DEFAULT NULL, |
|
|
|
// settledate date DEFAULT NULL, |
|
|
|
// loanterm mediumint(10) DEFAULT NULL, |
|
|
|
// commissionrate float DEFAULT NULL, |
|
|
|
// commission float DEFAULT NULL, |
|
|
|
// trailrate float DEFAULT NULL, |
|
|
|
// trail float DEFAULT NULL, |
|
|
|
// paydate date DEFAULT NULL, |
|
|
|
// brokerid int(64) NOT NULL, |
|
|
|
// status tinyint(4) NOT NULL, |
|
|
|
// notes varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, |
|
|
|
// PRIMARY KEY (id) |
|
|
|
// ) $charset_collate;"; |
|
|
|
|
|
|
|
//create database |
|
|
|
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
|
|
dbDelta( $sql ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
// |
|
|
|
@@ -140,7 +196,7 @@ class AcareOffice{ |
|
|
|
return $html; |
|
|
|
} |
|
|
|
|
|
|
|
public function bts_hours_options($attr){ |
|
|
|
public function bts_rate_options($attr){ |
|
|
|
$result = "<select> \n"; |
|
|
|
$options = get_option('bts_payitem_earnings_rate'); |
|
|
|
foreach($options as $o){ |
|
|
|
@@ -242,7 +298,6 @@ class AcareOffice{ |
|
|
|
wp_die(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function get_people_by_role($role){ |
|
|
|
//search all users that are staff |
|
|
|
@@ -261,7 +316,107 @@ class AcareOffice{ |
|
|
|
wp_send_json($response); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//ajax job CRUD |
|
|
|
function save_job() |
|
|
|
{ |
|
|
|
check_ajax_referer('acaresydney'); |
|
|
|
$r = $_POST['record']; |
|
|
|
$response = array(); |
|
|
|
$d = array( |
|
|
|
'tos' => $r['tos'], |
|
|
|
'start' => $r['start'], |
|
|
|
'finish' => $r['finish'], |
|
|
|
'rate' => $r['rate'], |
|
|
|
'staff' => $r['staff'], |
|
|
|
'client' => $r['client'], |
|
|
|
'ack' => $r['ack']=='true'?1:0, |
|
|
|
); |
|
|
|
|
|
|
|
//this is an update |
|
|
|
if ( isset($r['id']) && trim($r['id']) !='' && is_numeric($r['id'])){ |
|
|
|
$response['isNew'] = false; //add or update? |
|
|
|
$result = $this->update($d, array('id' =>$r['id'])); |
|
|
|
if ($result !== false && $this->db->last_error == ''){ |
|
|
|
$d['id'] = $r['id']; |
|
|
|
$response['status'] = 'success'; |
|
|
|
//do data type conversion, string to int |
|
|
|
$response['newdata'] = $this->get_ts_record($r['id']); |
|
|
|
$response['errors'] = array(); //empty array |
|
|
|
}else{ |
|
|
|
$response['status'] = 'error'; |
|
|
|
$repsonse['errors'] = array( |
|
|
|
'db' => "network database error" . $this->db->last_error, |
|
|
|
); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
$response['isNew'] = true; |
|
|
|
$result = $this->db->insert($this->table_name, $d); |
|
|
|
$lastid = $this->db->insert_id; |
|
|
|
if ($result != false && $this->db->last_error == ''){ |
|
|
|
$response['status'] = 'success'; |
|
|
|
$response['newdata'] = $this->get_ts_record($lastid); |
|
|
|
}else{ |
|
|
|
$response['status'] = 'error'; |
|
|
|
$response['errors'] = array( |
|
|
|
'db' => 'network database error ' . $this->db->last_error, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
wp_send_json($response); |
|
|
|
wp_die(); |
|
|
|
} |
|
|
|
|
|
|
|
private function get_ts_record($id){ |
|
|
|
$sql = "SELECT * FROM $this->table_name WHERE id=%d"; |
|
|
|
$row = $this->db->get_row($this->db->prepare ($sql, array($id))); |
|
|
|
$response = []; |
|
|
|
if ($row != null){ |
|
|
|
$response = array( |
|
|
|
'id' => (int)$row->id, |
|
|
|
'tos' => $row->tos, |
|
|
|
'start' => $row->start, |
|
|
|
'finish' => $row->finish, |
|
|
|
'rate' => $row->rate, |
|
|
|
'staff' => $row->staff, |
|
|
|
'client' => $row->client, |
|
|
|
'ack' => (int)$row->ack, |
|
|
|
'rating' =>(int) $row->rating, |
|
|
|
); |
|
|
|
} |
|
|
|
return $response; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//ajax delete job |
|
|
|
function delete_job(){ |
|
|
|
check_ajax_referer('acaresydney'); |
|
|
|
$id = $_POST['recordid']; |
|
|
|
$result = $this->db->delete($this->table_name, array('id'=> $id)); |
|
|
|
$response=array( |
|
|
|
'status' => 'success', |
|
|
|
'id' => $id, |
|
|
|
'action'=> 'delete', |
|
|
|
'error' => '', |
|
|
|
); |
|
|
|
if ($result == 1){ |
|
|
|
wp_send_json($response); |
|
|
|
}else{ |
|
|
|
$response['status'] = 'error'; |
|
|
|
$response['error'] = $this->db->last_error; |
|
|
|
wp_send_json($response); |
|
|
|
} |
|
|
|
wp_die(); |
|
|
|
} |
|
|
|
|
|
|
|
//ajax browse job with different filters |
|
|
|
function list_job(){ |
|
|
|
check_ajax_referer('acaresydney'); |
|
|
|
$r = $_POST['record']; |
|
|
|
$response = array(); |
|
|
|
wp_send_json($response); |
|
|
|
wp_die(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$bb = new AcareOffice(); |