diff --git a/Apiv1.php b/Apiv1.php index b18eed7..f199d80 100644 --- a/Apiv1.php +++ b/Apiv1.php @@ -39,10 +39,11 @@ class Apiv1{ $response = array( 'status'=>'success', 'jobs' => [], + 'job_maps' =>[], ); - //$sql = "SELECT * FROM $this->table_name WHERE start>='%s' and start <='%s' order by start ASC ,staff ASC"; - $sql = "SELECT * FROM $this->job_table order by start ASC ,staff ASC"; + $sql = "SELECT * FROM $this->job_table WHERE start>='%s' and start <='%s' order by start ASC ,staff ASC"; + //$sql = "SELECT * FROM $this->job_table order by start ASC ,staff ASC"; $query = $wpdb->prepare ($sql, array($start, $finish)); $response['sql'] = $query; $jobs = $wpdb->get_results($query); @@ -50,7 +51,7 @@ class Apiv1{ if (! empty($jobs)){ $response['status'] = 'success'; foreach( $jobs as $s){ - $response['jobs'][] = array( + $data = array( 'id' => $s->id, 'tos' => $s->tos, 'start'=> $s->start, @@ -61,9 +62,11 @@ class Apiv1{ 'ack' => $s->ack, 'rating' =>$s->rating, ); + + $response['jobs'][] = $data; + $response['jobs_maps'][$s->id] = $data; } } wp_send_json($response); - wp_die(); } } \ No newline at end of file diff --git a/NdisPrice.php b/NdisPrice.php index 15487f9..ec04192 100644 --- a/NdisPrice.php +++ b/NdisPrice.php @@ -8,6 +8,13 @@ class NdisPrice{ private $tos =[]; public function __construct(int $year=2019) { global $wpdb; + + if ( $year == "2019"){ + $now = new \DateTime(); + $year = (int)($now->format("Y")); + } + + $this->ndis_table = $wpdb->prefix . 'acare_ndis_price'; $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year $results = $wpdb->get_results($sql); @@ -15,7 +22,8 @@ class NdisPrice{ $this->tos =[]; $html = '
{{tos_name}}
@@ -29,10 +30,11 @@
estaf
ecli
econfirm
-
erat
+
e rat
edel
eeave
- \ No newline at end of file + +{{/jobs}} \ No newline at end of file diff --git a/js/bts_office.js b/js/bts_office.js index 6d97123..d91a946 100644 --- a/js/bts_office.js +++ b/js/bts_office.js @@ -146,7 +146,9 @@ }).done(function(response, status, xhr){ if (response.status =='success'){ bts().staff = response.users; + bts().staff_map = {}; response.users.forEach(function(u){ + bts().staff_map[u.login] = u; var html = bts_staff_html(u); jQuery('div.stafflist').append(html); new People("#p" + u.login,'#staff_item', u); @@ -168,7 +170,9 @@ }, function(response, status, xhr){ if (response.status =='success'){ bts().client = response.users; + bts().client_map = {}; response.users.forEach(function(u){ + bts().client_map[u.login] = u; hide_loading_client(); var html = bts_client_html(u); jQuery('div.clientlist').append(html); @@ -180,6 +184,21 @@ }); } + function list_tos() { + wifi(true); + $.post(bts().ajax_url, { // POST request + _ajax_nonce: bts().nonce, // nonce + action: "list_tos", // action + }, function(response, status, xhr){ + if (response.status =='success'){ + bts().tos = response.tos; + wifi(false); + }else{ + alert('error getting Type of Service list'); + } + }); + } + function show_loading_staff(){ jQuery('div.stafflist img').attr('src', bts().load_user_img).show(); } @@ -1147,23 +1166,39 @@ finish: format_date(last), }, function(response, status, xhr){ if (response.status =='success'){ - var job_els = []; - response.jobs.forEach(function(job){ - //console.log('loading job... %o', job); - var o = new Job(job); - job_els.push(o.el); - }); - show_jobs(job_els, 'in-ajax=true'); - //filter it if reqired - debounced_filter_workspace(); + display_jobs_after_staff_client_tos_info_ready(response); }else{ alert('error loading job'); + hide_loading_jobs(); } - hide_loading_jobs(); }); } + function display_jobs_after_staff_client_tos_info_ready(response) + { + var b = bts(); + if ((typeof b.staff_map != "undefined" && Object.keys(b.staff_map).length > 0) && + (typeof b.client_map != "undefined" && Object.keys(b.client_map).length > 0) && + (typeof b.tos != "undefined" && Object.keys(b.tos).length > 0 )) + { + //we do works, load timesheets + var template = $("#jobv1_item").html(); + var html = Mustache.render(template, response); + $('div.workspace').append(html); + hide_loading_jobs(); + + //filter it if reqired + //debounced_filter_workspace(); + return; + } + console.log('wating staff/client/tos info to be ready'); + setTimeout(function(){ + display_jobs_after_staff_client_tos_info_ready(response); + }, 500); //try it half seconds later + } + + function show_jobs(job_els, in_ajax){ if (job_els.length >0){ $('div.workspace').append(job_els); @@ -1393,13 +1428,16 @@ function init_ts(){ show_loading_jobs(); - list_staff(); - list_clients(); + setTimeout(list_staff, 5000); // for testing delayed loading of jobs only + //list_staff(); + //list_clients(); + setTimeout(list_clients, 8000); // for testing delayed loading of jobs only + //list_tos(); + setTimeout(list_tos, 10000); // for testing delayed loading of jobs only xero(false); wifi(false); csv(false); init_user_search(); - //ajax_earning_rate(); reset_title_to_today(); load_timesheet(); } diff --git a/ts.php b/ts.php index fd1445c..39a80b2 100644 --- a/ts.php +++ b/ts.php @@ -39,6 +39,8 @@ class AcareOffice{ register_activation_hook( __FILE__, array($this, 'db_install') ); //add_action('init', array($this, 'class_loader')); + add_action('init', array($this, 'check_csv_download')); + add_action('wp', array($this, 'check_auth')); add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); @@ -68,6 +70,8 @@ class AcareOffice{ add_action('wp_ajax_list_staff', array($this,'list_staff' )); add_action('wp_ajax_list_client', array($this,'list_client' )); + add_action('wp_ajax_list_tos', array($this,'list_tos' )); + add_action('wp_ajax_save_job', array($this,'save_job' )); add_action('wp_ajax_list_job', array($this,'list_job' )); @@ -137,11 +141,9 @@ class AcareOffice{ //$abc = new AddrMap("01515b52-6936-46b2-a000-9ad4cd7a5b50", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); //$abc = new AddrMap("122eb1d0-d8c4-4fc3-8bf8-b7825bee1a01", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); - - $this->check_csv_download(); } - private function check_csv_download() + public function check_csv_download() { $url = $_SERVER['REQUEST_URI']; $matches=[]; @@ -805,6 +807,19 @@ ZOT; wp_die(); } + //ajax + function list_tos() { + check_ajax_referer('acaresydney'); + // Handle the ajax request + $response = array( + 'status' =>'success', + 'tos' => [], + ); + + $price = new NdisPrice();//current year; + $response['tos']= $price->get_tos_array(); + wp_send_json($response); + } private function get_people_by_role($role){ //search all users that are staff @@ -1303,9 +1318,7 @@ ZOT; 'jobs'=>[], 'err'=>'' ]; - $now = new \DateTime(); - $price = new NdisPrice($now->format("Y"));//current year; - + $price = new NdisPrice();//current year; $summary=[];// by ndis code foreach($rows as $r){ $quantity = $this->get_job_hours($r->start, $r->finish);