| @@ -69,47 +69,37 @@ class AcareOffice{ | |||
| //user profile page | |||
| add_shortcode( 'bts_user_name', array($this,'bts_user_name')); | |||
| 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' )); | |||
| add_action('wp_ajax_delete_job', array($this,'delete_job' )); | |||
| add_action('wp_ajax_email_job', array($this,'email_job' )); | |||
| add_action('wp_ajax_email_feedback_url', array($this,'email_feedback_url' )); | |||
| 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' )); | |||
| add_action('wp_ajax_list_job_by_staff', array($this,'list_job_by_staff' )); | |||
| add_action('wp_ajax_nopriv_list_job_by_staff', array($this,'list_job_by_staff' )); | |||
| add_action('wp_ajax_staff_ack_job', array($this,'staff_ack_job' )); | |||
| add_action('wp_ajax_nopriv_staff_ack_job', array($this,'staff_ack_job' )); | |||
| add_action('wp_ajax_list_job_by_client', array($this,'list_job_by_client' )); | |||
| add_action('wp_ajax_nopriv_list_job_by_client', array($this,'list_job_by_client' )); | |||
| add_action('wp_ajax_client_ack_job', array($this,'client_ack_job' )); | |||
| add_action('wp_ajax_nopriv_client_ack_job', array($this,'client_ack_job' )); | |||
| add_action('wp_ajax_get_timesheet_from_xero', array($this,'get_timesheet_from_xero' )); | |||
| add_action('wp_ajax_approve_all_timesheet', array($this,'approve_all_timesheet' )); | |||
| add_action('wp_ajax_get_invoice_item', array($this,'get_invoice_item' )); | |||
| add_action('wp_ajax_create_invoice_in_xero', array($this,'create_invoice_in_xero' )); | |||
| $this->ajax_hook('list_staff'); | |||
| $this->ajax_hook('list_client'); | |||
| $this->ajax_hook('list_tos'); | |||
| $this->ajax_hook('save_job'); | |||
| $this->ajax_hook('list_job'); | |||
| $this->ajax_hook('delete_job'); | |||
| $this->ajax_hook('email_job'); | |||
| $this->ajax_hook('email_feedback_url'); | |||
| $this->ajax_hook('earnings_rate'); | |||
| $this->ajax_hook('list_job_by_staff'); | |||
| $this->ajax_hook('staff_ack_job'); | |||
| $this->ajax_hook('list_job_by_client'); | |||
| $this->ajax_hook('client_ack_job'); | |||
| $this->ajax_hook('get_timesheet_from_xero'); | |||
| $this->ajax_hook('approve_all_timesheet'); | |||
| $this->ajax_hook('get_invoice_item'); | |||
| $this->ajax_hook('create_invoice_in_xero'); | |||
| // hook add_rewrite_rules function into rewrite_rules_array | |||
| add_filter('rewrite_rules_array', array($this,'my_add_rewrite_rules')); | |||
| // hook add_query_vars function into query_vars | |||
| add_filter('query_vars', array($this,'add_query_vars')); | |||
| } | |||
| private function ajax_hook($code, $admin_only = false) | |||
| { | |||
| add_action("wp_ajax_$code", array($this,$code )); | |||
| if (!$admin_only) { | |||
| add_action("wp_ajax_nopriv_$code", array($this,$code)); | |||
| } | |||
| } | |||
| private function setup_db_name() | |||
| @@ -203,7 +193,7 @@ class AcareOffice{ | |||
| $date = new \Datetime($record->finish); | |||
| $finish = $date->format("Y-m-d"); | |||
| $quantity = $this->get_job_hours($record->start, $record->finish); | |||
| $hours = $quantity; | |||
| $hours = $this->get_job_hours_hh_mm($record->start, $record->finish); | |||
| $unitprice = $this->get_ndis_price()->get_tos_price($record->tos); | |||
| $authorizedby="helen"; | |||
| $participant_approved = ""; | |||
| @@ -324,13 +314,17 @@ class AcareOffice{ | |||
| switch($pagename){ | |||
| case 'task': | |||
| $this->cauth_task(); | |||
| $this->cauth_task(); //for staff | |||
| break; | |||
| case 'time-sheets': | |||
| $this->cauth_time_sheet(); | |||
| case 'office': | |||
| $this->cauth_time_sheet(); //for admin | |||
| break; | |||
| case 'xeroc': | |||
| $this->cauth_xero_sync(); //for accountant | |||
| break; | |||
| case 'feedback_card': | |||
| $this->cauth_feedback_card(); | |||
| $this->cauth_feedback_card(); //for client | |||
| break; | |||
| } | |||
| } | |||
| @@ -371,6 +365,12 @@ class AcareOffice{ | |||
| wp_redirect("/time-sheets/"); | |||
| return; | |||
| } | |||
| if ($this->is_accountant($current)){ | |||
| wp_redirect("/xeroc/"); | |||
| return; | |||
| } | |||
| if (!$this->is_staff($current) && ! $this->is_admin($current)) | |||
| { | |||
| wp_logout(); | |||
| @@ -463,6 +463,10 @@ class AcareOffice{ | |||
| wp_redirect("/task"); | |||
| return; | |||
| } | |||
| if ($this->is_accountant($current)){ | |||
| wp_redirect("/xeroc"); | |||
| return; | |||
| } | |||
| if ($this->is_admin($current)){ | |||
| //proceed | |||
| return; | |||
| @@ -475,6 +479,16 @@ class AcareOffice{ | |||
| wp_redirect("/?invalid-access"); | |||
| } | |||
| private function cauth_xero_sync() | |||
| { | |||
| $current = wp_get_current_user(); | |||
| if ($this->is_admin($current) ||$this->is_accountant($current) ){ | |||
| //proceed | |||
| return; | |||
| } | |||
| wp_redirect("/?invalid-access"); | |||
| } | |||
| /// | |||
| // enqueue / register css /js | |||
| // | |||
| @@ -867,10 +881,12 @@ ZOT; | |||
| } | |||
| function list_client(){ | |||
| check_ajax_referer('acaresydney'); | |||
| $user = wp_get_current_user(); | |||
| // Handle the ajax request | |||
| $response = array( | |||
| 'status' =>'error', | |||
| 'users' => [], | |||
| 'role' => $user, | |||
| ); | |||
| //search all users that are staff | |||
| $clientq = new \WP_User_Query(array('role'=>'client', 'meta_key'=>'first_name', 'orderby'=>'meta_value', 'order'=>'ASC')); | |||
| @@ -919,7 +935,7 @@ ZOT; | |||
| } | |||
| //ajax get earnings rates | |||
| function get_payitem_earnings_rate() | |||
| function earnings_rate() | |||
| { | |||
| $response= array( | |||
| 'status' => 'success', | |||
| @@ -1166,12 +1182,17 @@ ZOT; | |||
| } | |||
| private function is_admin($user) | |||
| { | |||
| $allowed_roles = array('administrator', 'acare_owner'); | |||
| $allowed_roles = array('administrator', 'admin'); | |||
| if( array_intersect($allowed_roles, $user->roles ) ) { | |||
| return true; | |||
| } | |||
| } | |||
| private function is_accountant($user) | |||
| { | |||
| return ($user->ID !=0 && in_array('accountant', $user->roles)); | |||
| } | |||
| public function staff_ack_job() | |||
| { | |||
| check_ajax_referer('acaresydney'); | |||
| @@ -1609,6 +1630,20 @@ By Carer : %s', | |||
| return sprintf('%0.2f', $hours); | |||
| } | |||
| private function get_job_hours_hh_mm($start, $finish) | |||
| { | |||
| $hours = 0; | |||
| $s = strtotime($start); | |||
| $f = strtotime($finish); | |||
| $diff = $f- $s; | |||
| $hours = floor($diff * 1.0 / 3600); //down to integer | |||
| $minutes = round( (($diff * 1.0) % 3600) / 60) ; //round to integer; | |||
| if ($minutes <10) | |||
| $minutes = "0$minutes"; | |||
| return "$hours:$minutes"; | |||
| } | |||
| public function feedback_url() | |||
| { | |||
| $users = get_users(array('role'=>'client')); | |||