CourseMember.php 11 KB

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