| //user profile page | //user profile page | ||||
| add_shortcode( 'bts_user_name', array($this,'bts_user_name')); | 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 | // hook add_rewrite_rules function into rewrite_rules_array | ||||
| add_filter('rewrite_rules_array', array($this,'my_add_rewrite_rules')); | add_filter('rewrite_rules_array', array($this,'my_add_rewrite_rules')); | ||||
| // hook add_query_vars function into query_vars | // hook add_query_vars function into query_vars | ||||
| add_filter('query_vars', array($this,'add_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() | private function setup_db_name() | ||||
| $date = new \Datetime($record->finish); | $date = new \Datetime($record->finish); | ||||
| $finish = $date->format("Y-m-d"); | $finish = $date->format("Y-m-d"); | ||||
| $quantity = $this->get_job_hours($record->start, $record->finish); | $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); | $unitprice = $this->get_ndis_price()->get_tos_price($record->tos); | ||||
| $authorizedby="helen"; | $authorizedby="helen"; | ||||
| $participant_approved = ""; | $participant_approved = ""; | ||||
| switch($pagename){ | switch($pagename){ | ||||
| case 'task': | case 'task': | ||||
| $this->cauth_task(); | |||||
| $this->cauth_task(); //for staff | |||||
| break; | break; | ||||
| case 'time-sheets': | 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; | break; | ||||
| case 'feedback_card': | case 'feedback_card': | ||||
| $this->cauth_feedback_card(); | |||||
| $this->cauth_feedback_card(); //for client | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| wp_redirect("/time-sheets/"); | wp_redirect("/time-sheets/"); | ||||
| return; | return; | ||||
| } | } | ||||
| if ($this->is_accountant($current)){ | |||||
| wp_redirect("/xeroc/"); | |||||
| return; | |||||
| } | |||||
| if (!$this->is_staff($current) && ! $this->is_admin($current)) | if (!$this->is_staff($current) && ! $this->is_admin($current)) | ||||
| { | { | ||||
| wp_logout(); | wp_logout(); | ||||
| wp_redirect("/task"); | wp_redirect("/task"); | ||||
| return; | return; | ||||
| } | } | ||||
| if ($this->is_accountant($current)){ | |||||
| wp_redirect("/xeroc"); | |||||
| return; | |||||
| } | |||||
| if ($this->is_admin($current)){ | if ($this->is_admin($current)){ | ||||
| //proceed | //proceed | ||||
| return; | return; | ||||
| wp_redirect("/?invalid-access"); | 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 | // enqueue / register css /js | ||||
| // | // | ||||
| } | } | ||||
| function list_client(){ | function list_client(){ | ||||
| check_ajax_referer('acaresydney'); | check_ajax_referer('acaresydney'); | ||||
| $user = wp_get_current_user(); | |||||
| // Handle the ajax request | // Handle the ajax request | ||||
| $response = array( | $response = array( | ||||
| 'status' =>'error', | 'status' =>'error', | ||||
| 'users' => [], | 'users' => [], | ||||
| 'role' => $user, | |||||
| ); | ); | ||||
| //search all users that are staff | //search all users that are staff | ||||
| $clientq = new \WP_User_Query(array('role'=>'client', 'meta_key'=>'first_name', 'orderby'=>'meta_value', 'order'=>'ASC')); | $clientq = new \WP_User_Query(array('role'=>'client', 'meta_key'=>'first_name', 'orderby'=>'meta_value', 'order'=>'ASC')); | ||||
| } | } | ||||
| //ajax get earnings rates | //ajax get earnings rates | ||||
| function get_payitem_earnings_rate() | |||||
| function earnings_rate() | |||||
| { | { | ||||
| $response= array( | $response= array( | ||||
| 'status' => 'success', | 'status' => 'success', | ||||
| } | } | ||||
| private function is_admin($user) | private function is_admin($user) | ||||
| { | { | ||||
| $allowed_roles = array('administrator', 'acare_owner'); | |||||
| $allowed_roles = array('administrator', 'admin'); | |||||
| if( array_intersect($allowed_roles, $user->roles ) ) { | if( array_intersect($allowed_roles, $user->roles ) ) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| private function is_accountant($user) | |||||
| { | |||||
| return ($user->ID !=0 && in_array('accountant', $user->roles)); | |||||
| } | |||||
| public function staff_ack_job() | public function staff_ack_job() | ||||
| { | { | ||||
| check_ajax_referer('acaresydney'); | check_ajax_referer('acaresydney'); | ||||
| return sprintf('%0.2f', $hours); | 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() | public function feedback_url() | ||||
| { | { | ||||
| $users = get_users(array('role'=>'client')); | $users = get_users(array('role'=>'client')); |