timesheet source code
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

139 líneas
3.6KB

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