timesheet source code
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

117 lignes
3.0KB

  1. <?php
  2. namespace Biukop;
  3. class NdisPrice{
  4. private $html = '';
  5. private $ndis_table;
  6. private $tos =[];
  7. public function __construct(int $year=2019) {
  8. global $wpdb;
  9. if ( $year == "2019"){
  10. $now = new \DateTime();
  11. $year = (int)($now->format("Y"));
  12. }
  13. $this->ndis_table = $wpdb->prefix . 'acare_ndis_price';
  14. $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year
  15. $results = $wpdb->get_results($sql);
  16. $this->tos =[];
  17. $html = ' <select>';
  18. foreach($results as $r){
  19. $this->tos[$r->code] = $r;
  20. $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>',
  21. $r->code,
  22. $r->level,
  23. (int) $r->year,
  24. $r->unit,
  25. (float) $r->price,
  26. $r->ot,
  27. (float) $r->price,
  28. $r->name,
  29. $this->get_level((int) $r->level),
  30. $r->ot
  31. );//end of sprintf
  32. }
  33. $html .=' </select>';
  34. $this->html = $html;
  35. }
  36. private function get_level($level_number){
  37. $levelStr = array(
  38. 0 => '(standard)',
  39. -1 => '', //no level number needed
  40. 1 => '(Level 1)',
  41. 2 => '(Level 2)',
  42. 3 => '(Level 3)'
  43. );
  44. if ( array_key_exists($level_number, $levelStr) )
  45. return $levelStr[$level_number];
  46. else
  47. return '';
  48. }
  49. public function get_html()
  50. {
  51. return $this->html;
  52. }
  53. public function get_tos_str($ndis_code)
  54. {
  55. //return $this->tos[$ndis_code]->name;
  56. foreach ($this->tos as $r){
  57. if ($ndis_code == $r->code)
  58. return $r->name;
  59. }
  60. return "";
  61. }
  62. public function get_tos_full_str($ndis_code)
  63. {
  64. foreach ($this->tos as $r){
  65. if ($ndis_code == $r->code){
  66. return sprintf("%.2f - %s %s %s",
  67. (float) $r->price,
  68. $r->name,
  69. $this->get_level((int) $r->level),
  70. $r->ot);
  71. }
  72. }
  73. return "";
  74. }
  75. public function get_tos_price($ndis_code)
  76. {
  77. foreach ($this->tos as $r){
  78. if ($ndis_code == $r->code)
  79. return (float) $r->price;
  80. }
  81. return 0;
  82. }
  83. public function get_tos_unit($ndis_code)
  84. {
  85. foreach ($this->tos as $r){
  86. if ($ndis_code == $r->code)
  87. return $r->unit;
  88. }
  89. return "";
  90. }
  91. public function get_tos_array()
  92. {
  93. foreach ($this->tos as $r){
  94. $r->tos_full_str = sprintf("%.2f - %s %s %s",
  95. (float) $r->price,
  96. $r->name,
  97. $this->get_level((int) $r->level),
  98. $r->ot);
  99. }
  100. return $this->tos;
  101. }
  102. }