CourseMember.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. class CourseMember extends Component
  5. {
  6. public $records = array();
  7. public $courses = [];
  8. public $course_frequencies = [];
  9. public $course_types = [];
  10. public $course_levels = [];
  11. public $course_durations = [];
  12. public $course_years = [];
  13. public $fromYear = "";
  14. public $toYear = "";
  15. public $fromFromYear = "";
  16. public $toToYear = "";
  17. public $filterCourse = [];
  18. public $filterLevel = [];
  19. public $filterFrequency = [];
  20. public $filterType = [];
  21. public $filterDuration = [];
  22. public $filterDays = [];
  23. public $filterHours = [];
  24. public $filterSubscription = "";
  25. public $filterStatus = [];
  26. public $filterYear = "";
  27. /*public $chkCertificateNormal = 0;
  28. public $chkCertificateAgonistico = 0;
  29. public $chkCertificateScaduti = 0;*/
  30. public $chkCertificateType = "";
  31. public $chkCertificateScadenza = 0;
  32. public $chkCard = [];
  33. public $filter = '';
  34. public $filterFromPrevious = '';
  35. public function mount()
  36. {
  37. if (isset($_GET["id"]))
  38. {
  39. $this->filterFromPrevious = $_GET["id"];
  40. }
  41. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  42. $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get();
  43. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  44. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  45. $this->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year');
  46. $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
  47. if (date("m") >= env('FISCAL_YEAR_MONTH_FROM', 1))
  48. $this->filterYear = date("Y") . "-" . (date("Y") + 1);
  49. else
  50. $this->filterYear = (date("Y") - 1) . "-" . date("Y");
  51. }
  52. public function render()
  53. {
  54. // Carico tutti i corsi associati
  55. $this->filter = '';
  56. $datas = \App\Models\MemberCourse::with('member')
  57. ->where(function($query) {
  58. $query->where('members.is_archived', false)
  59. ->orWhereNull('members.is_archived');
  60. })
  61. ->where(function($query) {
  62. $query->where('members.is_deleted', false)
  63. ->orWhereNull('members.is_deleted');
  64. });
  65. if (sizeof($this->filterCourse) > 0)
  66. {
  67. $course_ids = [];
  68. foreach($this->filterCourse as $c)
  69. {
  70. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  71. foreach($all as $a)
  72. {
  73. $course_ids[] = $a->id;
  74. }
  75. }
  76. $datas = $datas->whereIn('course_id', $course_ids);
  77. }
  78. if (sizeof($this->filterLevel) > 0)
  79. {
  80. $course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id');
  81. $datas = $datas->whereIn('course_id', $course_ids);
  82. }
  83. if (sizeof($this->filterFrequency) > 0)
  84. {
  85. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id');
  86. $datas = $datas->whereIn('course_id', $course_ids);
  87. }
  88. if (sizeof($this->filterType) > 0)
  89. {
  90. $course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id');
  91. $datas = $datas->whereIn('course_id', $course_ids);
  92. }
  93. if (sizeof($this->filterDuration) > 0)
  94. {
  95. $course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id');
  96. $datas = $datas->whereIn('course_id', $course_ids);
  97. }
  98. if (sizeof($this->filterDays) > 0)
  99. {
  100. $m_ids = [];
  101. foreach($this->filterDays as $c)
  102. {
  103. $all = \App\Models\MemberCourse::where('when', 'like', "%" . $c . "%")->get();
  104. foreach($all as $a)
  105. {
  106. $m_ids[] = $a->member_id;
  107. }
  108. }
  109. $datas = $datas->whereIn('member_id', $m_ids);
  110. }
  111. if (sizeof($this->filterHours) > 0)
  112. {
  113. $m_ids = [];
  114. foreach($this->filterHours as $c)
  115. {
  116. $all = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $c . "%")->get();
  117. foreach($all as $a)
  118. {
  119. $m_ids[] = $a->member_id;
  120. }
  121. }
  122. $datas = $datas->whereIn('member_id', $m_ids);
  123. }
  124. /*if ($this->filterDays != "")
  125. {
  126. $members_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('member_id');
  127. $datas = $datas->whereIn('member_id', $members_ids);
  128. $this->filter .= $this->filter != '' ? ', ' : '';
  129. $this->filter .= "Giorni : " . $this->filterDays . " ";
  130. }
  131. if ($this->filterHours != "")
  132. {
  133. $members_ids = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $this->filterHours . "%")->pluck('member_id');
  134. $datas = $datas->whereIn('member_id', $members_ids);
  135. $this->filter .= $this->filter != '' ? ', ' : '';
  136. $this->filter .= "Ore : " . $this->filterHours . " ";
  137. }*/
  138. if ($this->filterSubscription != "")
  139. {
  140. $ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
  141. $datas = $datas->whereIn('id', $ids);
  142. $this->filter .= $this->filter != '' ? ', ' : '';
  143. $this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " ";
  144. }
  145. if ($this->chkCertificateType != "")
  146. {
  147. $types = \App\Models\MemberCertificate::where('type', $this->chkCertificateType)->pluck('member_id');
  148. $datas = $datas->whereIn('member_id', $types);
  149. }
  150. if ($this->chkCertificateScadenza > 0)
  151. {
  152. if ($this->chkCertificateScadenza == "1")
  153. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  154. if ($this->chkCertificateScadenza == "2")
  155. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  156. $datas = $datas->whereIn('member_id', $scad);
  157. }
  158. if ($this->fromYear != "")
  159. {
  160. $m_ids = \App\Models\Member::where('birth_date', '<', date("Y-m-d", strtotime("-" . $this->fromYear . " year", time())))->pluck('id');
  161. $datas = $datas->whereIn('member_id', $m_ids);
  162. }
  163. if ($this->toYear != "")
  164. {
  165. $m_ids = \App\Models\Member::where('birth_date', '>', date("Y-m-d", strtotime("-" . $this->toYear . " year", time())))->pluck('id');
  166. $datas = $datas->whereIn('member_id', $m_ids);
  167. }
  168. if ($this->fromFromYear != "")
  169. {
  170. $m_ids = \App\Models\Member::whereYear('birth_date', '>=', $this->fromFromYear)->pluck('id');
  171. $datas = $datas->whereIn('member_id', $m_ids);
  172. }
  173. if ($this->toToYear != "")
  174. {
  175. $m_ids = \App\Models\Member::whereYear('birth_date', '<=', $this->toToYear)->pluck('id');
  176. $datas = $datas->whereIn('member_id', $m_ids);
  177. }
  178. /*if ($_GET["toYear"] != "")
  179. {
  180. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  181. }
  182. if ($_GET["fromYearYear"] != "")
  183. {
  184. $x = $x->whereYear('birth_date', '>=', $_GET["fromYearYear"]);
  185. }
  186. if ($_GET["toYearYear"] != "")
  187. {
  188. $x = $x->whereYear('birth_date', '<=', $_GET["toYearYear"]);
  189. }*/
  190. /*
  191. if ($this->chkCertificateNormal > 0)
  192. {
  193. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  194. $datas = $datas->whereIn('member_id', $normal);
  195. $this->filter .= $this->filter != '' ? ', ' : '';
  196. $this->filter .= "Certificato normale : SI ";
  197. }
  198. if ($this->chkCertificateAgonistico > 0)
  199. {
  200. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  201. $datas = $datas->whereIn('member_id', $agonistic);
  202. $this->filter .= $this->filter != '' ? ', ' : '';
  203. $this->filter .= "Certificato agonistico : SI ";
  204. }
  205. if ($this->chkCertificateScaduti > 0)
  206. {
  207. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  208. $datas = $datas->whereIn('member_id', $scaduto);
  209. $this->filter .= $this->filter != '' ? ', ' : '';
  210. $this->filter .= "Certificato scaduto : SI ";
  211. }
  212. if ($this->chkCertificateScadenza > 0)
  213. {
  214. $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  215. $datas = $datas->whereIn('member_id', $scadenza);
  216. $this->filter .= $this->filter != '' ? ', ' : '';
  217. $this->filter .= "Certificato in scadenza : SI ";
  218. }*/
  219. if (sizeof($this->chkCard) > 0)
  220. {
  221. $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->chkCard)->pluck('member_id');
  222. $datas = $datas->whereIn('member_id', $card_ids);
  223. $this->filter .= $this->filter != '' ? ', ' : '';
  224. $this->filter .= "Tessera : ";
  225. foreach($this->chkCard as $card)
  226. {
  227. $this->filter .= \App\Models\Card::findOrFail($card)->name . " ";
  228. }
  229. }
  230. if ($this->filterYear != "")
  231. {
  232. $course_ids = \App\Models\Course::where('year', $this->filterYear)->pluck('id');
  233. $datas = $datas->whereIn('course_id', $course_ids);
  234. $this->filter .= $this->filter != '' ? ', ' : '';
  235. $this->filter .= "Anno : " . $this->filterYear . " ";
  236. }
  237. $aRet = [];
  238. if (sizeof($this->filterStatus) > 0)
  239. {
  240. foreach($this->filterStatus as $s)
  241. {
  242. foreach($datas->get() as $aaa)
  243. {
  244. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  245. if ($state["status"] == $s)
  246. $aRet[] = $aaa;
  247. }
  248. }
  249. }
  250. else
  251. $aRet = $datas->get();
  252. $this->records = $aRet;
  253. $this->emit('load-data-table');
  254. return view('livewire.course_member');
  255. }
  256. public function disableSearch()
  257. {
  258. $this->filterCourse = [];
  259. $this->filterLevel = [];
  260. $this->filterType = [];
  261. $this->filterDuration = [];
  262. $this->filterFrequency = [];
  263. $this->filterDays = [];
  264. $this->filterHours = [];
  265. $this->filterSubscription = "";
  266. $this->filterStatus = [];
  267. $this->chkCertificateNormal = 0;
  268. $this->chkCertificateAgonistico = 0;
  269. $this->chkCertificateScaduti = 0;
  270. $this->chkCertificateScadenza = 0;
  271. $this->chkCard = [];
  272. $this->filterYear = "";
  273. $this->fromYear = "";
  274. $this->toYear = "";
  275. $this->fromFromYear = "";
  276. $this->toToYear = "";
  277. }
  278. }