| private $html = ''; | private $html = ''; | ||||
| private $ndis_table; | private $ndis_table; | ||||
| private $tos =[]; | private $tos =[]; | ||||
| private $current_year = 2020; | |||||
| public function __construct(int $year=2019) { | public function __construct(int $year=2019) { | ||||
| global $wpdb; | global $wpdb; | ||||
| if ( $year == "2019"){ | if ( $year == "2019"){ | ||||
| $now = new \DateTime(); | $now = new \DateTime(); | ||||
| $year = (int)($now->format("Y")); | |||||
| //$year = (int)($now->format("Y")); | |||||
| } | } | ||||
| foreach($results as $r){ | foreach($results as $r){ | ||||
| $this->tos[$r->code] = $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="%d" data-ndis="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>', | |||||
| $r->id, | |||||
| $r->code, | $r->code, | ||||
| $r->level, | $r->level, | ||||
| (int) $r->year, | (int) $r->year, | ||||
| return $this->html; | return $this->html; | ||||
| } | } | ||||
| public function get_tos_str($ndis_code) | |||||
| public function get_tos_str($tos_id) | |||||
| { | { | ||||
| //return $this->tos[$ndis_code]->name; | |||||
| //return $this->tos[$tos_id]->name; | |||||
| foreach ($this->tos as $r){ | foreach ($this->tos as $r){ | ||||
| if ($ndis_code == $r->code) | |||||
| if ($tos_id == $r->id) | |||||
| return $r->name; | return $r->name; | ||||
| } | } | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| public function get_tos_full_str($ndis_code) | |||||
| public function get_tos_full_str($tos_id) | |||||
| { | { | ||||
| foreach ($this->tos as $r){ | foreach ($this->tos as $r){ | ||||
| if ($ndis_code == $r->code){ | |||||
| if ($tos_id == $r->id){ | |||||
| return sprintf("%.2f - %s %s %s", | return sprintf("%.2f - %s %s %s", | ||||
| (float) $r->price, | (float) $r->price, | ||||
| $r->name, | $r->name, | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| public function get_tos_price($ndis_code) | |||||
| public function get_tos_price($tos_id) | |||||
| { | { | ||||
| foreach ($this->tos as $r){ | foreach ($this->tos as $r){ | ||||
| if ($ndis_code == $r->code) | |||||
| if ($tos_id == $r->id) | |||||
| return (float) $r->price; | return (float) $r->price; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| public function get_tos_unit($ndis_code) | |||||
| public function get_tos_unit($tos_id) | |||||
| { | { | ||||
| foreach ($this->tos as $r){ | foreach ($this->tos as $r){ | ||||
| if ($ndis_code == $r->code) | |||||
| if ($tos_id == $r->id) | |||||
| return $r->unit; | return $r->unit; | ||||
| } | } | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| public function get_tos_ndis_code($tos_id) | |||||
| { | |||||
| foreach ($this->tos as $r){ | |||||
| if ($tos_id == $r->id) | |||||
| return $r->code; | |||||
| } | |||||
| return ""; | |||||
| } | |||||
| public function get_tos_array() | public function get_tos_array() | ||||
| { | { | ||||
| foreach ($this->tos as $r){ | foreach ($this->tos as $r){ | ||||
| $r->tos_full_str = sprintf("%.2f - %s %s %s", | |||||
| $r->tos_full_str = sprintf("%.2f - %d - %s %s %s", | |||||
| (float) $r->price, | (float) $r->price, | ||||
| $r->year, | |||||
| $r->name, | $r->name, | ||||
| $this->get_level((int) $r->level), | $this->get_level((int) $r->level), | ||||
| $r->ot); | $r->ot); | ||||
| } | } | ||||
| return $this->tos; | return $this->tos; | ||||
| } | } | ||||
| } | |||||
| public function get_id_by_tos($ndis_code , int $year=2019) | |||||
| { | |||||
| foreach ($this->tos as $r){ | |||||
| if ($ndis_code == $r->code && $year == $r->year) | |||||
| return $r->id; | |||||
| } | |||||
| return 0; //0 = not found | |||||
| } | |||||
| } |
| } | } | ||||
| } | } | ||||
| public function dev_change_ndis_price ($args = array(), $assoc_args = array()) | |||||
| { | |||||
| echo "list ndis prices\n"; | |||||
| $nd = new NdisPrice(); | |||||
| echo "get tos array\n"; | |||||
| $tosarray = $nd->get_tos_array(); | |||||
| $map = array(); | |||||
| foreach($tosarray as $item){ | |||||
| $map[$item->code] = $item->id; | |||||
| echo "UPDATE wp1m_acare_ts SET tos_id=$item->id WHERE tos='$item->code' and id > 0; \n"; | |||||
| } | |||||
| //print_r($map); | |||||
| } | |||||
| private function send_email_with_job_link($staff, $start, $finish) | private function send_email_with_job_link($staff, $start, $finish) | ||||
| { | { | ||||
| $message = file_get_contents(plugin_dir_path(__FILE__) . "/html/email_job.html"); | $message = file_get_contents(plugin_dir_path(__FILE__) . "/html/email_job.html"); | ||||
| { | { | ||||
| $response['nojob'] = true; | $response['nojob'] = true; | ||||
| } | } | ||||
| $response['overall_total'] = 0; | |||||
| foreach ($summary as $key => $val) | foreach ($summary as $key => $val) | ||||
| { | { | ||||
| $unitprice = $price->get_tos_price($key); | |||||
| $tos_total = $val * $price->get_tos_price($key); | |||||
| $response['overall_total'] += $tos_total; | |||||
| $response['summary'][] = array( | $response['summary'][] = array( | ||||
| 'ndis' => $key, | 'ndis' => $key, | ||||
| 'tos' => $price->get_tos_full_str($key), | 'tos' => $price->get_tos_full_str($key), | ||||
| 'unitprice'=> $unitprice, | |||||
| 'Hours'=> sprintf("%0.2f", $val), | 'Hours'=> sprintf("%0.2f", $val), | ||||
| 'tos_total'=> sprintf("%0.2f", $tos_total), | |||||
| ); | ); | ||||
| } | } | ||||
| if (count($summary) > 0){ | if (count($summary) > 0){ | ||||
| $response['has_summary'] = true; | $response['has_summary'] = true; | ||||
| $response['overall_total'] = sprintf("%0.2f", $response['overall_total'] ); | |||||
| } | } | ||||
| ->setDate($now) | ->setDate($now) | ||||
| ->setDueDate($due); | ->setDueDate($due); | ||||
| $to_save=[];//all invoices to save; | $to_save=[];//all invoices to save; | ||||
| $price = new NdisPrice($now->format("Y"));//current year; | |||||
| $price = new NdisPrice(2019);//always 2019 until its being changed; | |||||
| 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); | ||||
| \WP_CLI::add_command( 'email_jobs', array($bb, 'email_jobs')); | \WP_CLI::add_command( 'email_jobs', array($bb, 'email_jobs')); | ||||
| \WP_CLI::add_command( 'feedback_url', array($bb, 'feedback_url')); | \WP_CLI::add_command( 'feedback_url', array($bb, 'feedback_url')); | ||||
| \WP_CLI::add_command( 'produce_invoice', array($bb, 'produce_invoice')); | \WP_CLI::add_command( 'produce_invoice', array($bb, 'produce_invoice')); | ||||
| \WP_CLI::add_command( 'dev_change_ndis_price', array($bb, 'dev_change_ndis_price')); | |||||
| } | } | ||||
| //$bb->class_loader(); | //$bb->class_loader(); |