| $response = array( | $response = array( | ||||
| 'status'=>'success', | 'status'=>'success', | ||||
| 'jobs' => [], | '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)); | $query = $wpdb->prepare ($sql, array($start, $finish)); | ||||
| $response['sql'] = $query; | $response['sql'] = $query; | ||||
| $jobs = $wpdb->get_results($query); | $jobs = $wpdb->get_results($query); | ||||
| if (! empty($jobs)){ | if (! empty($jobs)){ | ||||
| $response['status'] = 'success'; | $response['status'] = 'success'; | ||||
| foreach( $jobs as $s){ | foreach( $jobs as $s){ | ||||
| $response['jobs'][] = array( | |||||
| $data = array( | |||||
| 'id' => $s->id, | 'id' => $s->id, | ||||
| 'tos' => $s->tos, | 'tos' => $s->tos, | ||||
| 'start'=> $s->start, | 'start'=> $s->start, | ||||
| 'ack' => $s->ack, | 'ack' => $s->ack, | ||||
| 'rating' =>$s->rating, | 'rating' =>$s->rating, | ||||
| ); | ); | ||||
| $response['jobs'][] = $data; | |||||
| $response['jobs_maps'][$s->id] = $data; | |||||
| } | } | ||||
| } | } | ||||
| wp_send_json($response); | wp_send_json($response); | ||||
| wp_die(); | |||||
| } | } | ||||
| } | } |
| private $tos =[]; | private $tos =[]; | ||||
| public function __construct(int $year=2019) { | public function __construct(int $year=2019) { | ||||
| global $wpdb; | global $wpdb; | ||||
| if ( $year == "2019"){ | |||||
| $now = new \DateTime(); | |||||
| $year = (int)($now->format("Y")); | |||||
| } | |||||
| $this->ndis_table = $wpdb->prefix . 'acare_ndis_price'; | $this->ndis_table = $wpdb->prefix . 'acare_ndis_price'; | ||||
| $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year | $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year | ||||
| $results = $wpdb->get_results($sql); | $results = $wpdb->get_results($sql); | ||||
| $this->tos =[]; | $this->tos =[]; | ||||
| $html = ' <select>'; | $html = ' <select>'; | ||||
| foreach($results as $r){ | foreach($results as $r){ | ||||
| $this->tos[] = $r; | |||||
| $this->tos[$r->code] = $r; | |||||
| $html .= sprintf('<option value="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>', | $html .= sprintf('<option value="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>', | ||||
| $r->code, | $r->code, | ||||
| $r->level, | $r->level, | ||||
| public function get_tos_str($ndis_code) | public function get_tos_str($ndis_code) | ||||
| { | { | ||||
| //return $this->tos[$ndis_code]->name; | |||||
| foreach ($this->tos as $r){ | foreach ($this->tos as $r){ | ||||
| if ($ndis_code == $r->code) | if ($ndis_code == $r->code) | ||||
| return $r->name; | return $r->name; | ||||
| } | } | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| public function get_tos_array() | |||||
| { | |||||
| foreach ($this->tos as $r){ | |||||
| $r->tos_full_str = sprintf("%.2f - %s %s %s", | |||||
| (float) $r->price, | |||||
| $r->name, | |||||
| $this->get_level((int) $r->level), | |||||
| $r->ot); | |||||
| } | |||||
| return $this->tos; | |||||
| } | |||||
| } | } |
| <div class="divTable blueTable" id="job_{{jobid}}" data-id="{{jobid}}"> | |||||
| {{#jobs}} | |||||
| <div class="divTable blueTable " id="job_{{id}}" | |||||
| data-id="{{id}}" data-tos="{{tos}}" data-rate="{{rate}}" data-staff="{{staff}}" data-client="{{client}}"> | |||||
| <div class="divTableBody"> | <div class="divTableBody"> | ||||
| <div class="divTableRow"> | <div class="divTableRow"> | ||||
| <input type='hidden' name='id' value=''> | |||||
| <div class="divTableCell btos"> | <div class="divTableCell btos"> | ||||
| {{tos_name}} | {{tos_name}} | ||||
| </div> | </div> | ||||
| <div class="divTableCell bstaff_err">estaf</div> | <div class="divTableCell bstaff_err">estaf</div> | ||||
| <div class="divTableCell bclient_err">ecli</div> | <div class="divTableCell bclient_err">ecli</div> | ||||
| <div class="divTableCell bconfirmed_err">econfirm</div> | <div class="divTableCell bconfirmed_err">econfirm</div> | ||||
| <div class="divTableCell brating_err">erat</div> | |||||
| <div class="divTableCell brating_err">e rat</div> | |||||
| <div class="divTableCell bdelete_err">edel</div> | <div class="divTableCell bdelete_err">edel</div> | ||||
| <div class="divTableCell bsave_err">eeave</div> | <div class="divTableCell bsave_err">eeave</div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | |||||
| </div> | |||||
| {{/jobs}} |
| }).done(function(response, status, xhr){ | }).done(function(response, status, xhr){ | ||||
| if (response.status =='success'){ | if (response.status =='success'){ | ||||
| bts().staff = response.users; | bts().staff = response.users; | ||||
| bts().staff_map = {}; | |||||
| response.users.forEach(function(u){ | response.users.forEach(function(u){ | ||||
| bts().staff_map[u.login] = u; | |||||
| var html = bts_staff_html(u); | var html = bts_staff_html(u); | ||||
| jQuery('div.stafflist').append(html); | jQuery('div.stafflist').append(html); | ||||
| new People("#p" + u.login,'#staff_item', u); | new People("#p" + u.login,'#staff_item', u); | ||||
| }, function(response, status, xhr){ | }, function(response, status, xhr){ | ||||
| if (response.status =='success'){ | if (response.status =='success'){ | ||||
| bts().client = response.users; | bts().client = response.users; | ||||
| bts().client_map = {}; | |||||
| response.users.forEach(function(u){ | response.users.forEach(function(u){ | ||||
| bts().client_map[u.login] = u; | |||||
| hide_loading_client(); | hide_loading_client(); | ||||
| var html = bts_client_html(u); | var html = bts_client_html(u); | ||||
| jQuery('div.clientlist').append(html); | jQuery('div.clientlist').append(html); | ||||
| }); | }); | ||||
| } | } | ||||
| 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(){ | function show_loading_staff(){ | ||||
| jQuery('div.stafflist img').attr('src', bts().load_user_img).show(); | jQuery('div.stafflist img').attr('src', bts().load_user_img).show(); | ||||
| } | } | ||||
| finish: format_date(last), | finish: format_date(last), | ||||
| }, function(response, status, xhr){ | }, function(response, status, xhr){ | ||||
| if (response.status =='success'){ | 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{ | }else{ | ||||
| alert('error loading job'); | 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){ | function show_jobs(job_els, in_ajax){ | ||||
| if (job_els.length >0){ | if (job_els.length >0){ | ||||
| $('div.workspace').append(job_els); | $('div.workspace').append(job_els); | ||||
| function init_ts(){ | function init_ts(){ | ||||
| show_loading_jobs(); | 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); | xero(false); | ||||
| wifi(false); | wifi(false); | ||||
| csv(false); | csv(false); | ||||
| init_user_search(); | init_user_search(); | ||||
| //ajax_earning_rate(); | |||||
| reset_title_to_today(); | reset_title_to_today(); | ||||
| load_timesheet(); | load_timesheet(); | ||||
| } | } |
| register_activation_hook( __FILE__, array($this, 'db_install') ); | register_activation_hook( __FILE__, array($this, 'db_install') ); | ||||
| //add_action('init', array($this, 'class_loader')); | //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', array($this, 'check_auth')); | ||||
| add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); | add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); | ||||
| add_action('wp_ajax_list_staff', array($this,'list_staff' )); | 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_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_save_job', array($this,'save_job' )); | ||||
| add_action('wp_ajax_list_job', array($this,'list_job' )); | add_action('wp_ajax_list_job', array($this,'list_job' )); | ||||
| //$abc = new AddrMap("01515b52-6936-46b2-a000-9ad4cd7a5b50", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); | //$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"); | //$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']; | $url = $_SERVER['REQUEST_URI']; | ||||
| $matches=[]; | $matches=[]; | ||||
| wp_die(); | 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){ | private function get_people_by_role($role){ | ||||
| //search all users that are staff | //search all users that are staff | ||||
| 'jobs'=>[], | 'jobs'=>[], | ||||
| 'err'=>'' | 'err'=>'' | ||||
| ]; | ]; | ||||
| $now = new \DateTime(); | |||||
| $price = new NdisPrice($now->format("Y"));//current year; | |||||
| $price = new NdisPrice();//current year; | |||||
| $summary=[];// by ndis code | $summary=[];// by ndis code | ||||
| foreach($rows as $r){ | foreach($rows as $r){ | ||||
| $quantity = $this->get_job_hours($r->start, $r->finish); | $quantity = $this->get_job_hours($r->start, $r->finish); |