|
|
@@ -15,7 +15,8 @@ class PresenceReport extends Component
|
|
|
|
|
|
public $member_ids = [];
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ public $courses = [];
|
|
|
public $courts = [];
|
|
|
public $instructors = [];
|
|
|
public $motivations = [];
|
|
|
@@ -23,7 +24,7 @@ class PresenceReport extends Component
|
|
|
public $court_filter;
|
|
|
public $instructor_filter;
|
|
|
public $motivation_filter;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
public $members = [];
|
|
|
|
|
|
@@ -31,34 +32,47 @@ class PresenceReport extends Component
|
|
|
|
|
|
public $ids = [];
|
|
|
|
|
|
+ public $course_id;
|
|
|
+ public $from;
|
|
|
+ public $to;
|
|
|
+ public $court_id;
|
|
|
+ public $instructor_id;
|
|
|
+
|
|
|
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->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 . " 00:00:00";
|
|
|
- $to = $this->date . " 23:59:59";
|
|
|
+ $from = $this->date . " " . $this->from;
|
|
|
+ $to = $this->date . " " . $this->to;
|
|
|
|
|
|
- $calendars = \App\Models\Calendar::where('from', '>=', $from)->where('to', '<=', $to)->orderBy('from')->get();
|
|
|
+ $calendars = \App\Models\Calendar::where('from', '>=', $from)->where('from', '<=', $to)->orderBy('from')->get();
|
|
|
|
|
|
- foreach($calendars as $calendar)
|
|
|
- {
|
|
|
+ foreach ($calendars as $calendar) {
|
|
|
|
|
|
- $presences = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', '<>', 99)->pluck('member_id')->toArray();
|
|
|
+ $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'];
|
|
|
@@ -68,56 +82,61 @@ class PresenceReport extends Component
|
|
|
$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();
|
|
|
+ $courses = \App\Models\Course::where('name', $calendar->name)->where('date_from', '<=', $calendar->from)->where('date_to', '>=', $calendar->to);
|
|
|
+ if (!is_null($this->course_id)) {
|
|
|
+ $courses = $courses->where('id', $this->course_id);
|
|
|
+ }
|
|
|
+ $courses = $courses->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)
|
|
|
- {
|
|
|
+ // $members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->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)
|
|
|
- {
|
|
|
+ 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 (in_array($member->member->id, $presences)) {
|
|
|
+ $status = "<span class='fw-bold' style='color:#0c6197'>Presente</span>";
|
|
|
+ } else {
|
|
|
+ if (in_array($member->member->id, $presences_annullate)) {
|
|
|
+ $status = "<span class='fw-bold' style='color:gray'>Annullata</span>";
|
|
|
+ } else {
|
|
|
+ if (date("Ymd") > date("Ymd", strtotime($calendar->from))) {
|
|
|
+ $status = "<span class='fw-bold' style='color:red'>Assente</span>";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($calendar->status == 99)
|
|
|
- {
|
|
|
- $status = "<span style=\"color:gray\">Annullata</span>";
|
|
|
+ if ($calendar->status == 99) {
|
|
|
+ $status = "<span class='fw-bold' 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);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ array_push($this->courses, $calendar->course_id);
|
|
|
}
|
|
|
|
|
|
+ $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');
|
|
|
}
|
|
|
|
|
|
@@ -131,4 +150,8 @@ class PresenceReport extends Component
|
|
|
$this->date = date("Y-m-d", strtotime("+1 day", strtotime($this->date)));
|
|
|
}
|
|
|
|
|
|
+ public function today()
|
|
|
+ {
|
|
|
+ $this->date = date("Y-m-d");
|
|
|
+ }
|
|
|
}
|