CourseMember.php 11 KB

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