CourseList.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  5. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  6. class CourseList extends Component
  7. {
  8. public $records = array();
  9. public $recordsNoPaginate = array();
  10. public $courses = array();
  11. public $start = 0;
  12. public $totalRecords = 0;
  13. public $pages = 0;
  14. public $currentPage = 1;
  15. public $pageLength = 10;
  16. public $totS = [];
  17. public $totSExcel = [];
  18. public $sort = '';
  19. public $dir = '';
  20. public $hasFilter = false;
  21. public $courseId = 0;
  22. public $filterCourse = [];
  23. public $filterLevel = [];
  24. public $filterFrequency = [];
  25. public $filterType = [];
  26. public $filterDuration = [];
  27. public $course_durations = [];
  28. public $course_types = [];
  29. public $course_frequencies = [];
  30. public $course_levels = [];
  31. public $course_years = [];
  32. public $totals = [];
  33. public $totalIsc = [];
  34. public $aaa;
  35. public $months = array('Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago');
  36. public function mount()
  37. {
  38. $this->selectedCourseId = 0;
  39. $this->selectedMemberId = 0;
  40. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  41. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  42. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  43. $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get();
  44. $this->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year');
  45. $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
  46. //if (sizeof($this->courses) > 0)
  47. // $this->courseId = $this->courses[0]->id;
  48. }
  49. public function updatedfilterCourse($value){
  50. $this->emit('load-data-table');
  51. }
  52. public function updatedfilterLevel($value){
  53. $this->emit('load-data-table');
  54. }
  55. public function updatedfilterFrequency($value){
  56. $this->emit('load-data-table');
  57. }
  58. public function updatedfilterType($value){
  59. $this->emit('load-data-table');
  60. }
  61. public function updatedfilterDuration($value){
  62. $this->emit('load-data-table');
  63. }
  64. public function updatedpageLength($value){
  65. $this->emit('load-data-table');
  66. }
  67. public function render()
  68. {
  69. /*
  70. if ($this->hasFilter)
  71. {
  72. $member_course = \App\Models\MemberCourse::with('member');
  73. if (sizeof($this->filterCourse) > 0)
  74. {
  75. $course_ids = [];
  76. foreach($this->filterCourse as $c)
  77. {
  78. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  79. foreach($all as $a)
  80. {
  81. $course_ids[] = $a->id;
  82. }
  83. //$course_ids = array_merge($course_ids, $a);
  84. }
  85. //$course_ids = \App\Models\Course::where('name', 'like', '%' . $this->filterCourse . "%")->pluck('id');
  86. $member_course = $member_course->whereIn('course_id', $course_ids);
  87. }
  88. if (sizeof($this->filterLevel) > 0)
  89. {
  90. $course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id');
  91. $member_course = $member_course->whereIn('course_id', $course_ids);
  92. }
  93. if (sizeof($this->filterFrequency) > 0)
  94. {
  95. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id');
  96. $member_course = $member_course->whereIn('course_id', $course_ids);
  97. }
  98. if (sizeof($this->filterType) > 0)
  99. {
  100. $course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id');
  101. $member_course = $member_course->whereIn('course_id', $course_ids);
  102. }
  103. if (sizeof($this->filterDuration) > 0)
  104. {
  105. $course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id');
  106. $member_course = $member_course->whereIn('course_id', $course_ids);
  107. }
  108. //$member_course = $member_course->where('course_id', 999999);
  109. $member_course = $member_course->get();
  110. }
  111. else
  112. {
  113. $member_course = \App\Models\MemberCourse::with('member')->get();
  114. }
  115. $this->records = [];
  116. $this->totals = [];
  117. $this->totalIsc = [];
  118. foreach($member_course as $x)
  119. {
  120. $price = 0;
  121. $price = $x->course->price;
  122. $subPrice = $x->course->subscription_price;
  123. $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
  124. $prices = [];
  125. foreach ($records as $record)
  126. {
  127. foreach ($record->rows as $row)
  128. {
  129. //if ($row->causal_id == $x->course->sub_causal_id || str_contains(strtolower($row->note), 'iscrizione'))
  130. if (str_contains(strtolower($row->note), 'iscrizione'))
  131. {
  132. $subPrice = $row->amount;
  133. }
  134. if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  135. {
  136. $tot = sizeof(json_decode($row->when));
  137. foreach(json_decode($row->when) as $m)
  138. {
  139. $prices[$m->month] = $row->amount / $tot;
  140. }
  141. }
  142. }
  143. }
  144. for($i=1; $i<=12; $i++)
  145. {
  146. $cls = $this->getColor($x->months, $i);
  147. if ($cls != 'grey')
  148. {
  149. if (!isset($this->totals[$i]))
  150. {
  151. $this->totals[$i]['green'] = 0;
  152. $this->totals[$i]['orange'] = 0;
  153. $this->totals[$i]['yellow'] = 0;
  154. }
  155. if ($cls == 'yellow')
  156. {
  157. $this->totals[$i][$cls] += 1;
  158. }
  159. else
  160. {
  161. $p = isset($prices[$i]) ? $prices[$i] : $price;
  162. $this->totals[$i][$cls] += $p;
  163. }
  164. }
  165. }
  166. $sub = $x->subscribed ? "Y" : "N";
  167. if (isset($this->totalIsc[$sub]))
  168. $this->totalIsc[$sub] += $subPrice;
  169. else
  170. $this->totalIsc[$sub] = $subPrice;
  171. $this->records[] = array(
  172. $x->member_id . "§" . $x->member->first_name . "§" . $x->member->last_name,
  173. $this->getColor($x->months, 9) . "§" . (isset($prices[9]) ? $prices[9] : $price),
  174. $this->getColor($x->months, 10) . "§" . (isset($prices[10]) ? $prices[10] : $price),
  175. $this->getColor($x->months, 11) . "§" . (isset($prices[11]) ? $prices[11] : $price),
  176. $this->getColor($x->months, 12) . "§" . (isset($prices[12]) ? $prices[12] : $price),
  177. $this->getColor($x->months, 1) . "§" . (isset($prices[1]) ? $prices[1] : $price),
  178. $this->getColor($x->months, 2) . "§" . (isset($prices[2]) ? $prices[2] : $price),
  179. $this->getColor($x->months, 3) . "§" . (isset($prices[3]) ? $prices[3] : $price),
  180. $this->getColor($x->months, 4) . "§" . (isset($prices[4]) ? $prices[4] : $price),
  181. $this->getColor($x->months, 5) . "§" . (isset($prices[5]) ? $prices[5] : $price),
  182. $this->getColor($x->months, 6) . "§" . (isset($prices[6]) ? $prices[6] : $price),
  183. $this->getColor($x->months, 7) . "§" . (isset($prices[7]) ? $prices[7] : $price),
  184. $this->getColor($x->months, 8) . "§" . (isset($prices[8]) ? $prices[8] : $price),
  185. $x->course_id,
  186. $x->id,
  187. $x->subscribed . "§" . $subPrice
  188. );
  189. }
  190. $js = '';
  191. $xx = 2;
  192. $str = '';
  193. $str .= "<a class=green><small>" . (isset($this->totalIsc["Y"]) ? formatPrice($this->totalIsc["Y"]) : 0) . "</small></a><br>";
  194. $str .= "<a class=orange><small>" . (isset($this->totalIsc["N"]) ? formatPrice($this->totalIsc["N"]) : 0) . "</small></a><br>";
  195. $str .= "<a class=yellow><small>0</small></a><br>";
  196. $js .= "2§" . $str . "_";
  197. $str = "";
  198. foreach($this->totals as $z => $t)
  199. {
  200. if ($z == 1) $xx = 7;
  201. if ($z == 2) $xx = 8;
  202. if ($z == 3) $xx = 9;
  203. if ($z == 4) $xx = 10;
  204. if ($z == 5) $xx = 11;
  205. if ($z == 6) $xx = 12;
  206. if ($z == 7) $xx = 13;
  207. if ($z == 8) $xx = 14;
  208. if ($z == 9) $xx = 3;
  209. if ($z == 10) $xx = 4;
  210. if ($z == 11) $xx = 5;
  211. if ($z == 12) $xx = 6;
  212. $str = '';
  213. foreach($t as $x => $c)
  214. {
  215. $y = $x == 'yellow' ? $c : formatPrice($c);
  216. $str .= "<a class=" . $x . "><small>" . $y . "</small></a><br>";
  217. }
  218. $js .= $xx . "§" . $str . "_";
  219. $xx += 1;
  220. }
  221. //$this->aaa = $js;
  222. //$this->emit('setTotals', $js);
  223. $this->emit('load-data-table');
  224. */
  225. $member_course = \App\Models\MemberCourse::with('member')->with('course');
  226. if ($this->hasFilter)
  227. {
  228. if (isset($_GET["search"]["value"]))
  229. {
  230. if ($_GET["search"]["value"] != '')
  231. {
  232. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  233. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  234. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  235. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  236. })->pluck('id');
  237. /*
  238. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  239. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  240. $query->where('first_name', 'like', '%' . $v . '%')
  241. ->orWhere('last_name', 'like', '%' . $v . '%');
  242. })->pluck('id');*/
  243. $member_course = $member_course->whereIn('member_id', $member_ids);
  244. }
  245. }
  246. if (sizeof($this->filterCourse) > 0)
  247. {
  248. $course_ids = [];
  249. $courses = $this->filterCourse;
  250. foreach($courses as $c)
  251. {
  252. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  253. foreach($all as $a)
  254. {
  255. $course_ids[] = $a->id;
  256. }
  257. }
  258. $member_course = $member_course->whereIn('course_id', $course_ids);
  259. }
  260. if (sizeof($this->filterLevel) > 0)
  261. {
  262. $course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id');
  263. $member_course = $member_course->whereIn('course_id', $course_ids);
  264. }
  265. if (sizeof($this->filterFrequency) > 0)
  266. {
  267. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id');
  268. $member_course = $member_course->whereIn('course_id', $course_ids);
  269. }
  270. if (sizeof($this->filterType) > 0)
  271. {
  272. $course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id');
  273. $member_course = $member_course->whereIn('course_id', $course_ids);
  274. }
  275. if (sizeof($this->filterDuration) > 0)
  276. {
  277. $course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id');
  278. $member_course = $member_course->whereIn('course_id', $course_ids);
  279. }
  280. }
  281. /*
  282. if ($_GET["filterCourse"] != "null")
  283. {
  284. $course_ids = [];
  285. $courses = explode(",", $_GET["filterCourse"]);
  286. foreach($courses as $c)
  287. {
  288. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  289. foreach($all as $a)
  290. {
  291. $course_ids[] = $a->id;
  292. }
  293. }
  294. $member_course = $member_course->whereIn('course_id', $course_ids);
  295. }
  296. if ($_GET["filterYear"] != "")
  297. {
  298. $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
  299. $member_course = $member_course->whereIn('course_id', $course_ids);
  300. }
  301. if ($_GET["filterLevel"] != "null")
  302. {
  303. $levels = explode(",", $_GET["filterLevel"]);
  304. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  305. $member_course = $member_course->whereIn('course_id', $course_ids);
  306. }
  307. if ($_GET["filterFrequency"] != "null")
  308. {
  309. $frequencies = explode(",", $_GET["filterFrequency"]);
  310. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  311. $member_course = $member_course->whereIn('course_id', $course_ids);
  312. }
  313. if ($_GET["filterType"] != "null")
  314. {
  315. $types = explode(",", $_GET["filterType"]);
  316. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  317. $member_course = $member_course->whereIn('course_id', $course_ids);
  318. }
  319. if ($_GET["filterDuration"] != "null")
  320. {
  321. $durations = explode(",", $_GET["filterDuration"]);
  322. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  323. $member_course = $member_course->whereIn('course_id', $course_ids);
  324. }
  325. */
  326. $totals = [];
  327. $totalIsc = [];
  328. $datas = [];
  329. $xxx = 1;
  330. /*
  331. $sortColumn = '';
  332. if (isset($_GET["order"]))
  333. {
  334. }
  335. */
  336. $column = '';
  337. $sort_value = 0;
  338. if ($this->sort != '')
  339. {
  340. $f = $this->sort;
  341. $d = $this->dir;
  342. if ($f >= 5 && $f <= 16)
  343. {
  344. $column = 'column_' . ($f - 2);
  345. if (session()->get('sort_column'))
  346. {
  347. if (session()->get('sort_column') != $f)
  348. {
  349. session()->put('sort_column', $f);
  350. session()->put('sort_order', $d);
  351. session()->put('sort_value', 0);
  352. $sort_value = 0;
  353. }
  354. else
  355. {
  356. if (session()->get('sort_order') == $d)
  357. {
  358. //session()->put('sort_value', 0);
  359. $sort_value = session()->get('sort_value', 0);
  360. }
  361. else
  362. {
  363. if (session()->get('sort_value', 0) == 0)
  364. {
  365. $sort_value = 1;
  366. }
  367. if (session()->get('sort_value', 0) == 1)
  368. {
  369. $sort_value = 2;
  370. }
  371. if (session()->get('sort_value', 0) == 2)
  372. {
  373. $sort_value = 3;
  374. }
  375. if (session()->get('sort_value', 0) == 3)
  376. {
  377. $sort_value = 0;
  378. }
  379. session()->put('sort_value', $sort_value);
  380. }
  381. session()->put('sort_order', $d);
  382. }
  383. }
  384. else
  385. {
  386. session()->put('sort_column', $f);
  387. session()->put('sort_order', $d);
  388. session()->put('sort_value', 0);
  389. $sort_value = 0;
  390. }
  391. }
  392. }
  393. //print $sort_value;
  394. $totals = [];
  395. $prices = [];
  396. $member_course_totals = $member_course->get();
  397. foreach($member_course_totals as $x)
  398. {
  399. $price = 0;
  400. $price = $x->price; // $x->course->price;
  401. $subPrice = $x->subscription_price; // $x->course->subscription_price;
  402. $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
  403. $prices = [];
  404. foreach ($records as $record)
  405. {
  406. foreach ($record->rows as $row)
  407. {
  408. if ($row->causal_id == $x->course->sub_causal_id) // || str_contains(strtolower($row->note), 'iscrizione'))
  409. //if (str_contains(strtolower($row->note), 'iscrizione'))
  410. {
  411. $subPrice = $row->amount;
  412. }
  413. if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  414. {
  415. $tot = sizeof(json_decode($row->when));
  416. foreach(json_decode($row->when) as $m)
  417. {
  418. if (isset($prices[$m->month]))
  419. $prices[$m->month] += $row->amount / $tot;
  420. else
  421. $prices[$m->month] = $row->amount / $tot;
  422. }
  423. }
  424. }
  425. }
  426. for($i=1; $i<=12; $i++)
  427. {
  428. $cls = $this->getColor($x->months, $i, isset($prices[$i]) && $prices[$i] == $price);
  429. if ($cls != 'wgrey')
  430. {
  431. if (!isset($totals[$i]))
  432. {
  433. $totals[$i]['green'] = 0;
  434. $totals[$i]['orange'] = 0;
  435. $totals[$i]['yellow'] = 0;
  436. }
  437. if ($cls == 'yellow')
  438. {
  439. $totals[$i][$cls] += 1;
  440. }
  441. else
  442. {
  443. $p = isset($prices[$i]) ? $prices[$i] : $price;
  444. //if (isset($totals[$i][$cls]))
  445. $totals[$i][$cls] += $p;
  446. //else
  447. //$totals[$i][$cls] = $p;
  448. }
  449. }
  450. }
  451. $sub = $x->subscribed ? "Y" : "N";
  452. if (isset($totalIsc[$sub]))
  453. $totalIsc[$sub] += $subPrice;
  454. else
  455. $totalIsc[$sub] = $subPrice;
  456. $s = 0;
  457. if ($column != '')
  458. {
  459. $z = 0;
  460. switch ($column) {
  461. case 'column_3':
  462. $z = 9;
  463. break;
  464. case 'column_4':
  465. $z = 10;
  466. break;
  467. case 'column_5':
  468. $z = 11;
  469. break;
  470. case 'column_6':
  471. $z = 12;
  472. break;
  473. case 'column_7':
  474. $z = 1;
  475. break;
  476. case 'column_8':
  477. $z = 2;
  478. break;
  479. case 'column_9':
  480. $z = 3;
  481. break;
  482. case 'column_10':
  483. $z = 4;
  484. break;
  485. case 'column_11':
  486. $z = 5;
  487. break;
  488. case 'column_12':
  489. $z = 6;
  490. break;
  491. case 'column_13':
  492. $z = 7;
  493. break;
  494. case 'column_14':
  495. $z = 8;
  496. break;
  497. default:
  498. $z = 0;
  499. break;
  500. }
  501. $c = getColor($x->months, $z);
  502. if ($sort_value == 0)
  503. {
  504. switch ($c) {
  505. case 'wgrey':
  506. $s = 0;
  507. break;
  508. case 'orange':
  509. $s = 1;
  510. break;
  511. case 'green':
  512. $s = 2;
  513. break;
  514. case 'yellow':
  515. $s = 3;
  516. break;
  517. default:
  518. $s = 0;
  519. break;
  520. }
  521. }
  522. if ($sort_value == 1)
  523. {
  524. switch ($c) {
  525. case 'wgrey':
  526. $s = 3;
  527. break;
  528. case 'orange':
  529. $s = 0;
  530. break;
  531. case 'green':
  532. $s = 1;
  533. break;
  534. case 'yellow':
  535. $s = 2;
  536. break;
  537. default:
  538. $s = 0;
  539. break;
  540. }
  541. }
  542. if ($sort_value == 2)
  543. {
  544. switch ($c) {
  545. case 'wgrey':
  546. $s = 2;
  547. break;
  548. case 'orange':
  549. $s = 3;
  550. break;
  551. case 'green':
  552. $s = 0;
  553. break;
  554. case 'yellow':
  555. $s = 1;
  556. break;
  557. default:
  558. $s = 0;
  559. break;
  560. }
  561. }
  562. if ($sort_value == 3)
  563. {
  564. switch ($c) {
  565. case 'wgrey':
  566. $s = 1;
  567. break;
  568. case 'orange':
  569. $s = 2;
  570. break;
  571. case 'green':
  572. $s = 3;
  573. break;
  574. case 'yellow':
  575. $s = 0;
  576. break;
  577. default:
  578. $s = 0;
  579. break;
  580. }
  581. }
  582. }
  583. $datas[] = array(
  584. "column_19" => $x->course->name,
  585. "column_0" => $x->member->last_name,
  586. "column_1" => $x->member->first_name,
  587. "column_2" => $x->subscribed . "§" . formatPrice($subPrice),
  588. "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' : ''),
  589. "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' : ''),
  590. "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' : ''),
  591. "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' : ''),
  592. "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' : ''),
  593. "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' : ''),
  594. "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' : ''),
  595. "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' : ''),
  596. "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' : ''),
  597. "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' : ''),
  598. "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' : ''),
  599. "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' : ''),
  600. "column_15" => $x->course_id,
  601. "column_16" => $x->id,
  602. "column_17" => $x->member_id,
  603. "column_18" => $xxx++,
  604. "column_20" => $s
  605. );
  606. }
  607. $count = $member_course->count();
  608. $this->totSExcel = [];
  609. $this->totS = [];
  610. //$js = '';
  611. $xx = 4;
  612. $str = '';
  613. if ($count > 0)
  614. {
  615. $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>";
  616. $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>";
  617. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=yellow><small>0</small></a><br>";
  618. $this->totSExcel[] = array('green' => (isset($totalIsc["Y"]) ? formatPrice($totalIsc["Y"]) : 0), 'orange' => (isset($totalIsc["N"]) ? formatPrice($totalIsc["N"]) : 0), 'yellow' => 0);
  619. }
  620. $this->totS[] = $str;
  621. $str = "";
  622. foreach($totals as $z => $t)
  623. {
  624. if ($z == 1) $xx = 5;
  625. if ($z == 2) $xx = 6;
  626. if ($z == 3) $xx = 7;
  627. if ($z == 4) $xx = 8;
  628. if ($z == 5) $xx = 9;
  629. if ($z == 6) $xx = 10;
  630. if ($z == 7) $xx = 11;
  631. if ($z == 8) $xx = 12;
  632. if ($z == 9) $xx = 1;
  633. if ($z == 10) $xx = 2;
  634. if ($z == 11) $xx = 3;
  635. if ($z == 12) $xx = 4;
  636. $str = '';
  637. $aaa = [];
  638. foreach($t as $x => $c)
  639. {
  640. $y = $x == 'yellow' ? $c : formatPrice($c);
  641. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=" . $x . "><small>" . $y . "</small></a><br>";
  642. $aaa[$x] = $y;
  643. }
  644. $this->totSExcel[$xx] = $aaa;
  645. $this->totS[$xx] = $str;
  646. //$js .= $xx . "§" . $str . "_";
  647. $xx += 1;
  648. }
  649. for($e=sizeof($this->totS);$e<=12;$e++)
  650. {
  651. $this->totS[] = '';
  652. }
  653. if ($this->sort != '')
  654. {
  655. $s = $this->sort;
  656. if ($s == 1) $s = 21;
  657. if ($column != '')
  658. array_multisort(array_column($datas, 'column_20'), SORT_ASC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
  659. else
  660. array_multisort(array_column($datas, 'column_' . ($s - 2)), $this->dir == "ASC" ? SORT_ASC : SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
  661. }
  662. $xxx = 1;
  663. foreach($datas as $yyy => $d)
  664. {
  665. $datas[$yyy]["column_18"] = $xxx++;
  666. }
  667. $this->totalRecords = sizeof($datas);
  668. //$start = 0;
  669. $this->recordsNoPaginate = [];
  670. $this->recordsNoPaginate = $datas;
  671. //if (isset($_GET["start"]))
  672. $datas = array_slice($datas, $this->start, $this->pageLength);
  673. $this->pages = ceil($this->totalRecords / $this->pageLength);
  674. $this->records = [];
  675. $this->records = $datas;
  676. //$this->totS = $js;
  677. return view('livewire.course_list');
  678. }
  679. public function setPage($page)
  680. {
  681. $this->currentPage = $page;
  682. $this->start = $this->pageLength * ($page - 1);
  683. $this->emit('load-data-table');
  684. }
  685. public function setSort($sort)
  686. {
  687. $this->sort = $sort;
  688. if ($this->dir == '')
  689. $this->dir = 'ASC';
  690. else
  691. $this->dir = $this->dir == 'ASC' ? 'DESC' : 'ASC';
  692. $this->emit('load-data-table');
  693. }
  694. public function search()
  695. {
  696. $this->currentPage = 1;
  697. $this->start = 0;
  698. $this->hasFilter = true;
  699. $this->emit('load-data-table');
  700. }
  701. public function getColor($months, $m, $all)
  702. {
  703. $class = "wgrey";
  704. foreach(json_decode($months) as $mm)
  705. {
  706. if ($mm->m == $m)
  707. {
  708. if ($mm->status == "")
  709. {
  710. $class = "orange";
  711. }
  712. if ($mm->status == "1")
  713. {
  714. $class = "green";
  715. }
  716. if ($mm->status == "2")
  717. {
  718. $class = "yellow";
  719. }
  720. if (!$all)
  721. {
  722. $class = "orange";
  723. }
  724. }
  725. }
  726. return $class;
  727. }
  728. public function newPayment($course_id, $months, $member_id, $id, $subscription)
  729. {
  730. $newMonths = array();
  731. if ($months != '')
  732. {
  733. $mm = explode(",", $months);
  734. foreach($mm as $month)
  735. {
  736. if ($month < 5) $month += 12;
  737. if ($month >= 5) $month -= 4;
  738. $newMonths[] = $month;
  739. }
  740. }
  741. $c = \App\Models\Course::findOrFail($course_id);
  742. $m = \App\Models\MemberCourse::findOrFail($id);
  743. 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);
  744. }
  745. /*
  746. public function newPayment()
  747. {
  748. $c = \App\Models\Course::findOrFail($this->selectedCourseId);
  749. 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);
  750. }
  751. */
  752. public function newSubscription($course_id, $member_id, $id)
  753. {
  754. $c = \App\Models\Course::findOrFail($course_id);
  755. 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);
  756. }
  757. public function disableSearch()
  758. {
  759. $this->filterCourse = [];
  760. $this->filterLevel = [];
  761. $this->filterType = [];
  762. $this->filterDuration = [];
  763. $this->filterFrequency = [];
  764. $this->hasFilter = false;
  765. }
  766. public function export()
  767. {
  768. $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');
  769. $spreadsheet = new Spreadsheet();
  770. $activeWorksheet = $spreadsheet->getActiveSheet();
  771. //$activeWorksheet->setCellValue('A1', 'PrimaNota');
  772. $activeWorksheet->setCellValue('A1', "Corso");
  773. $activeWorksheet->setCellValue('B1', "Cognome");
  774. $activeWorksheet->setCellValue('C1', "Nome");
  775. $activeWorksheet->setCellValue('D1', "Iscrizione");
  776. $activeWorksheet->setCellValue('E1', "Settembre");
  777. $activeWorksheet->setCellValue('F1', "Ottobre");
  778. $activeWorksheet->setCellValue('G1', "Novembre");
  779. $activeWorksheet->setCellValue('H1', "Dicembre");
  780. $activeWorksheet->setCellValue('I1', "Gennaio");
  781. $activeWorksheet->setCellValue('J1', "Febbraio");
  782. $activeWorksheet->setCellValue('K1', "Marzo");
  783. $activeWorksheet->setCellValue('L1', "Aprile");
  784. $activeWorksheet->setCellValue('M1', "Maggio");
  785. $activeWorksheet->setCellValue('N1', "Giugno");
  786. $activeWorksheet->setCellValue('O1', "Luglio");
  787. $activeWorksheet->setCellValue('P1', "Agosto");
  788. $count = 2;
  789. foreach($this->recordsNoPaginate as $idx => $record)
  790. {
  791. $activeWorksheet->setCellValue('A' . $count, $record["column_19"]);
  792. $activeWorksheet->setCellValue('B' . $count, $record["column_0"]);
  793. $activeWorksheet->setCellValue('C' . $count, $record["column_1"]);
  794. list($color, $value) = explode("§", $record["column_2"]);
  795. $activeWorksheet->setCellValue('D' . $count, $value);
  796. $c = '#FFFFFF';
  797. if($color == 0)
  798. $c = 'ffa500';
  799. if($color == 1)
  800. $c = '00ff00';
  801. $activeWorksheet->getStyle('D' . $count . ':D' . $count)
  802. ->getFill()
  803. ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
  804. ->getStartColor()
  805. ->setARGB($c);
  806. for($ii=3; $ii<=14; $ii++)
  807. {
  808. list($color, $value) = explode("§", $record["column_" . $ii]);
  809. $c = 'FFFFFF';
  810. if($color == 'orange')
  811. $c = 'ffa500';
  812. if($color == 'green')
  813. $c = '00ff00';
  814. if($color == 'yellow')
  815. {
  816. $c = '5088bf';
  817. $activeWorksheet->getStyle($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count)
  818. ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
  819. }
  820. if($color == 'wgrey')
  821. $value = '';
  822. $activeWorksheet->setCellValue($letters[$ii + 1] . $count, $value);
  823. $activeWorksheet->getStyle($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count)
  824. ->getFill()
  825. ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
  826. ->getStartColor()
  827. ->setARGB($c);
  828. /*$activeWorksheet->cells($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count, function ($cells) use ($c)
  829. {
  830. $cells->setBackground($c);
  831. //$cells->setAlignment('center');
  832. });*/
  833. }
  834. $activeWorksheet->getStyle("A1:P1")->getFont()->setBold( true );
  835. $count++;
  836. }
  837. // Totali
  838. $activeWorksheet->setCellValue('A' . (1 + $count), '');
  839. $activeWorksheet->setCellValue('B' . (1 + $count), '');
  840. $activeWorksheet->setCellValue('C' . (1 + $count), '');
  841. for($x=0; $x<=sizeof($this->totSExcel); $x++)
  842. {
  843. if (isset($this->totSExcel[$x]))
  844. {
  845. $activeWorksheet->setCellValue($letters[$x + 3] . (1 + $count), isset($this->totSExcel[$x]['green']) ? $this->totSExcel[$x]['green'] : 0);
  846. $activeWorksheet->getStyle($letters[$x + 3] . (1 + $count) . ':' . $letters[$x + 3] . (1 + $count))
  847. ->getFill()
  848. ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
  849. ->getStartColor()
  850. ->setARGB('00ff00');
  851. $activeWorksheet->setCellValue($letters[$x + 3] . (2 + $count), isset($this->totSExcel[$x]['orange']) ? $this->totSExcel[$x]['orange'] : 0);
  852. $activeWorksheet->getStyle($letters[$x + 3] . (2 + $count) . ':' . $letters[$x + 3] . (2 + $count))
  853. ->getFill()
  854. ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
  855. ->getStartColor()
  856. ->setARGB('ffa500');
  857. $activeWorksheet->setCellValue($letters[$x + 3] . (3 + $count), isset($this->totSExcel[$x]['yellow']) ? $this->totSExcel[$x]['yellow'] : 0);
  858. $activeWorksheet->getStyle($letters[$x + 3] . (3 + $count) . ':' . $letters[$x + 3] . (3 + $count))
  859. ->getFill()
  860. ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
  861. ->getStartColor()
  862. ->setARGB('5088bf');
  863. $activeWorksheet->getStyle($letters[$x + 3] . (3 + $count) . ':' . $letters[$x + 3] . (3 + $count))
  864. ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
  865. }
  866. }
  867. $writer = new Xlsx($spreadsheet);
  868. $writer->save($path = storage_path('pagamento_corsi_' . date("YmdHis") . '.xlsx'));
  869. $this->emit('load-data-table');
  870. return response()->download($path)->deleteFileAfterSend();
  871. }
  872. }