course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get(); $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get(); $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get(); $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get(); $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name'); //if (sizeof($this->courses) > 0) // $this->courseId = $this->courses[0]->id; } public function render() { // Carico tutti i corsi associati /* if ($this->courseId > 0) $member_course = \App\Models\MemberCourse::where('course_id', $this->courseId)->with('member'); //->get(); else $member_course = \App\Models\MemberCourse::with('member'); //->get(); */ $member_course = \App\Models\MemberCourse::with('member'); if (sizeof($this->filterCourse) > 0) { $course_ids = []; foreach($this->filterCourse as $c) { $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get(); foreach($all as $a) { $course_ids[] = $a->id; } //$course_ids = array_merge($course_ids, $a); } //$course_ids = \App\Models\Course::where('name', 'like', '%' . $this->filterCourse . "%")->pluck('id'); $member_course = $member_course->whereIn('course_id', $course_ids); } if (sizeof($this->filterLevel) > 0) { $course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id'); $member_course = $member_course->whereIn('course_id', $course_ids); } if (sizeof($this->filterFrequency) > 0) { $course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id'); $member_course = $member_course->whereIn('course_id', $course_ids); } if (sizeof($this->filterType) > 0) { $course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id'); $member_course = $member_course->whereIn('course_id', $course_ids); } if (sizeof($this->filterDuration) > 0) { $course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id'); $member_course = $member_course->whereIn('course_id', $course_ids); } $member_course = $member_course->get(); $this->records = array(); foreach($member_course as $x) { $price = 0; $price = $x->course->price; $subPrice = $x->course->subscription_price; $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get(); $prices = []; foreach ($records as $record) { foreach ($record->rows as $row) { if ($row->causal_id == $x->course->sub_causal_id) { $subPrice = $row->amount; } if ($row->causal_id == $x->course->causal_id) { $tot = sizeof(json_decode($row->when)); foreach(json_decode($row->when) as $m) { $prices[$m->month] = $row->amount / $tot; } } } } $this->records[] = array( $x->member_id . "§" . $x->member->first_name . "§" . $x->member->last_name, $this->getColor($x->months, 9) . "§" . (isset($prices[9]) ? $prices[9] : $price), $this->getColor($x->months, 10) . "§" . (isset($prices[10]) ? $prices[10] : $price), $this->getColor($x->months, 11) . "§" . (isset($prices[11]) ? $prices[11] : $price), $this->getColor($x->months, 12) . "§" . (isset($prices[12]) ? $prices[12] : $price), $this->getColor($x->months, 1) . "§" . (isset($prices[1]) ? $prices[1] : $price), $this->getColor($x->months, 2) . "§" . (isset($prices[2]) ? $prices[2] : $price), $this->getColor($x->months, 3) . "§" . (isset($prices[3]) ? $prices[3] : $price), $this->getColor($x->months, 4) . "§" . (isset($prices[4]) ? $prices[4] : $price), $this->getColor($x->months, 5) . "§" . (isset($prices[5]) ? $prices[5] : $price), $this->getColor($x->months, 6) . "§" . (isset($prices[6]) ? $prices[6] : $price), $this->getColor($x->months, 7) . "§" . (isset($prices[7]) ? $prices[7] : $price), $this->getColor($x->months, 8) . "§" . (isset($prices[8]) ? $prices[8] : $price), $x->course_id, $x->id, $x->subscribed . "§" . $subPrice ); } $this->emit('load-data-table'); return view('livewire.course_list'); } public function getColor($months, $m) { $class = "grey"; foreach(json_decode($months) as $mm) { if ($mm->m == $m) { if ($mm->status == "") { $class = "orange"; } if ($mm->status == "1") { $class = "green"; } if ($mm->status == "2") { $class = "yellow"; } } } return $class; } public function search() { } public function newPayment($course_id, $month, $member_id, $id) { if ($month < 5) $month += 12; if ($month >= 5) $month -= 4; $c = \App\Models\Course::findOrFail($course_id); return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=0&months=' . $month . '&price=' . $c->price . '&subscription_price=' . $c->subscription_price . "&courseId=" . $id); } public function newSubscription($course_id, $member_id, $id) { $c = \App\Models\Course::findOrFail($course_id); return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=1&price=0.00&subscription_price=' . $c->subscription_price . "&courseId=" . $id); } public function disableSearch() { $this->filterCourse = []; $this->filterLevel = []; $this->filterType = []; $this->filterDuration = []; $this->filterFrequency = []; } }