| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class CourseList extends Component
- {
- public $records = array();
- public $courses = array();
- public $courseId = 0;
- public $filterCourse = [];
- public $filterLevel = [];
- public $filterFrequency = [];
- public $filterType = [];
- public $filterDuration = [];
- public $course_durations = [];
- public $course_types = [];
- public $course_frequencies = [];
- public $course_levels = [];
- public $totals = [];
- public $totalIsc = [];
- public $months = array('Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago');
- public function mount()
- {
- $this->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 || str_contains(strtolower($row->note), 'iscrizione'))
- if (str_contains(strtolower($row->note), 'iscrizione'))
- {
- $subPrice = $row->amount;
- }
- if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
- {
- $tot = sizeof(json_decode($row->when));
- foreach(json_decode($row->when) as $m)
- {
- $prices[$m->month] = $row->amount / $tot;
- }
- }
- }
- }
- for($i=1; $i<=12; $i++)
- {
- $cls = $this->getColor($x->months, $i);
- if ($cls != 'grey')
- {
- if (!isset($this->totals[$i]))
- {
- $this->totals[$i]['green'] = 0;
- $this->totals[$i]['orange'] = 0;
- $this->totals[$i]['yellow'] = 0;
- }
- if ($cls == 'yellow')
- {
- $this->totals[$i][$cls] += 1;
- }
- else
- {
- $p = isset($prices[$i]) ? $prices[$i] : $price;
- $this->totals[$i][$cls] += $p;
- }
- }
- }
- $sub = $x->subscribed ? "Y" : "N";
- if (isset($this->totalIsc[$sub]))
- $this->totalIsc[$sub] += $subPrice;
- else
- $this->totalIsc[$sub] = $subPrice;
- $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 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 = [];
- }
- }
|