| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- class CourseList extends Component
- {
- public $records = array();
- public $recordsNoPaginate = array();
- public $courses = array();
- public $start = 0;
- public $totalRecords = 0;
- public $pages = 0;
- public $currentPage = 1;
- public $pageLength = 10;
- public $totS = [];
- public $totSExcel = [];
- public $sort = '';
- public $dir = '';
- 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 updatedfilterCourse($value){
- $this->emit('load-data-table');
- }
- public function updatedfilterLevel($value){
- $this->emit('load-data-table');
- }
- public function updatedfilterFrequency($value){
- $this->emit('load-data-table');
- }
- public function updatedfilterType($value){
- $this->emit('load-data-table');
- }
- public function updatedfilterDuration($value){
- $this->emit('load-data-table');
- }
- public function updatedpageLength($value){
- $this->emit('load-data-table');
- }
- public function render()
- {
- /*
- 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');
- */
- $member_course = \App\Models\MemberCourse::with('member')->with('course');
- if ($this->hasFilter)
- {
- if (isset($_GET["search"]["value"]))
- {
- if ($_GET["search"]["value"] != '')
- {
- $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
- $member_ids = \App\Models\Member::where(function ($query) use ($v) {
- $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
- ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
- })->pluck('id');
- /*
- $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
- $member_ids = \App\Models\Member::where(function ($query) use ($v) {
- $query->where('first_name', 'like', '%' . $v . '%')
- ->orWhere('last_name', 'like', '%' . $v . '%');
- })->pluck('id');*/
- $member_course = $member_course->whereIn('member_id', $member_ids);
- }
- }
- if (sizeof($this->filterCourse) > 0)
- {
- $course_ids = [];
- $courses = $this->filterCourse;
- foreach($courses as $c)
- {
- $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
- foreach($all as $a)
- {
- $course_ids[] = $a->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);
- }
- }
- /*
- if ($_GET["filterCourse"] != "null")
- {
- $course_ids = [];
- $courses = explode(",", $_GET["filterCourse"]);
- foreach($courses as $c)
- {
- $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
- foreach($all as $a)
- {
- $course_ids[] = $a->id;
- }
- }
- $member_course = $member_course->whereIn('course_id', $course_ids);
- }
- if ($_GET["filterYear"] != "")
- {
- $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
- $member_course = $member_course->whereIn('course_id', $course_ids);
- }
- if ($_GET["filterLevel"] != "null")
- {
- $levels = explode(",", $_GET["filterLevel"]);
- $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
- $member_course = $member_course->whereIn('course_id', $course_ids);
- }
- if ($_GET["filterFrequency"] != "null")
- {
- $frequencies = explode(",", $_GET["filterFrequency"]);
- $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
- $member_course = $member_course->whereIn('course_id', $course_ids);
- }
- if ($_GET["filterType"] != "null")
- {
- $types = explode(",", $_GET["filterType"]);
- $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
- $member_course = $member_course->whereIn('course_id', $course_ids);
- }
- if ($_GET["filterDuration"] != "null")
- {
- $durations = explode(",", $_GET["filterDuration"]);
- $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
- $member_course = $member_course->whereIn('course_id', $course_ids);
- }
- */
- $totals = [];
- $totalIsc = [];
- $datas = [];
- $xxx = 1;
- /*
- $sortColumn = '';
- if (isset($_GET["order"]))
- {
- }
- */
- $column = '';
- $sort_value = 0;
- if ($this->sort != '')
- {
- $f = $this->sort;
- $d = $this->dir;
- if ($f >= 5 && $f <= 16)
- {
- $column = 'column_' . ($f - 2);
- if (session()->get('sort_column'))
- {
- if (session()->get('sort_column') != $f)
- {
- session()->put('sort_column', $f);
- session()->put('sort_order', $d);
- session()->put('sort_value', 0);
- $sort_value = 0;
- }
- else
- {
- if (session()->get('sort_order') == $d)
- {
- //session()->put('sort_value', 0);
- $sort_value = session()->get('sort_value', 0);
- }
- else
- {
- if (session()->get('sort_value', 0) == 0)
- {
- $sort_value = 1;
- }
- if (session()->get('sort_value', 0) == 1)
- {
- $sort_value = 2;
- }
- if (session()->get('sort_value', 0) == 2)
- {
- $sort_value = 3;
- }
- if (session()->get('sort_value', 0) == 3)
- {
- $sort_value = 0;
- }
- session()->put('sort_value', $sort_value);
- }
- session()->put('sort_order', $d);
- }
- }
- else
- {
- session()->put('sort_column', $f);
- session()->put('sort_order', $d);
- session()->put('sort_value', 0);
- $sort_value = 0;
- }
- }
- }
- //print $sort_value;
- $totals = [];
- $prices = [];
- $member_course_totals = $member_course->get();
- foreach($member_course_totals as $x)
- {
- $price = 0;
- $price = $x->price; // $x->course->price;
- $subPrice = $x->subscription_price; // $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)
- {
- if (isset($prices[$m->month]))
- $prices[$m->month] += $row->amount / $tot;
- else
- $prices[$m->month] = $row->amount / $tot;
- }
- }
- }
- }
- for($i=1; $i<=12; $i++)
- {
- $cls = $this->getColor($x->months, $i, isset($prices[$i]) && $prices[$i] == $price);
- if ($cls != 'wgrey')
- {
- if (!isset($totals[$i]))
- {
- $totals[$i]['green'] = 0;
- $totals[$i]['orange'] = 0;
- $totals[$i]['yellow'] = 0;
- }
- if ($cls == 'yellow')
- {
- $totals[$i][$cls] += 1;
- }
- else
- {
- $p = isset($prices[$i]) ? $prices[$i] : $price;
- //if (isset($totals[$i][$cls]))
- $totals[$i][$cls] += $p;
- //else
- //$totals[$i][$cls] = $p;
- }
- }
- }
- $sub = $x->subscribed ? "Y" : "N";
- if (isset($totalIsc[$sub]))
- $totalIsc[$sub] += $subPrice;
- else
- $totalIsc[$sub] = $subPrice;
- $s = 0;
- if ($column != '')
- {
- $z = 0;
- switch ($column) {
- case 'column_3':
- $z = 9;
- break;
- case 'column_4':
- $z = 10;
- break;
- case 'column_5':
- $z = 11;
- break;
- case 'column_6':
- $z = 12;
- break;
- case 'column_7':
- $z = 1;
- break;
- case 'column_8':
- $z = 2;
- break;
- case 'column_9':
- $z = 3;
- break;
- case 'column_10':
- $z = 4;
- break;
- case 'column_11':
- $z = 5;
- break;
- case 'column_12':
- $z = 6;
- break;
- case 'column_13':
- $z = 7;
- break;
- case 'column_14':
- $z = 8;
- break;
- default:
- $z = 0;
- break;
- }
- $c = getColor($x->months, $z);
- if ($sort_value == 0)
- {
- switch ($c) {
- case 'wgrey':
- $s = 0;
- break;
- case 'orange':
- $s = 1;
- break;
- case 'green':
- $s = 2;
- break;
- case 'yellow':
- $s = 3;
- break;
- default:
- $s = 0;
- break;
- }
- }
- if ($sort_value == 1)
- {
- switch ($c) {
- case 'wgrey':
- $s = 3;
- break;
- case 'orange':
- $s = 0;
- break;
- case 'green':
- $s = 1;
- break;
- case 'yellow':
- $s = 2;
- break;
- default:
- $s = 0;
- break;
- }
- }
- if ($sort_value == 2)
- {
- switch ($c) {
- case 'wgrey':
- $s = 2;
- break;
- case 'orange':
- $s = 3;
- break;
- case 'green':
- $s = 0;
- break;
- case 'yellow':
- $s = 1;
- break;
- default:
- $s = 0;
- break;
- }
- }
- if ($sort_value == 3)
- {
- switch ($c) {
- case 'wgrey':
- $s = 1;
- break;
- case 'orange':
- $s = 2;
- break;
- case 'green':
- $s = 3;
- break;
- case 'yellow':
- $s = 0;
- break;
- default:
- $s = 0;
- break;
- }
- }
- }
- $datas[] = array(
- "column_19" => $x->course->name,
- "column_0" => $x->member->last_name,
- "column_1" => $x->member->first_name,
- "column_2" => $x->subscribed . "§" . formatPrice($subPrice),
- "column_3" => $this->getColor($x->months, 9, isset($prices[9]) && $prices[9] == $price) . "§" . formatPrice(isset($prices[9]) ? $prices[9] : $price) . "§" . (isset($prices[9]) && $prices[9] != $price ? 'X' : ''),
- "column_4" => $this->getColor($x->months, 10, isset($prices[10]) && $prices[10] == $price) . "§" . formatPrice(isset($prices[10]) ? $prices[10] : $price) . "§" . (isset($prices[10]) && $prices[10] != $price ? 'X' : ''),
- "column_5" => $this->getColor($x->months, 11, isset($prices[11]) && $prices[11] == $price) . "§" . formatPrice(isset($prices[11]) ? $prices[11] : $price) . "§" . (isset($prices[11]) && $prices[11] != $price ? 'X' : ''),
- "column_6" => $this->getColor($x->months, 12, isset($prices[12]) && $prices[12] == $price) . "§" . formatPrice(isset($prices[12]) ? $prices[12] : $price) . "§" . (isset($prices[12]) && $prices[12] != $price ? 'X' : ''),
- "column_7" => $this->getColor($x->months, 1, isset($prices[1]) && $prices[1] == $price) . "§" . formatPrice(isset($prices[1]) ? $prices[1] : $price) . "§" . (isset($prices[1]) && $prices[1] != $price ? 'X' : ''),
- "column_8" => $this->getColor($x->months, 2, isset($prices[2]) && $prices[2] == $price) . "§" . formatPrice(isset($prices[2]) ? $prices[2] : $price) . "§" . (isset($prices[2]) && $prices[2] != $price ? 'X' : ''),
- "column_9" => $this->getColor($x->months, 3, isset($prices[3]) && $prices[3] == $price) . "§" . formatPrice(isset($prices[3]) ? $prices[3] : $price) . "§" . (isset($prices[3]) && $prices[3] != $price ? 'X' : ''),
- "column_10" => $this->getColor($x->months, 4, isset($prices[4]) && $prices[4] == $price) . "§" . formatPrice(isset($prices[4]) ? $prices[4] : $price) . "§" . (isset($prices[4]) && $prices[4] != $price ? 'X' : ''),
- "column_11" => $this->getColor($x->months, 5, isset($prices[5]) && $prices[5] == $price) . "§" . formatPrice(isset($prices[5]) ? $prices[5] : $price) . "§" . (isset($prices[5]) && $prices[5] != $price ? 'X' : ''),
- "column_12" => $this->getColor($x->months, 6, isset($prices[6]) && $prices[6] == $price) . "§" . formatPrice(isset($prices[6]) ? $prices[6] : $price) . "§" . (isset($prices[6]) && $prices[6] != $price ? 'X' : ''),
- "column_13" => $this->getColor($x->months, 7, isset($prices[7]) && $prices[7] == $price) . "§" . formatPrice(isset($prices[7]) ? $prices[7] : $price) . "§" . (isset($prices[7]) && $prices[7] != $price ? 'X' : ''),
- "column_14" => $this->getColor($x->months, 8, isset($prices[8]) && $prices[8] == $price) . "§" . formatPrice(isset($prices[8]) ? $prices[8] : $price) . "§" . (isset($prices[8]) && $prices[8] != $price ? 'X' : ''),
- "column_15" => $x->course_id,
- "column_16" => $x->id,
- "column_17" => $x->member_id,
- "column_18" => $xxx++,
- "column_20" => $s
- );
- }
- $count = $member_course->count();
- $this->totSExcel = [];
- $this->totS = [];
- //$js = '';
- $xx = 4;
- $str = '';
- if ($count > 0)
- {
- $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=green><small>" . (isset($totalIsc["Y"]) ? formatPrice($totalIsc["Y"]) : 0) . "</small></a><br>";
- $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=orange><small>" . (isset($totalIsc["N"]) ? formatPrice($totalIsc["N"]) : 0) . "</small></a><br>";
- $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=yellow><small>0</small></a><br>";
- $this->totSExcel[] = array('green' => (isset($totalIsc["Y"]) ? formatPrice($totalIsc["Y"]) : 0), 'orange' => (isset($totalIsc["N"]) ? formatPrice($totalIsc["N"]) : 0), 'yellow' => 0);
- }
- $this->totS[] = $str;
- $str = "";
- foreach($totals as $z => $t)
- {
- if ($z == 1) $xx = 5;
- if ($z == 2) $xx = 6;
- if ($z == 3) $xx = 7;
- if ($z == 4) $xx = 8;
- if ($z == 5) $xx = 9;
- if ($z == 6) $xx = 10;
- if ($z == 7) $xx = 11;
- if ($z == 8) $xx = 12;
- if ($z == 9) $xx = 1;
- if ($z == 10) $xx = 2;
- if ($z == 11) $xx = 3;
- if ($z == 12) $xx = 4;
- $str = '';
- $aaa = [];
- foreach($t as $x => $c)
- {
- $y = $x == 'yellow' ? $c : formatPrice($c);
- $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=" . $x . "><small>" . $y . "</small></a><br>";
- $aaa[$x] = $y;
- }
- $this->totSExcel[$xx] = $aaa;
- $this->totS[$xx] = $str;
- //$js .= $xx . "§" . $str . "_";
- $xx += 1;
- }
- for($e=sizeof($this->totS);$e<=12;$e++)
- {
- $this->totS[] = '';
- }
- if ($this->sort != '')
- {
- $s = $this->sort;
- if ($s == 1) $s = 21;
- if ($column != '')
- array_multisort(array_column($datas, 'column_20'), SORT_ASC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
- else
- array_multisort(array_column($datas, 'column_' . ($s - 2)), $this->dir == "ASC" ? SORT_ASC : SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
- }
- $xxx = 1;
- foreach($datas as $yyy => $d)
- {
- $datas[$yyy]["column_18"] = $xxx++;
- }
- $this->totalRecords = sizeof($datas);
- //$start = 0;
- $this->recordsNoPaginate = [];
- $this->recordsNoPaginate = $datas;
- //if (isset($_GET["start"]))
- $datas = array_slice($datas, $this->start, $this->pageLength);
- $this->pages = ceil($this->totalRecords / $this->pageLength);
- $this->records = [];
- $this->records = $datas;
- //$this->totS = $js;
- return view('livewire.course_list');
- }
- public function setPage($page)
- {
- $this->currentPage = $page;
- $this->start = $this->pageLength * ($page - 1);
- $this->emit('load-data-table');
- }
- public function setSort($sort)
- {
- $this->sort = $sort;
- if ($this->dir == '')
- $this->dir = 'ASC';
- else
- $this->dir = $this->dir == 'ASC' ? 'DESC' : 'ASC';
- $this->emit('load-data-table');
- }
- public function search()
- {
- $this->currentPage = 1;
- $this->start = 0;
- $this->hasFilter = true;
- $this->emit('load-data-table');
- }
- public function getColor($months, $m, $all)
- {
- $class = "wgrey";
- 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";
- }
- if (!$all)
- {
- $class = "orange";
- }
- }
- }
- 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);
- $m = \App\Models\MemberCourse::findOrFail($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=' . $m->price : '') . '&subscription_price=' . $m->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;
- }
- public function export()
- {
- $letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
- $spreadsheet = new Spreadsheet();
- $activeWorksheet = $spreadsheet->getActiveSheet();
- //$activeWorksheet->setCellValue('A1', 'PrimaNota');
- $activeWorksheet->setCellValue('A1', "Corso");
- $activeWorksheet->setCellValue('B1', "Cognome");
- $activeWorksheet->setCellValue('C1', "Nome");
- $activeWorksheet->setCellValue('D1', "Iscrizione");
- $activeWorksheet->setCellValue('E1', "Settembre");
- $activeWorksheet->setCellValue('F1', "Ottobre");
- $activeWorksheet->setCellValue('G1', "Novembre");
- $activeWorksheet->setCellValue('H1', "Dicembre");
- $activeWorksheet->setCellValue('I1', "Gennaio");
- $activeWorksheet->setCellValue('J1', "Febbraio");
- $activeWorksheet->setCellValue('K1', "Marzo");
- $activeWorksheet->setCellValue('L1', "Aprile");
- $activeWorksheet->setCellValue('M1', "Maggio");
- $activeWorksheet->setCellValue('N1', "Giugno");
- $activeWorksheet->setCellValue('O1', "Luglio");
- $activeWorksheet->setCellValue('P1', "Agosto");
- $count = 2;
- foreach($this->recordsNoPaginate as $idx => $record)
- {
- $activeWorksheet->setCellValue('A' . $count, $record["column_19"]);
- $activeWorksheet->setCellValue('B' . $count, $record["column_0"]);
- $activeWorksheet->setCellValue('C' . $count, $record["column_1"]);
- list($color, $value) = explode("§", $record["column_2"]);
- $activeWorksheet->setCellValue('D' . $count, $value);
- $c = '#FFFFFF';
- if($color == 0)
- $c = 'ffa500';
- if($color == 1)
- $c = '00ff00';
- $activeWorksheet->getStyle('D' . $count . ':D' . $count)
- ->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()
- ->setARGB($c);
- for($ii=3; $ii<=14; $ii++)
- {
- list($color, $value) = explode("§", $record["column_" . $ii]);
- $c = 'FFFFFF';
- if($color == 'orange')
- $c = 'ffa500';
- if($color == 'green')
- $c = '00ff00';
- if($color == 'yellow')
- {
- $c = '5088bf';
- $activeWorksheet->getStyle($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count)
- ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
- }
- if($color == 'wgrey')
- $value = '';
- $activeWorksheet->setCellValue($letters[$ii + 1] . $count, $value);
- $activeWorksheet->getStyle($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count)
- ->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()
- ->setARGB($c);
- /*$activeWorksheet->cells($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count, function ($cells) use ($c)
- {
- $cells->setBackground($c);
- //$cells->setAlignment('center');
- });*/
- }
- $activeWorksheet->getStyle("A1:P1")->getFont()->setBold( true );
- $count++;
- }
- // Totali
- $activeWorksheet->setCellValue('A' . (1 + $count), '');
- $activeWorksheet->setCellValue('B' . (1 + $count), '');
- $activeWorksheet->setCellValue('C' . (1 + $count), '');
- for($x=0; $x<=sizeof($this->totSExcel); $x++)
- {
- if (isset($this->totSExcel[$x]))
- {
- $activeWorksheet->setCellValue($letters[$x + 3] . (1 + $count), isset($this->totSExcel[$x]['green']) ? $this->totSExcel[$x]['green'] : 0);
- $activeWorksheet->getStyle($letters[$x + 3] . (1 + $count) . ':' . $letters[$x + 3] . (1 + $count))
- ->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()
- ->setARGB('00ff00');
- $activeWorksheet->setCellValue($letters[$x + 3] . (2 + $count), isset($this->totSExcel[$x]['orange']) ? $this->totSExcel[$x]['orange'] : 0);
- $activeWorksheet->getStyle($letters[$x + 3] . (2 + $count) . ':' . $letters[$x + 3] . (2 + $count))
- ->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()
- ->setARGB('ffa500');
- $activeWorksheet->setCellValue($letters[$x + 3] . (3 + $count), isset($this->totSExcel[$x]['yellow']) ? $this->totSExcel[$x]['yellow'] : 0);
- $activeWorksheet->getStyle($letters[$x + 3] . (3 + $count) . ':' . $letters[$x + 3] . (3 + $count))
- ->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()
- ->setARGB('5088bf');
- $activeWorksheet->getStyle($letters[$x + 3] . (3 + $count) . ':' . $letters[$x + 3] . (3 + $count))
- ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
- }
- }
- $writer = new Xlsx($spreadsheet);
- $writer->save($path = storage_path('pagamento_corsi_' . date("YmdHis") . '.xlsx'));
- $this->emit('load-data-table');
- return response()->download($path)->deleteFileAfterSend();
- }
- }
|