|
@@ -29,6 +29,19 @@ class Presence extends Component
|
|
|
public $motivations = [];
|
|
public $motivations = [];
|
|
|
public $motivations_add = [];
|
|
public $motivations_add = [];
|
|
|
|
|
|
|
|
|
|
+ public $insertUser = 'exist';
|
|
|
|
|
+ public $course_limit;
|
|
|
|
|
+ public $motivation_course_id = null;
|
|
|
|
|
+ public $motivation_course_name = 0;
|
|
|
|
|
+ public $motivation_course_level = 0;
|
|
|
|
|
+ public $motivation_course_type = 0;
|
|
|
|
|
+ public $motivation_course_frequency = 0;
|
|
|
|
|
+
|
|
|
|
|
+ public $course_names = [];
|
|
|
|
|
+ public $course_levels = [];
|
|
|
|
|
+ public $course_types = [];
|
|
|
|
|
+ public $course_frequencies = [];
|
|
|
|
|
+
|
|
|
public $members = [];
|
|
public $members = [];
|
|
|
|
|
|
|
|
public $newMembers = [];
|
|
public $newMembers = [];
|
|
@@ -62,6 +75,86 @@ class Presence extends Component
|
|
|
$this->save_court_id = 0;
|
|
$this->save_court_id = 0;
|
|
|
$this->save_instructor_id = 0;
|
|
$this->save_instructor_id = 0;
|
|
|
$this->save_notes = '';
|
|
$this->save_notes = '';
|
|
|
|
|
+
|
|
|
|
|
+ $this->insertUser = 'exist';
|
|
|
|
|
+ $this->course_limit = now()->endOfDay();
|
|
|
|
|
+
|
|
|
|
|
+ $this->course_names = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->orderBy('name')->groupBy('name')->pluck('name');
|
|
|
|
|
+ $this->course_levels = [];
|
|
|
|
|
+ $this->course_types = [];
|
|
|
|
|
+ $this->course_frequencies = [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updatedMotivationCourseName() {
|
|
|
|
|
+ if ($this->motivation_course_name > 0 && $this->motivation_course_name != '') {
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+ $this->motivation_course_level = 0;
|
|
|
|
|
+ $this->motivation_course_type = 0;
|
|
|
|
|
+ $this->motivation_course_frequency = 0;
|
|
|
|
|
+
|
|
|
|
|
+ $levels_ids = [];
|
|
|
|
|
+ $levels = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->get();
|
|
|
|
|
+ foreach ($levels as $l) {
|
|
|
|
|
+ $levels_ids[] = $l->course_level_id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->course_levels = \App\Models\CourseLevel::where('enabled', true)->whereIn('id', $levels_ids)->orderBy('name')->get();
|
|
|
|
|
+ $this->course_types = [];
|
|
|
|
|
+ $this->course_frequencies = [];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->course_levels = [];
|
|
|
|
|
+ $this->course_types = [];
|
|
|
|
|
+ $this->course_frequencies = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updatedMotivationCourseLevel() {
|
|
|
|
|
+ if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '') {
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+ $this->motivation_course_type = 0;
|
|
|
|
|
+ $this->motivation_course_frequency = 0;
|
|
|
|
|
+
|
|
|
|
|
+ $type_ids = [];
|
|
|
|
|
+ $types = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->where('course_level_id', $this->motivation_course_level)->get();
|
|
|
|
|
+ foreach ($types as $t) {
|
|
|
|
|
+ $type_ids[] = $t->course_type_id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->course_types = \App\Models\CourseType::where('enabled', true)->whereIn('id', $type_ids)->orderBy('name')->get();
|
|
|
|
|
+ $this->course_frequencies = [];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->course_types = [];
|
|
|
|
|
+ $this->course_frequencies = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updatedMotivationCourseType() {
|
|
|
|
|
+ if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '' && $this->motivation_course_type > 0 && $this->motivation_course_type != '') {
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+ $this->motivation_course_frequency = 0;
|
|
|
|
|
+
|
|
|
|
|
+ $frequency_ids = [];
|
|
|
|
|
+ $frequencies = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->where('course_level_id', $this->motivation_course_level)->where('course_type_id', $this->motivation_course_type)->get();
|
|
|
|
|
+ foreach ($frequencies as $f) {
|
|
|
|
|
+ $frequency_ids[] = $f->course_frequency_id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->course_frequencies = \App\Models\CourseFrequency::where('enabled', true)->whereIn('id', $frequency_ids)->orderBy('name')->get();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->course_frequencies = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updatedMotivationCourseFrequency() {
|
|
|
|
|
+ if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '' && $this->motivation_course_type > 0 && $this->motivation_course_type != '' && $this->motivation_course_frequency > 0 && $this->motivation_course_frequency != '') {
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+
|
|
|
|
|
+ $course = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->where('course_level_id', $this->motivation_course_level)->where('course_type_id', $this->motivation_course_type)->where('course_frequency_id', $this->motivation_course_frequency)->first();
|
|
|
|
|
+
|
|
|
|
|
+ $this->motivation_course_id = $course->id;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function updatedNewMemberMotivationId()
|
|
public function updatedNewMemberMotivationId()
|
|
@@ -302,8 +395,9 @@ class Presence extends Component
|
|
|
// Mappa degli ultimi motivation_id per ogni member_id dell'utente e calendario correnti
|
|
// Mappa degli ultimi motivation_id per ogni member_id dell'utente e calendario correnti
|
|
|
$userId = \Auth::user()->id;
|
|
$userId = \Auth::user()->id;
|
|
|
$calendarId = $this->calendar->id;
|
|
$calendarId = $this->calendar->id;
|
|
|
- $lastEditData = \App\Models\Presence::query()
|
|
|
|
|
- ->select('member_id', 'motivation_id')
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $motivation_query = \App\Models\Presence::query()
|
|
|
|
|
+ ->select('member_id', 'motivation_id', 'motivation_course_id')
|
|
|
->where('calendar_id', $calendarId)
|
|
->where('calendar_id', $calendarId)
|
|
|
->where('user_id', $userId)
|
|
->where('user_id', $userId)
|
|
|
->where('status', '<>', 99)
|
|
->where('status', '<>', 99)
|
|
@@ -316,9 +410,10 @@ class Presence extends Component
|
|
|
->groupBy('member_id');
|
|
->groupBy('member_id');
|
|
|
})
|
|
})
|
|
|
->get()
|
|
->get()
|
|
|
- ->keyBy('member_id') // -> [member_id => (obj con motivation_id)]
|
|
|
|
|
- ->map(fn($row) => $row->motivation_id)
|
|
|
|
|
- ->toArray();
|
|
|
|
|
|
|
+ ->keyBy('member_id');
|
|
|
|
|
+
|
|
|
|
|
+ $motivationMap = $motivation_query->map(fn($row) => $row->motivation_id)->toArray();
|
|
|
|
|
+ $motivationCourseMap = $motivation_query->map(fn($row) => $row->motivation_course_id)->toArray();
|
|
|
|
|
|
|
|
// Elimino tutti i dati correnti che devono essere sostituiti
|
|
// Elimino tutti i dati correnti che devono essere sostituiti
|
|
|
\App\Models\Presence::query()
|
|
\App\Models\Presence::query()
|
|
@@ -334,7 +429,8 @@ class Presence extends Component
|
|
|
$p->calendar_id = $calendarId;
|
|
$p->calendar_id = $calendarId;
|
|
|
|
|
|
|
|
// Se per quel membro esisteva un motivation_id, lo riuso, altrimenti lo lascio null
|
|
// Se per quel membro esisteva un motivation_id, lo riuso, altrimenti lo lascio null
|
|
|
- $p->motivation_id = $lastEditData[$id] ?? null;
|
|
|
|
|
|
|
+ $p->motivation_id = $motivationMap[$id] ?? null;
|
|
|
|
|
+ $p->motivation_course_id = $motivationCourseMap[$id] ?? null;
|
|
|
$p->user_id = $userId;
|
|
$p->user_id = $userId;
|
|
|
$p->status = 0;
|
|
$p->status = 0;
|
|
|
|
|
|
|
@@ -429,6 +525,7 @@ class Presence extends Component
|
|
|
$p->member_id = $member->id;
|
|
$p->member_id = $member->id;
|
|
|
$p->calendar_id = $this->calendar->id;
|
|
$p->calendar_id = $this->calendar->id;
|
|
|
$p->motivation_id = $this->newMemberMotivationId;
|
|
$p->motivation_id = $this->newMemberMotivationId;
|
|
|
|
|
+ $p->motivation_course_id = $this->motivation_course_id;
|
|
|
$p->user_id = \Auth::user()->id;
|
|
$p->user_id = \Auth::user()->id;
|
|
|
$p->status = 0;
|
|
$p->status = 0;
|
|
|
$p->court_id = null;
|
|
$p->court_id = null;
|
|
@@ -461,6 +558,7 @@ class Presence extends Component
|
|
|
$p->member_id = $m;
|
|
$p->member_id = $m;
|
|
|
$p->calendar_id = $this->calendar->id;
|
|
$p->calendar_id = $this->calendar->id;
|
|
|
$p->motivation_id = $this->newMemberMotivationId;
|
|
$p->motivation_id = $this->newMemberMotivationId;
|
|
|
|
|
+ $p->motivation_course_id = $this->motivation_course_id;
|
|
|
$p->user_id = \Auth::user()->id;
|
|
$p->user_id = \Auth::user()->id;
|
|
|
$p->status = 0;
|
|
$p->status = 0;
|
|
|
$p->court_id = null;
|
|
$p->court_id = null;
|
|
@@ -484,6 +582,24 @@ class Presence extends Component
|
|
|
$this->emit('reload');
|
|
$this->emit('reload');
|
|
|
$this->emit('saved');
|
|
$this->emit('saved');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ $this->resetCreationFields();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function resetCreationFields() {
|
|
|
|
|
+ $this->insertUser = 'new';
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+ $this->motivation_course_name = null;
|
|
|
|
|
+ $this->motivation_course_level = null;
|
|
|
|
|
+ $this->motivation_course_type = null;
|
|
|
|
|
+ $this->motivation_course_frequency = null;
|
|
|
|
|
+ $this->newMemberMotivationId = null;
|
|
|
|
|
+ $this->newMemberFirstName = null;
|
|
|
|
|
+ $this->newMemberLastName = null;
|
|
|
|
|
+ $this->newMemberEmail = null;
|
|
|
|
|
+ $this->newMemberFiscalCode = null;
|
|
|
|
|
+
|
|
|
|
|
+ $this->emit('resetCreationForm');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function createInstructor()
|
|
public function createInstructor()
|