| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use App\Models\MemberCourse;
- use Illuminate\Support\Facades\Log;
- 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 suspendPayment($course_id, $month, $member_id, $id, $subscription)
- {
- $monthMap = [
- 1 => 9, // September
- 2 => 10, // October
- 3 => 11, // November
- 4 => 12, // December
- 5 => 1, // January
- 6 => 2, // February
- 7 => 3, // March
- 8 => 4, // April
- 9 => 5, // May
- 10 => 6, // June
- 11 => 7, // July
- 12 => 8 // August
- ];
- $dbMonth = isset($monthMap[$month]) ? $monthMap[$month] : $month;
- $memberCourse = MemberCourse::where('id', $id)
- ->where('member_id', $member_id)
- ->where('course_id', $course_id)
- ->first();
- if (!$memberCourse) {
- return response()->json(['error' => 'Non Trovato'], 404);
- }
- $monthsData = json_decode($memberCourse->months, true);
- if (!is_array($monthsData)) {
- return response()->json(['error' => 'Invalid months data format'], 400);
- }
- $monthUpdated = false;
- foreach ($monthsData as &$monthData) {
- if ($monthData['m'] == $dbMonth) {
- $monthData['status'] = 2;
- $monthUpdated = true;
- }
- }
- if (!$monthUpdated) {
- return response()->json(['error' => 'Month not found in data'], 404);
- }
- $memberCourse->months = json_encode($monthsData);
- $memberCourse->save();
- session()->flash('success', 'Payment suspended successfully');
- return redirect()->to('/course_list');
- }
- public function resumePayment($course_id, $month, $member_id, $id, $subscription)
- {
- Log::info('resumePayment');
- Log::info($course_id);
- Log::info($month);
- Log::info($member_id);
- Log::info($id);
- $monthMap = [
- 1 => 9, // September
- 2 => 10, // October
- 3 => 11, // November
- 4 => 12, // December
- 5 => 1, // January
- 6 => 2, // February
- 7 => 3, // March
- 8 => 4, // April
- 9 => 5, // May
- 10 => 6, // June
- 11 => 7, // July
- 12 => 8 // August
- ];
- $dbMonth = isset($monthMap[$month]) ? $monthMap[$month] : $month;
- $memberCourse = MemberCourse::where('id', $id)
- ->where('member_id', $member_id)
- ->where('course_id', $course_id)
- ->first();
- if (!$memberCourse) {
- return response()->json(['error' => 'Non Trovato'], 404);
- }
- $monthsData = json_decode($memberCourse->months, true);
- Log::info('data mese',$monthsData);
- if (!is_array($monthsData)) {
- return response()->json(['error' => 'Invalid months data format'], 400);
- }
- $monthUpdated = false;
- foreach ($monthsData as &$monthData) {
- if ($monthData['m'] == $dbMonth) {
- $monthData['status'] = "";
- $monthUpdated = true;
- }
- }
- Log::info($monthUpdated);
- if (!$monthUpdated) {
- return response()->json(['error' => 'Month not found in data'], 404);
- }
- $memberCourse->months = json_encode($monthsData);
- $memberCourse->save();
- session()->flash('success', 'Payment resumed successfully');
- return redirect()->to('/course_list');
- }
- /*
- 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();
- }
- }
|