|
|
|
@@ -6,12 +6,13 @@ class NdisPrice{ |
|
|
|
private $html = ''; |
|
|
|
private $ndis_table; |
|
|
|
private $tos =[]; |
|
|
|
private $current_year = 2020; |
|
|
|
public function __construct(int $year=2019) { |
|
|
|
global $wpdb; |
|
|
|
|
|
|
|
if ( $year == "2019"){ |
|
|
|
$now = new \DateTime(); |
|
|
|
$year = (int)($now->format("Y")); |
|
|
|
//$year = (int)($now->format("Y")); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@@ -24,7 +25,8 @@ class NdisPrice{ |
|
|
|
foreach($results as $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->level, |
|
|
|
(int) $r->year, |
|
|
|
@@ -61,20 +63,20 @@ class NdisPrice{ |
|
|
|
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){ |
|
|
|
if ($ndis_code == $r->code) |
|
|
|
if ($tos_id == $r->id) |
|
|
|
return $r->name; |
|
|
|
} |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
public function get_tos_full_str($ndis_code) |
|
|
|
public function get_tos_full_str($tos_id) |
|
|
|
{ |
|
|
|
foreach ($this->tos as $r){ |
|
|
|
if ($ndis_code == $r->code){ |
|
|
|
if ($tos_id == $r->id){ |
|
|
|
return sprintf("%.2f - %s %s %s", |
|
|
|
(float) $r->price, |
|
|
|
$r->name, |
|
|
|
@@ -85,33 +87,52 @@ class NdisPrice{ |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
public function get_tos_price($ndis_code) |
|
|
|
public function get_tos_price($tos_id) |
|
|
|
{ |
|
|
|
foreach ($this->tos as $r){ |
|
|
|
if ($ndis_code == $r->code) |
|
|
|
if ($tos_id == $r->id) |
|
|
|
return (float) $r->price; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
public function get_tos_unit($ndis_code) |
|
|
|
public function get_tos_unit($tos_id) |
|
|
|
{ |
|
|
|
foreach ($this->tos as $r){ |
|
|
|
if ($ndis_code == $r->code) |
|
|
|
if ($tos_id == $r->id) |
|
|
|
return $r->unit; |
|
|
|
} |
|
|
|
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() |
|
|
|
{ |
|
|
|
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, |
|
|
|
$r->year, |
|
|
|
$r->name, |
|
|
|
$this->get_level((int) $r->level), |
|
|
|
$r->ot); |
|
|
|
} |
|
|
|
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 |
|
|
|
} |
|
|
|
} |