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.

96 lignes
2.5KB

  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} WHERE year=$year"; //for this year
  11. $results = $wpdb->get_results($sql);
  12. $this->tos =[];
  13. $html = ' <select>';
  14. foreach($results as $r){
  15. $this->tos[] = $r;
  16. $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>',
  17. $r->code,
  18. $r->level,
  19. (int) $r->year,
  20. $r->unit,
  21. (float) $r->price,
  22. $r->ot,
  23. (float) $r->price,
  24. $r->name,
  25. $this->get_level((int) $r->level),
  26. $r->ot
  27. );//end of sprintf
  28. }
  29. $html .=' </select>';
  30. $this->html = $html;
  31. }
  32. private function get_level($level_number){
  33. $levelStr = array(
  34. 0 => '(standard)',
  35. -1 => '', //no level number needed
  36. 1 => '(Level 1)',
  37. 2 => '(Level 2)',
  38. 3 => '(Level 3)'
  39. );
  40. if ( array_key_exists($level_number, $levelStr) )
  41. return $levelStr[$level_number];
  42. else
  43. return '';
  44. }
  45. public function get_html()
  46. {
  47. return $this->html;
  48. }
  49. public function get_tos_str($ndis_code)
  50. {
  51. foreach ($this->tos as $r){
  52. if ($ndis_code == $r->code)
  53. return $r->name;
  54. }
  55. return "";
  56. }
  57. public function get_tos_full_str($ndis_code)
  58. {
  59. foreach ($this->tos as $r){
  60. if ($ndis_code == $r->code){
  61. return sprintf("%.2f - %s %s %s",
  62. (float) $r->price,
  63. $r->name,
  64. $this->get_level((int) $r->level),
  65. $r->ot);
  66. }
  67. }
  68. return "";
  69. }
  70. public function get_tos_price($ndis_code)
  71. {
  72. foreach ($this->tos as $r){
  73. if ($ndis_code == $r->code)
  74. return (float) $r->price;
  75. }
  76. return 0;
  77. }
  78. public function get_tos_unit($ndis_code)
  79. {
  80. foreach ($this->tos as $r){
  81. if ($ndis_code == $r->code)
  82. return $r->unit;
  83. }
  84. return "";
  85. }
  86. }