diff --git a/css/xeroc.css b/css/xeroc.css index afbcf8d..b5dafd9 100644 --- a/css/xeroc.css +++ b/css/xeroc.css @@ -27,7 +27,6 @@ } - .hidden{ display:none; } @@ -190,6 +189,21 @@ td.invoice_summary_header{ background-color: #ededed; } +table.invoice_preferred th.title{ + background-color: #e0e0e0; + font-weight: 900; + font-size: 1.3em; + text-shadow: 0px 0px 2px #dad8d8; +} + +table.invoice_not_preferred th.title{ + background-color: #e0e0e0; + font-weight: 900; + font-size: 1.3em; + text-shadow: 0px 0px 2px #dad8d8; +} + + .select_client_check_box span.client_name{ color: grey; font-size: 1.1em; diff --git a/img/loading_ndis.gif b/img/loading_ndis.gif new file mode 100644 index 0000000..82de25b Binary files /dev/null and b/img/loading_ndis.gif differ diff --git a/js/xeroc.js b/js/xeroc.js index 5795f76..dab0246 100644 --- a/js/xeroc.js +++ b/js/xeroc.js @@ -366,7 +366,7 @@ function on_download_ndis_csv (){} hide_loading_client(); response.users.forEach(function(u){ bts().client_map[u.login] = u; - if (u.payment != 'invoice') + if (u.account !="" && u.account != null &&(u.payment == '' || u.payment== 'ndis_baulk')) u.ndis_checked ="checked"; }); var html = Mustache.render(template,response); @@ -387,8 +387,16 @@ function on_download_ndis_csv (){} return clients; }; - function show_loading_client(){}; - function hide_loading_client(){}; + function show_loading_client(){ + var img = $('#loading_csv_waiting img'); + img.removeAttr('width'); + img.removeAttr('height'); + img.attr('src', bts().load_user_img); + $('#loading_csv_waiting').removeClass('hidden'); + }; + function hide_loading_client(){ + $('#loading_csv_waiting').addClass('hidden'); + }; function get_template(id, options) { @@ -456,6 +464,19 @@ function on_download_ndis_csv (){} $('input[name="finish"]').attr('value', val); }); + $(document).on('click', 'input.client_check', function(e){ + var val = $(this).prop('checked'); + var login = $(this).data().login; + var c = bts().client_map[login].account; + var name = bts().client_map[login].display_name; + if (val == true){ + if (c =="" || c ==null){ + $(this).prop('checked', false); + alert(name + " : has invalid NDIS account number "); + } + } + }); + $('#checkall').click(function(){ var val = $(this).prop('checked'); $('input.client_check').prop('checked', val); diff --git a/ts.php b/ts.php index e571ec6..25eb57e 100644 --- a/ts.php +++ b/ts.php @@ -17,6 +17,7 @@ require_once (ABSPATH . 'wp-includes/pluggable.php'); class AcareOffice{ + private $acare_ndis_registration = "4050024758"; private $nonce; //for ajax verification private $pages = array('time-sheets', 'user-list'); private $bts_user_id = 0; @@ -29,6 +30,7 @@ class AcareOffice{ private $addr_table; private $ndis_table; private $apiv1; + private $ndis_price; public function __construct() { $this->setup_db_name(); @@ -64,7 +66,6 @@ class AcareOffice{ add_shortcode( 'bts_client_invoice_template', array($this, 'bts_client_invoice_template')); add_shortcode( 'bts_csv_template', array($this, 'bts_csv_template')); add_shortcode( 'bts_invoiced_client', array($this, 'bts_invoiced_client')); - //user profile page add_shortcode( 'bts_user_name', array($this,'bts_user_name')); @@ -184,25 +185,33 @@ class AcareOffice{ exit(); } + private function get_ndis_price() + {//help to ensure ndis_price is only build once per call + if ( ! $this->ndis_price instanceof NdisPrice ) + $this->ndis_price = new NdisPrice(); + return $this->ndis_price; + } + private function ndis_csv_line($record) { $str = ""; - - $registration = "4500000"; + $price = $price = $this->get_ndis_price(); + $registration = $this->acare_ndis_registration; $ndisnumber = $this->get_client_ndis_account($record->client); $date = new \DateTime($record->start); $start = $date->format("Y-m-d"); $date = new \Datetime($record->finish); $finish = $date->format("Y-m-d"); - $quantity = 0; - $hours = 0; - $unitprice = 0; + $quantity = $this->get_job_hours($record->start, $record->finish); + $hours = $quantity; + $unitprice = $this->get_ndis_price()->get_tos_price($record->tos); $authorizedby="helen"; $participant_approved = ""; - $in_kind_program =""; + $GST = $this->get_client_GST($record->client); + $in_kind_program = $this->get_client_in_kind_program($record->client); $ClaimType = "";// standard; $CancellationReason=""; - return "$registration,$ndisnumber,$start,$finish,$record->tos,REC_{$record->id},$quantity,$hours,$unitprice,P1,$authorizedby,$participant_approved,$in_kind_program,$ClaimType,$CancellationReason\n"; + return "$registration,$ndisnumber,$start,$finish,$record->tos,REC_{$record->id},$quantity,$hours,$unitprice,$GST,$authorizedby,$participant_approved,$in_kind_program,$ClaimType,$CancellationReason\n"; } private function get_client_ndis_account($client) @@ -211,6 +220,20 @@ class AcareOffice{ return get_user_meta($user->ID,'account',true); } + private function get_client_in_kind_program($client) + { + $user = get_user_by('login', $client); + return get_user_meta($user->ID,'in_kind_prog',true); + } + private function get_client_GST($client) + { + $user = get_user_by('login', $client); + $str = get_user_meta($user->ID,'gst',true); + if ($str == "") + return "P2"; + return $str; + } + //init database public function db_install () { global $wpdb; @@ -758,15 +781,19 @@ class AcareOffice{ public function bts_invoiced_client($attr) { + $attr = shortcode_atts([ + 'preferred' => 'true', + ], $attr); + $result = ""; $users = $users = get_users(array('role' => 'client')); $row = << + %s - + %s is loading .... please wait... @@ -775,13 +802,27 @@ ZOT; foreach ($users as $u) { $payment = get_user_meta($u->ID, 'payment', true); - if( $payment != 'invoice' ) - continue; //bypass - $result .= sprintf($row, $u->user_login, $u->user_login, $u->user_login, $u->display_name, - $u->user_login, $u->user_login, $u->user_login, $u->display_name); + + if ( $attr['preferred'] == 'true' ){ + if( $payment == 'invoice' ){ + $invoice_preferred = "invoice_preferred"; + $result .= sprintf($row, + $u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name, + $u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name); + } + }else{ + $invoice_preferred = ""; + if( $payment != 'invoice' ){ + $result .= sprintf($row, + $u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name, + $u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name); + } + + } } return $result; } + //generate template based on html file private function template($id, $file) { @@ -865,8 +906,7 @@ ZOT; 'status' =>'success', 'tos' => [], ); - - $price = new NdisPrice();//current year; + $price = $this->get_ndis_price(); $response['tos']= $price->get_tos_array(); wp_send_json($response); } @@ -1244,7 +1284,7 @@ ZOT; $days=[]; $d = new \DateTime($start); for ($i=1; $i<=14; $i++){ - $days["days_$i"] = $d->format("d/F"); + $days["days_$i"] = $d->format("d/M"); $d->modify("+1 day"); } @@ -1369,7 +1409,7 @@ ZOT; 'jobs'=>[], 'err'=>'' ]; - $price = new NdisPrice();//current year; + $price = $this->get_ndis_price(); $summary=[];// by ndis code foreach($rows as $r){ $quantity = $this->get_job_hours($r->start, $r->finish); @@ -1404,7 +1444,7 @@ ZOT; $response['summary'][] = array( 'ndis' => $key, 'tos' => $price->get_tos_full_str($key), - 'Hours'=> $val, + 'Hours'=> sprintf("%0.2f", $val), ); } if (count($summary) > 0){ @@ -1448,9 +1488,9 @@ ZOT; $user = get_user_by('login', $client_login); if ( !$this->is_client($user) ) return NULL; - $payment = get_user_meta($user->ID, "payment", true); - if ($payment != "invoice") - return NULL; +// $payment = get_user_meta($user->ID, "payment", true); +// if ($payment != "invoice") +// return NULL; $sql = "SELECT * from $this->table_name WHERE tos != '00_000_0000_0_0' and start>='$start 00:00:00' and start<='$finish 23:59:59' and client='$client_login' ORDER BY start"; $rows = $this->db->get_results($sql); @@ -1566,7 +1606,7 @@ By Carer : %s', $f = strtotime($finish); $diff = $f- $s; $hours = ($diff * 1.0 / 3600); //can be float; - return $hours; + return sprintf('%0.2f', $hours); } public function feedback_url()