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->from = "00:00:00"; $this->to = "23:59:59"; $this->date = date("Y-m-d"); setlocale(LC_ALL, 'it_IT'); } public function render() { setlocale(LC_ALL, 'it_IT'); $this->records = []; $this->courses = []; $from = $this->date . " " . $this->from; $to = $this->date . " " . $this->to; $calendars = \App\Models\Calendar::where('from', '>=', $from)->where('from', '<=', $to)->orderBy('from')->get(); foreach ($calendars as $calendar) { $presences = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', '<>', 99); if (!is_null($this->court_id)) { $presences = $presences->where('court_id', $this->court_id); } if (!is_null($this->instructor_id)) { $presences = $presences->where('instructor_id', $this->instructor_id); } $presences = $presences->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); if (!is_null($this->course_name)) { $courses = $courses->where('name', $this->course_name); } $courses = $courses->pluck('id')->toArray(); $mids = []; $months = date("n", strtotime($calendar->from)); // Elenco utenti iscritti al corso "padre" $members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->where('months', 'like', '%"m":' . $months . ',%')->whereIn('course_id', $courses)->get(); //$members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->whereIn('member_id', $presences)->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 = "Presente"; } else { if (in_array($member->member->id, $presences_annullate)) { $status = "Annullata"; } else { if (date("Ymd") > date("Ymd", strtotime($calendar->from))) { $status = "Assente"; } } } if ($calendar->status == 99) { $status = "Annullata"; } $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); $mids[] = $member->member->id; } $presences_recuperi = \App\Models\Presence::where('calendar_id', $calendar->id)->whereNotIn('member_id', $mids)->get(); foreach($presences_recuperi as $p) { $court = $p->court ? $p->court->name : ""; $instructor = $p->instructor ? $p->instructor->name : ""; $motivation = $p->motivation ? $p->motivation->name : ""; $status = "Recupero"; $this->records[$calendar->name][$h][] = array("last_name" => $p->member->last_name, "first_name" => $p->member->first_name, "court" => $court, "instructor" => $instructor, "status" => $status, 'motivation' => $motivation); } /* $calendar_recuperi = \App\Models\Calendar::where('manual', 1)->where('id', $calendar->id)->pluck('id')->toArray(); $presences_recuperi = \App\Models\Presence::whereIn('calendar_id', $calendar_recuperi)->where('member_id', $this->dataId)->get(); foreach($presences_recuperi as $p) { $this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => 'Recupero');//\App\Models\Presence::where('member_id', $this->dataId)->get(); $this->recuperi += 1; } */ //array_push($this->courses, $calendar->course_id); } $this->courses = \App\Models\Calendar::orderBy('name')->groupBy('name')->pluck('name')->toArray(); /*$this->courses = array_unique($this->courses); $this->courses = array_map(function ($course_id) { try { return \App\Models\Course::findOrFail($course_id); } catch (\Throwable $e) { return null; } }, $this->courses); $this->courses = array_filter($this->courses);*/ 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))); } public function today() { $this->date = date("Y-m-d"); } }