|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
use Livewire\Component;
|
|
|
|
|
|
class Presence extends Component
|
|
|
@@ -44,6 +45,9 @@ class Presence extends Component
|
|
|
|
|
|
public $members = [];
|
|
|
|
|
|
+ public $add_member_id = 0;
|
|
|
+ public $add_member_courses = [];
|
|
|
+
|
|
|
public $newMembers = [];
|
|
|
|
|
|
public $ids = [];
|
|
|
@@ -59,11 +63,11 @@ class Presence extends Component
|
|
|
$this->motivation_manual_id = $this->calendar->motivation_manual_id;
|
|
|
$this->manual = $this->calendar->manual;
|
|
|
$this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_archived', false)
|
|
|
->orWhereNull('is_archived');
|
|
|
})
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_deleted', false)
|
|
|
->orWhereNull('is_deleted');
|
|
|
})->orderBy('last_name')->orderBy('first_name')->get();
|
|
|
@@ -79,13 +83,55 @@ class Presence extends Component
|
|
|
$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_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_names = [];
|
|
|
$this->course_levels = [];
|
|
|
$this->course_types = [];
|
|
|
$this->course_frequencies = [];
|
|
|
}
|
|
|
|
|
|
- function updatedMotivationCourseName() {
|
|
|
+ public function updatedAddMemberId()
|
|
|
+ {
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
+ $this->add_member_courses = \App\Models\MemberCourse::where('member_id', $this->add_member_id)->groupBy('course_id')->pluck('course_id');
|
|
|
+ $this->course_names = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->whereIn('id', $this->add_member_courses)->orderBy('name')->groupBy('name')->pluck('name');
|
|
|
+ $this->course_levels = [];
|
|
|
+ $this->course_types = [];
|
|
|
+ $this->course_frequencies = [];
|
|
|
+
|
|
|
+ $this->motivation_course_id = null;
|
|
|
+ $this->motivation_course_name = 0;
|
|
|
+ $this->motivation_course_level = 0;
|
|
|
+ $this->motivation_course_type = 0;
|
|
|
+ $this->motivation_course_frequency = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updatedInsertUser()
|
|
|
+ {
|
|
|
+ $this->add_member_id = 0;
|
|
|
+
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
+ $this->course_names = [];
|
|
|
+ } else {
|
|
|
+ $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 = [];
|
|
|
+
|
|
|
+ $this->motivation_course_id = null;
|
|
|
+ $this->motivation_course_name = 0;
|
|
|
+ $this->motivation_course_level = 0;
|
|
|
+ $this->motivation_course_type = 0;
|
|
|
+ $this->motivation_course_frequency = 0;
|
|
|
+
|
|
|
+ $this->emit('reload');
|
|
|
+ }
|
|
|
+
|
|
|
+ function updatedMotivationCourseName()
|
|
|
+ {
|
|
|
if ($this->motivation_course_name > 0 && $this->motivation_course_name != '') {
|
|
|
$this->motivation_course_id = null;
|
|
|
$this->motivation_course_level = 0;
|
|
|
@@ -93,7 +139,12 @@ class Presence extends Component
|
|
|
$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();
|
|
|
+ $levels_query = \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);
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
+ $levels_query->whereIn('id', $this->add_member_courses);
|
|
|
+ }
|
|
|
+ $levels = $levels_query->get();
|
|
|
+
|
|
|
foreach ($levels as $l) {
|
|
|
$levels_ids[] = $l->course_level_id;
|
|
|
}
|
|
|
@@ -108,14 +159,19 @@ class Presence extends Component
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function updatedMotivationCourseLevel() {
|
|
|
+ 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();
|
|
|
+ $types_query = \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);
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
+ $types_query->whereIn('id', $this->add_member_courses);
|
|
|
+ }
|
|
|
+ $types = $types_query->get();
|
|
|
foreach ($types as $t) {
|
|
|
$type_ids[] = $t->course_type_id;
|
|
|
}
|
|
|
@@ -128,13 +184,19 @@ class Presence extends Component
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function updatedMotivationCourseType() {
|
|
|
+ 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();
|
|
|
+ $frequencies_query = \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);
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
+ $frequencies_query->whereIn('id', $this->add_member_courses);
|
|
|
+ }
|
|
|
+ $frequencies = $frequencies_query->get();
|
|
|
+
|
|
|
foreach ($frequencies as $f) {
|
|
|
$frequency_ids[] = $f->course_frequency_id;
|
|
|
}
|
|
|
@@ -145,11 +207,16 @@ class Presence extends Component
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function updatedMotivationCourseFrequency() {
|
|
|
+ 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();
|
|
|
+ $course_query = \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);
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
+ $course_query->whereIn('id', $this->add_member_courses);
|
|
|
+ }
|
|
|
+ $course = $course_query->first();
|
|
|
|
|
|
$this->motivation_course_id = $course->id;
|
|
|
} else {
|
|
|
@@ -196,35 +263,35 @@ class Presence extends Component
|
|
|
|
|
|
// $members_courses = \App\Models\MemberCourse::whereRaw("JSON_CONTAINS(`when`, JSON_OBJECT('day', JSON_ARRAY(?), 'from', ?), '$')", [$d, $h])->where('months', 'like', '%"m":' . $months . ',%')->whereIn('course_id', $courses)->pluck('member_id')->toArray();
|
|
|
$members_courses = \App\Models\MemberCourse::query()
|
|
|
- ->whereRaw("JSON_CONTAINS(`when`, JSON_OBJECT('day', JSON_ARRAY(?), 'from', ?), '$')", [$d, $h])
|
|
|
- ->whereRaw("JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED)), '$')", [$months])
|
|
|
- ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', 2), '$')", [$months])
|
|
|
- ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', '2'), '$')", [$months])
|
|
|
- ->whereIn('course_id', $courses)
|
|
|
- ->pluck('member_id')
|
|
|
- ->toArray();
|
|
|
+ ->whereRaw("JSON_CONTAINS(`when`, JSON_OBJECT('day', JSON_ARRAY(?), 'from', ?), '$')", [$d, $h])
|
|
|
+ ->whereRaw("JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED)), '$')", [$months])
|
|
|
+ ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', 2), '$')", [$months])
|
|
|
+ ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', '2'), '$')", [$months])
|
|
|
+ ->whereIn('course_id', $courses)
|
|
|
+ ->pluck('member_id')
|
|
|
+ ->toArray();
|
|
|
|
|
|
if ($this->filter != '') {
|
|
|
$filter = $this->filter;
|
|
|
$members = \App\Models\Member::whereIn('id', $members_courses)->where(function ($query) use ($filter) {
|
|
|
- $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $filter . "%'")
|
|
|
- ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $filter . "%'");
|
|
|
- })
|
|
|
- ->where(function($query) {
|
|
|
+ $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $filter . "%'")
|
|
|
+ ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $filter . "%'");
|
|
|
+ })
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_archived', false)
|
|
|
->orWhereNull('is_archived');
|
|
|
})
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_deleted', false)
|
|
|
->orWhereNull('is_deleted');
|
|
|
})->orderBy('last_name')->orderBy('first_name')->get();
|
|
|
} else
|
|
|
$members = \App\Models\Member::whereIn('id', $members_courses)
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_archived', false)
|
|
|
->orWhereNull('is_archived');
|
|
|
})
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_deleted', false)
|
|
|
->orWhereNull('is_deleted');
|
|
|
})->orderBy('last_name')->orderBy('first_name')->get();
|
|
|
@@ -245,24 +312,24 @@ class Presence extends Component
|
|
|
if ($this->filter != '') {
|
|
|
$filter = $this->filter;
|
|
|
$members = \App\Models\Member::whereIn('id', $members_presences)->where(function ($query) use ($filter) {
|
|
|
- $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $filter . "%'")
|
|
|
- ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $filter . "%'");
|
|
|
- })
|
|
|
- ->where(function($query) {
|
|
|
+ $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $filter . "%'")
|
|
|
+ ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $filter . "%'");
|
|
|
+ })
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_archived', false)
|
|
|
->orWhereNull('is_archived');
|
|
|
})
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_deleted', false)
|
|
|
->orWhereNull('is_deleted');
|
|
|
})->get();
|
|
|
} else
|
|
|
$members = \App\Models\Member::whereIn('id', $members_presences)
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_archived', false)
|
|
|
->orWhereNull('is_archived');
|
|
|
})
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('is_deleted', false)
|
|
|
->orWhereNull('is_deleted');
|
|
|
})->get();
|
|
|
@@ -473,6 +540,9 @@ class Presence extends Component
|
|
|
$this->added = true;
|
|
|
//if (!in_array($id, $this->newMembers))
|
|
|
// $this->newMembers[] = $id;
|
|
|
+ if (!is_array($ids)) {
|
|
|
+ $ids = [$ids];
|
|
|
+ }
|
|
|
|
|
|
$this->member_ids = $ids;
|
|
|
|
|
|
@@ -548,7 +618,34 @@ class Presence extends Component
|
|
|
$this->validate([
|
|
|
"newMemberMotivationId" => 'required',
|
|
|
]);
|
|
|
+
|
|
|
+ $validator = Validator::make(
|
|
|
+ [
|
|
|
+ 'motivation_course_id' => $this->motivation_course_id,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'motivation_course_id' => 'nullable|integer',
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
foreach ($this->member_ids as $m) {
|
|
|
+ $validator->after(function ($validator) use ($m) {
|
|
|
+ if (!$this->motivation_course_id) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $exists = \App\Models\MemberCourse::where('member_id', $m)->where('course_id', $this->motivation_course_id)->exists();
|
|
|
+
|
|
|
+ if (!$exists) {
|
|
|
+ $validator->errors()->add(
|
|
|
+ 'motivation_course_id',
|
|
|
+ 'Il corso selezionato non è associato a questo utente.'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $validator->validate();
|
|
|
+
|
|
|
//if ($this->manual)
|
|
|
//{
|
|
|
//\App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->where('status', '<>', 99)->delete();
|
|
|
@@ -586,7 +683,8 @@ class Presence extends Component
|
|
|
$this->resetCreationFields();
|
|
|
}
|
|
|
|
|
|
- public function resetCreationFields() {
|
|
|
+ public function resetCreationFields()
|
|
|
+ {
|
|
|
$this->insertUser = 'new';
|
|
|
$this->motivation_course_id = null;
|
|
|
$this->motivation_course_name = null;
|