PresenceReport.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. class PresenceReport extends Component
  5. {
  6. public $calendar;
  7. public $records;
  8. public $date;
  9. public $member_ids = [];
  10. public $courts = [];
  11. public $instructors = [];
  12. public $motivations = [];
  13. public $court_filter;
  14. public $instructor_filter;
  15. public $motivation_filter;
  16. public $members = [];
  17. public $newMembers = [];
  18. public $ids = [];
  19. public function mount()
  20. {
  21. $this->courts = \App\Models\Court::select('*')->where('enabled', true)->get();
  22. $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->get();
  23. $this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->where('type', 'del')->get();
  24. $this->date = date("Y-m-d");
  25. setlocale(LC_ALL, 'it_IT');
  26. }
  27. public function render()
  28. {
  29. setlocale(LC_ALL, 'it_IT');
  30. $this->records = [];
  31. $from = $this->date . " 00:00:00";
  32. $to = $this->date . " 23:59:59";
  33. $calendars = \App\Models\Calendar::where('from', '>=', $from)->where('to', '<=', $to)->orderBy('from')->get();
  34. foreach($calendars as $calendar)
  35. {
  36. $presences = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', '<>', 99)->pluck('member_id')->toArray();
  37. $presences_annullate = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', 99)->pluck('member_id')->toArray();
  38. $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
  39. $dow = date('w', strtotime($calendar->from));
  40. $d = $days[$dow];
  41. $h = date('H:i', strtotime($calendar->from));
  42. // Elenco corsi per tipologia in base al calendario
  43. $courses = \App\Models\Course::where('name', $calendar->name)->where('date_from', '<=', $calendar->from)->where('date_to', '>=', $calendar->to)->pluck('id')->toArray();
  44. // Elenco utenti iscritti al corso "padre"
  45. $members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->whereIn('course_id', $courses)->get();
  46. foreach($members as $member)
  47. {
  48. $court = '';
  49. $instructor = '';
  50. $motivation = '';
  51. $presence = \App\Models\Presence::where('member_id', $member->member->id)->where('calendar_id', $calendar->id)->first();
  52. if ($presence)
  53. {
  54. $court = $presence->court ? $presence->court->name : "";
  55. $instructor = $presence->instructor ? $presence->instructor->name : "";
  56. $motivation = $presence->motivation ? $presence->motivation->name : "";
  57. }
  58. $status = '';
  59. if (in_array($member->member->id, $presences))
  60. {
  61. $status = "<span style=\"color:#0c6197\">Prezenza ordinaria</span>";
  62. }
  63. else
  64. {
  65. if (in_array($member->member->id, $presences_annullate))
  66. {
  67. $status = "<span style=\"color:gray\">Annullata</span>";
  68. }
  69. else
  70. {
  71. if (date("Ymd") > date("Ymd", strtotime($calendar->from)))
  72. {
  73. $status = "<span style=\"color:red\">Assenza</span>";
  74. }
  75. }
  76. }
  77. if ($calendar->status == 99)
  78. {
  79. $status = "<span style=\"color:gray\">Annullata</span>";
  80. }
  81. $this->records[$calendar->name][$h][] = array("last_name" => $member->member->last_name, "first_name" => $member->member->first_name, "court" => $court, "instructor" => $instructor, "status" => $status, 'motivation' => $motivation);
  82. }
  83. }
  84. return view('livewire.presence_report');
  85. }
  86. public function prev()
  87. {
  88. $this->date = date("Y-m-d", strtotime("-1 day", strtotime($this->date)));
  89. }
  90. public function next()
  91. {
  92. $this->date = date("Y-m-d", strtotime("+1 day", strtotime($this->date)));
  93. }
  94. }