|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
use Livewire\Component;
|
|
use Livewire\Component;
|
|
|
use App\Http\Middleware\TenantMiddleware;
|
|
use App\Http\Middleware\TenantMiddleware;
|
|
|
|
|
|
|
@@ -43,6 +44,9 @@ class Presence extends Component
|
|
|
|
|
|
|
|
public $members = [];
|
|
public $members = [];
|
|
|
|
|
|
|
|
|
|
+ public $add_member_id = 0;
|
|
|
|
|
+ public $add_member_courses = [];
|
|
|
|
|
+
|
|
|
public $newMembers = [];
|
|
public $newMembers = [];
|
|
|
|
|
|
|
|
public $ids = [];
|
|
public $ids = [];
|
|
@@ -83,9 +87,48 @@ class Presence extends Component
|
|
|
$this->insertUser = 'exist';
|
|
$this->insertUser = 'exist';
|
|
|
$this->course_limit = now()->endOfDay();
|
|
$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_frequencies = [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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_frequencies = [];
|
|
|
|
|
+
|
|
|
|
|
+ $this->motivation_course_id = null;
|
|
|
|
|
+ $this->motivation_course_name = 0;
|
|
|
|
|
+ $this->motivation_course_level = 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_levels = [];
|
|
|
|
|
+ $this->course_types = [];
|
|
|
$this->course_frequencies = [];
|
|
$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()
|
|
function updatedMotivationCourseName()
|
|
@@ -96,7 +139,12 @@ class Presence extends Component
|
|
|
$this->motivation_course_frequency = 0;
|
|
$this->motivation_course_frequency = 0;
|
|
|
|
|
|
|
|
$levels_ids = [];
|
|
$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) {
|
|
foreach ($levels as $l) {
|
|
|
$levels_ids[] = $l->course_level_id;
|
|
$levels_ids[] = $l->course_level_id;
|
|
|
}
|
|
}
|
|
@@ -116,7 +164,12 @@ class Presence extends Component
|
|
|
$this->motivation_course_frequency = 0;
|
|
$this->motivation_course_frequency = 0;
|
|
|
|
|
|
|
|
$frequency_ids = [];
|
|
$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)->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);
|
|
|
|
|
+ if ($this->insertUser == 'exist') {
|
|
|
|
|
+ $frequencies_query->whereIn('id', $this->add_member_courses);
|
|
|
|
|
+ }
|
|
|
|
|
+ $frequencies = $frequencies_query->get();
|
|
|
|
|
+
|
|
|
foreach ($frequencies as $f) {
|
|
foreach ($frequencies as $f) {
|
|
|
$frequency_ids[] = $f->course_frequency_id;
|
|
$frequency_ids[] = $f->course_frequency_id;
|
|
|
}
|
|
}
|
|
@@ -132,7 +185,11 @@ class Presence extends Component
|
|
|
if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '' && $this->motivation_course_frequency > 0 && $this->motivation_course_frequency != '') {
|
|
if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '' && $this->motivation_course_frequency > 0 && $this->motivation_course_frequency != '') {
|
|
|
$this->motivation_course_id = null;
|
|
$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_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_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;
|
|
$this->motivation_course_id = $course->id;
|
|
|
} else {
|
|
} else {
|
|
@@ -481,6 +538,9 @@ class Presence extends Component
|
|
|
$this->added = true;
|
|
$this->added = true;
|
|
|
//if (!in_array($id, $this->newMembers))
|
|
//if (!in_array($id, $this->newMembers))
|
|
|
// $this->newMembers[] = $id;
|
|
// $this->newMembers[] = $id;
|
|
|
|
|
+ if (!is_array($ids)) {
|
|
|
|
|
+ $ids = [$ids];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$this->member_ids = $ids;
|
|
$this->member_ids = $ids;
|
|
|
|
|
|
|
@@ -556,7 +616,34 @@ class Presence extends Component
|
|
|
$this->validate([
|
|
$this->validate([
|
|
|
"newMemberMotivationId" => 'required',
|
|
"newMemberMotivationId" => 'required',
|
|
|
]);
|
|
]);
|
|
|
|
|
+
|
|
|
|
|
+ $validator = Validator::make(
|
|
|
|
|
+ [
|
|
|
|
|
+ 'motivation_course_id' => $this->motivation_course_id,
|
|
|
|
|
+ ],
|
|
|
|
|
+ [
|
|
|
|
|
+ 'motivation_course_id' => 'nullable|integer',
|
|
|
|
|
+ ]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
foreach ($this->member_ids as $m) {
|
|
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)
|
|
//if ($this->manual)
|
|
|
//{
|
|
//{
|
|
|
//\App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->where('status', '<>', 99)->delete();
|
|
//\App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->where('status', '<>', 99)->delete();
|