| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class CourseList extends Component
- {
- public $records = array();
- public $courses = array();
- public $hasFilter = false;
- 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 $course_years = [];
- public $totals = [];
- public $totalIsc = [];
- public $aaa;
- public $months = array('Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago');
- public function mount()
- {
- $this->selectedCourseId = 0;
- $this->selectedMemberId = 0;
- $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->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year');
- $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();
- */
- if ($this->hasFilter)
- {
- $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->where('course_id', 999999);
- $member_course = $member_course->get();
- }
- else
- {
- $member_course = \App\Models\MemberCourse::with('member')->get();
- }
- $this->records = [];
- $this->totals = [];
- $this->totalIsc = [];
- 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
- );
- }
- $js = '';
- $xx = 2;
- $str = '';
- $str .= "<a class=green><small>" . (isset($this->totalIsc["Y"]) ? formatPrice($this->totalIsc["Y"]) : 0) . "</small></a><br>";
- $str .= "<a class=orange><small>" . (isset($this->totalIsc["N"]) ? formatPrice($this->totalIsc["N"]) : 0) . "</small></a><br>";
- $str .= "<a class=yellow><small>0</small></a><br>";
- $js .= "2§" . $str . "_";
- $str = "";
- foreach($this->totals as $z => $t)
- {
- if ($z == 1) $xx = 7;
- if ($z == 2) $xx = 8;
- if ($z == 3) $xx = 9;
- if ($z == 4) $xx = 10;
- if ($z == 5) $xx = 11;
- if ($z == 6) $xx = 12;
- if ($z == 7) $xx = 13;
- if ($z == 8) $xx = 14;
- if ($z == 9) $xx = 3;
- if ($z == 10) $xx = 4;
- if ($z == 11) $xx = 5;
- if ($z == 12) $xx = 6;
- $str = '';
- foreach($t as $x => $c)
- {
- $y = $x == 'yellow' ? $c : formatPrice($c);
- $str .= "<a class=" . $x . "><small>" . $y . "</small></a><br>";
- }
- $js .= $xx . "§" . $str . "_";
- $xx += 1;
- }
- //$this->aaa = $js;
- //$this->emit('setTotals', $js);
- $this->emit('load-data-table');
- return view('livewire.course_list');
- }
- public function search()
- {
- $this->hasFilter = true;
- }
- 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, $months, $member_id, $id, $subscription)
- {
-
- $newMonths = array();
- if ($months != '')
- {
- $mm = explode(",", $months);
- foreach($mm as $month)
- {
- if ($month < 5) $month += 12;
- if ($month >= 5) $month -= 4;
- $newMonths[] = $month;
- }
- }
-
- $c = \App\Models\Course::findOrFail($course_id);
- return redirect()->to('/in?new=1&memberId=' . $member_id . (sizeof($newMonths) > 0 ? '&causalId=' . $c->causal_id : '') . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=' . ($subscription ? 1 : 0) . (sizeof($newMonths) > 0 ? '&months=' . implode("|", $newMonths) : '') . (sizeof($newMonths) > 0 ? '&price=' . $c->price : '') . '&subscription_price=' . $c->subscription_price . "&courseId=" . $id);
- }
- /*
- public function newPayment()
- {
- $c = \App\Models\Course::findOrFail($this->selectedCourseId);
- return redirect()->to('/in?new=1&memberId=' . $this->selectedMemberId . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=0' . (sizeof($this->payMonths) > 0 ? '&months=' . implode("|", $this->payMonths) : "") . '&price=' . $c->price . '&subscription_price=' . $c->subscription_price . "&courseId=" . $this->selectedCourseId);
- }
- */
- 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 = [];
- $this->hasFilter = false;
- }
- }
|