|
|
@@ -37,11 +37,12 @@ class PresenceReport extends Component
|
|
|
public $to;
|
|
|
public $court_id;
|
|
|
public $instructor_id;
|
|
|
+ public $search;
|
|
|
|
|
|
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->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->orderBy('name', 'asc')->get();
|
|
|
$this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->where('type', 'del')->get();
|
|
|
|
|
|
$this->from = "00:00:00";
|
|
|
@@ -66,14 +67,45 @@ class PresenceReport extends Component
|
|
|
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);
|
|
|
+ $presences_annullate = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', 99);
|
|
|
+
|
|
|
+ // filtra per campo court_id
|
|
|
+ if (!is_null($this->court_id) && $this->court_id > 0) {
|
|
|
+ $presences->where('court_id', $this->court_id);
|
|
|
+ $presences_annullate->where('court_id', $this->court_id);
|
|
|
}
|
|
|
- if (!is_null($this->instructor_id)) {
|
|
|
- $presences = $presences->where('instructor_id', $this->instructor_id);
|
|
|
+
|
|
|
+ // filtra per campo istructor_id/user_id
|
|
|
+ if (!is_null($this->instructor_id) && $this->instructor_id > 0) {
|
|
|
+ $presences->where(function ($query) {
|
|
|
+ $query->where('instructor_id', $this->instructor_id)
|
|
|
+ ->orWhere('user_id', $this->instructor_id);
|
|
|
+ });
|
|
|
+ $presences_annullate->where(function ($query) {
|
|
|
+ $query->where('instructor_id', $this->instructor_id)
|
|
|
+ ->orWhere('user_id', $this->instructor_id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // filtra per campo search (nome/cognome)
|
|
|
+ if (!is_null($this->search) && $this->search != "") {
|
|
|
+ $search_value = $this->search;
|
|
|
+ $presences->whereHas('member', function ($q) use ($search_value) {
|
|
|
+ $q->where(function ($qq) use ($search_value) {
|
|
|
+ $qq->whereRaw("CONCAT(TRIM(first_name), ' ', TRIM(last_name)) LIKE ?", ["%{$search_value}%"])
|
|
|
+ ->orWhereRaw("CONCAT(TRIM(last_name), ' ', TRIM(first_name)) LIKE ?", ["%{$search_value}%"]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ $presences_annullate->whereHas('member', function ($q) use ($search_value) {
|
|
|
+ $q->where(function ($qq) use ($search_value) {
|
|
|
+ $qq->whereRaw("CONCAT(TRIM(first_name), ' ', TRIM(last_name)) LIKE ?", ["%{$search_value}%"])
|
|
|
+ ->orWhereRaw("CONCAT(TRIM(last_name), ' ', TRIM(first_name)) LIKE ?", ["%{$search_value}%"]);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
$presences = $presences->pluck('member_id')->toArray();
|
|
|
- $presences_annullate = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', 99)->pluck('member_id')->toArray();
|
|
|
+ $presences_annullate = $presences_annullate->pluck('member_id')->toArray();
|
|
|
|
|
|
$days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
|
|
|
$dow = date('w', strtotime($calendar->from));
|
|
|
@@ -91,8 +123,9 @@ class PresenceReport extends Component
|
|
|
$mids = [];
|
|
|
|
|
|
// Elenco utenti iscritti al corso "padre"
|
|
|
- $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();
|
|
|
+ // $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();
|
|
|
+ $members = \App\Models\MemberCourse::whereRaw("JSON_CONTAINS(`when`, JSON_OBJECT('day', JSON_ARRAY(?), 'from', ?), '$')",[$d, $h])->whereIn('member_id', $presences)->whereIn('course_id', $courses)->get();
|
|
|
foreach ($members as $member) {
|
|
|
|
|
|
$court = '';
|
|
|
@@ -102,7 +135,7 @@ class PresenceReport extends Component
|
|
|
$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 : "";
|
|
|
+ $instructor = $presence->user->name . ($presence->instructor && $presence->instructor !== $presence->user ? ", " . $presence->instructor->name : "");
|
|
|
$motivation = $presence->motivation ? $presence->motivation->name : "";
|
|
|
}
|
|
|
|
|
|
@@ -123,21 +156,52 @@ class PresenceReport extends Component
|
|
|
$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);
|
|
|
+ $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)
|
|
|
- {
|
|
|
+ $presences_recuperi = \App\Models\Presence::where('calendar_id', $calendar->id)->whereNotIn('member_id', $mids);
|
|
|
+ if (!is_null($this->court_id) && $this->court_id > 0) {
|
|
|
+ $presences_recuperi->where('court_id', $this->court_id);
|
|
|
+ }
|
|
|
+ if (!is_null($this->instructor_id) && $this->instructor_id > 0) {
|
|
|
+ $presences_recuperi->where(function ($query) {
|
|
|
+ $query->where('instructor_id', $this->instructor_id)
|
|
|
+ ->orWhere('user_id', $this->instructor_id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!is_null($this->search) && $this->search != "") {
|
|
|
+ $search_value = $this->search;
|
|
|
+ $presences_recuperi->whereHas('member', function ($q) use ($search_value) {
|
|
|
+ $q->where(function ($qq) use ($search_value) {
|
|
|
+ $qq->whereRaw("CONCAT(TRIM(first_name), ' ', TRIM(last_name)) LIKE ?", ["%{$search_value}%"])
|
|
|
+ ->orWhereRaw("CONCAT(TRIM(last_name), ' ', TRIM(first_name)) LIKE ?", ["%{$search_value}%"]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ $presences_recuperi = $presences_recuperi->get();
|
|
|
+ foreach ($presences_recuperi as $p) {
|
|
|
$court = $p->court ? $p->court->name : "";
|
|
|
- $instructor = $p->instructor ? $p->instructor->name : "";
|
|
|
+ $instructor = $p->user->name . ($p->instructor && $p->instructor !== $p->user ? ", " . $p->instructor->name : "");
|
|
|
$motivation = $p->motivation ? $p->motivation->name : "";
|
|
|
$status = "<span class='fw-bold' style='color:gray'>Recupero</span>";
|
|
|
- $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);
|
|
|
- }
|
|
|
+ $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();
|
|
|
@@ -147,9 +211,19 @@ class PresenceReport extends Component
|
|
|
$this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => '<span style="color:#7136f6">Recupero</span>');//\App\Models\Presence::where('member_id', $this->dataId)->get();
|
|
|
$this->recuperi += 1;
|
|
|
}
|
|
|
- */
|
|
|
+ */
|
|
|
|
|
|
//array_push($this->courses, $calendar->course_id);
|
|
|
+
|
|
|
+ // sort records per cognome-nome
|
|
|
+ if (isset($this->records[$calendar->name]) && isset($this->records[$calendar->name][$h])) {
|
|
|
+ usort($this->records[$calendar->name][$h], function($a, $b) {
|
|
|
+ $last_name_compare = strcmp($a['last_name'], $b['last_name']);
|
|
|
+ $first_name_compare = strcmp($a['first_name'], $b['first_name']);
|
|
|
+
|
|
|
+ return $last_name_compare != 0 ? $last_name_compare : $first_name_compare;
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$this->courses = \App\Models\Calendar::orderBy('name')->groupBy('name')->pluck('name')->toArray();
|