|
|
@@ -0,0 +1,134 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Livewire;
|
|
|
+
|
|
|
+use Livewire\Component;
|
|
|
+
|
|
|
+class PresenceReport extends Component
|
|
|
+{
|
|
|
+
|
|
|
+ public $calendar;
|
|
|
+
|
|
|
+ public $records;
|
|
|
+
|
|
|
+ public $date;
|
|
|
+
|
|
|
+ public $member_ids = [];
|
|
|
+
|
|
|
+
|
|
|
+ public $courts = [];
|
|
|
+ public $instructors = [];
|
|
|
+ public $motivations = [];
|
|
|
+
|
|
|
+ public $court_filter;
|
|
|
+ public $instructor_filter;
|
|
|
+ public $motivation_filter;
|
|
|
+
|
|
|
+
|
|
|
+ public $members = [];
|
|
|
+
|
|
|
+ public $newMembers = [];
|
|
|
+
|
|
|
+ public $ids = [];
|
|
|
+
|
|
|
+ public function mount()
|
|
|
+ {
|
|
|
+
|
|
|
+ $this->courts = \App\Models\Court::select('*')->where('enabled', true)->get();
|
|
|
+ $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->get();
|
|
|
+ $this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->where('type', 'del')->get();
|
|
|
+
|
|
|
+ $this->date = date("Y-m-d");
|
|
|
+ setlocale(LC_ALL, 'it_IT');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function render()
|
|
|
+ {
|
|
|
+
|
|
|
+ setlocale(LC_ALL, 'it_IT');
|
|
|
+
|
|
|
+ $this->records = [];
|
|
|
+
|
|
|
+ $from = $this->date . " 00:00:00";
|
|
|
+ $to = $this->date . " 23:59:59";
|
|
|
+
|
|
|
+ $calendars = \App\Models\Calendar::where('from', '>=', $from)->where('to', '<=', $to)->orderBy('from')->get();
|
|
|
+
|
|
|
+ foreach($calendars as $calendar)
|
|
|
+ {
|
|
|
+
|
|
|
+ $presences = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', '<>', 99)->pluck('member_id')->toArray();
|
|
|
+ $presences_annullate = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', 99)->pluck('member_id')->toArray();
|
|
|
+
|
|
|
+ $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
|
|
|
+ $dow = date('w', strtotime($calendar->from));
|
|
|
+ $d = $days[$dow];
|
|
|
+
|
|
|
+ $h = date('H:i', strtotime($calendar->from));
|
|
|
+
|
|
|
+ // Elenco corsi per tipologia in base al calendario
|
|
|
+ $courses = \App\Models\Course::where('name', $calendar->name)->where('date_from', '<=', $calendar->from)->where('date_to', '>=', $calendar->to)->pluck('id')->toArray();
|
|
|
+
|
|
|
+ // Elenco utenti iscritti al corso "padre"
|
|
|
+ $members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->whereIn('course_id', $courses)->get();
|
|
|
+ foreach($members as $member)
|
|
|
+ {
|
|
|
+
|
|
|
+ $court = '';
|
|
|
+ $instructor = '';
|
|
|
+ $motivation = '';
|
|
|
+
|
|
|
+ $presence = \App\Models\Presence::where('member_id', $member->member->id)->where('calendar_id', $calendar->id)->first();
|
|
|
+ if ($presence)
|
|
|
+ {
|
|
|
+ $court = $presence->court ? $presence->court->name : "";
|
|
|
+ $instructor = $presence->instructor ? $presence->instructor->name : "";
|
|
|
+ $motivation = $presence->motivation ? $presence->motivation->name : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = '';
|
|
|
+ if (in_array($member->member->id, $presences))
|
|
|
+ {
|
|
|
+ $status = "<span style=\"color:#0c6197\">Prezenza ordinaria</span>";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (in_array($member->member->id, $presences_annullate))
|
|
|
+ {
|
|
|
+ $status = "<span style=\"color:gray\">Annullata</span>";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (date("Ymd") > date("Ymd", strtotime($calendar->from)))
|
|
|
+ {
|
|
|
+ $status = "<span style=\"color:red\">Assenza</span>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($calendar->status == 99)
|
|
|
+ {
|
|
|
+ $status = "<span style=\"color:gray\">Annullata</span>";
|
|
|
+ }
|
|
|
+
|
|
|
+ $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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return view('livewire.presence_report');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function prev()
|
|
|
+ {
|
|
|
+ $this->date = date("Y-m-d", strtotime("-1 day", strtotime($this->date)));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function next()
|
|
|
+ {
|
|
|
+ $this->date = date("Y-m-d", strtotime("+1 day", strtotime($this->date)));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|