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.

133 líneas
3.4KB

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