course.blade.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <div class="col card--ui" id="card--dashboard">
  2. <header id="title--section" style="display:none !important" class="d-flex align-items-center justify-content-between">
  3. <div class="title--section_name d-flex align-items-center justify-content-between">
  4. <i class="ico--ui title_section utenti me-2"></i>
  5. <h2 class="primary">@if(!$add && !$update)Corsi @else Inserimento/modifica corso @endif</h2>
  6. </div>
  7. @if(!$add && !$update)
  8. <div class="title--section_addButton" wire:click="add()" style="cursor: pointer;">
  9. <div class="btn--ui entrata d-flex justify-items-between">
  10. <a href="#" wire:click="add()" style="color:white">Aggiungi</a>
  11. </div>
  12. </div>
  13. @endif
  14. </header>
  15. @if(!$add && !$update)
  16. <a class="btn--ui lightGrey" href="/settings?type=corsi"><i class="fa-solid fa-arrow-left"></i></a><br>
  17. <div class="row mt-3" style="margin-bottom:2rem !important;">
  18. <div class="col-1 mt-4">
  19. <h4>Anno</h4>
  20. </div>
  21. <div class="col-2 mt-4">
  22. <select class="form-select filterYear" onchange="reload()">
  23. <option value="">--Seleziona--
  24. @foreach($course_years as $c)
  25. @php
  26. $selected = '';
  27. if (!isset($_GET["year"]))
  28. {
  29. try
  30. {
  31. list($f, $t) = explode("-", $c);
  32. if ($f == date("Y") - 1)
  33. $selected = 'selected';
  34. } catch (Exception $e) {
  35. }
  36. }
  37. else
  38. {
  39. if ($_GET["year"] == $c)
  40. $selected = 'selected';
  41. }
  42. @endphp
  43. <option value="{{$c}}" {{$selected}}>{{$c}}
  44. @endforeach
  45. </select>
  46. </div>
  47. </div>
  48. <section id="resume-table">
  49. <div class="compare--chart_wrapper d-none"></div>
  50. <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
  51. <thead>
  52. <tr>
  53. <th style="text-align:center" scope="col"><input type="checkbox" class="checkAll"></th>
  54. <th scope="col">Anno</th>
  55. <th scope="col">Nome</th>
  56. <th scope="col">Livello</th>
  57. <th scope="col">Tipologia</th>
  58. <th scope="col">Frequenza</th>
  59. <th scope="col">Prezzo mensile</th>
  60. <th scope="col">N° partecipanti</th>
  61. <th scope="col">...</th>
  62. </tr>
  63. </thead>
  64. <tbody id="checkall-target">
  65. @foreach($records as $record)
  66. <tr>
  67. <td style="text-align:center"><input type="checkbox" class="chkCourse" name="{{$record->id}}"></td>
  68. <td>{{$record->year}}</td>
  69. <td>{{$record->name}}</td>
  70. <td>{{$record->level->name ?? ""}}</td>
  71. <td>{{$record->type->name ?? ""}}</td>
  72. <td>{{$record->frequency->name ?? ""}}</td>
  73. <td>{{formatPrice($record->price)}}</td>
  74. <td>{{$record->getCount()}}</td>
  75. <td>
  76. <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
  77. <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
  78. <button type="button" class="btn" wire:click="duplicate({{ $record->id }}, false)" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Duplica"><i class="fa-regular fa-copy"></i></button>
  79. </td>
  80. </tr>
  81. @endforeach
  82. </tbody>
  83. </table>
  84. </section>
  85. @else
  86. <a class="btn--ui lightGrey" href="/courses?showFilters=1"><i class="fa-solid fa-arrow-left"></i></a><br>
  87. <div class="container">
  88. @if (session()->has('error'))
  89. <div class="alert alert-danger" role="alert">
  90. {{ session()->get('error') }}
  91. </div>
  92. @endif
  93. <div class="row">
  94. <div class="col">
  95. <form action="">
  96. <div class="row mb-3 ">
  97. <div class="col-6 mt-2">
  98. <div class="form--item">
  99. <label for="inputName" class="form-label">Nome</label>
  100. <input class="form-control js-keyupTitle @error('name') is-invalid @enderror" type="text" id="name" placeholder="Nome" wire:model="name">
  101. @error('name')
  102. <div class="invalid-feedback">{{ $message }}</div>
  103. @enderror
  104. </div>
  105. </div>
  106. @if(false)
  107. <div class="col-6 mt-2">
  108. <div class="form--item">
  109. <label for="inputName" class="form-label">Tipologia</label>
  110. <select class="form-select form-select-lg me-1 @error('course_type_id') is-invalid @enderror" wire:model="course_type_id">
  111. <option value="">
  112. @foreach($course_types as $c)
  113. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  114. @endforeach
  115. </select>
  116. </div>
  117. </div>
  118. <div class="col-6 mt-2">
  119. <div class="form--item">
  120. <label for="inputName" class="form-label">Durata</label>
  121. <select class="form-select form-select-lg me-1 @error('course_duration_id') is-invalid @enderror" wire:model="course_duration_id">
  122. <option value="">
  123. @foreach($course_durations as $c)
  124. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  125. @endforeach
  126. </select>
  127. </div>
  128. </div>
  129. @endif
  130. <div class="col-6 mt-2">
  131. <div class="form--item">
  132. <label for="inputName" class="form-label">Frequenza</label>
  133. <select class="form-select form-select-lg me-1 @error('course_frequency_id') is-invalid @enderror" wire:model="course_frequency_id">
  134. <option value="">
  135. @foreach($course_frequencies as $c)
  136. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  137. @endforeach
  138. </select>
  139. </div>
  140. </div>
  141. <div class="col-6 mt-2">
  142. <div class="form--item">
  143. <label for="inputName" class="form-label">Livello</label>
  144. <select class="form-select form-select-lg me-1 @error('course_level_id') is-invalid @enderror" wire:model="course_level_id">
  145. <option value="">
  146. @foreach($course_levels as $c)
  147. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  148. @endforeach
  149. </select>
  150. </div>
  151. </div>
  152. <div class="col-3 mt-2">
  153. <div class="form--item">
  154. <label for="inputName" class="form-label">Data inizio</label>
  155. <input class="form-control" type="date" placeholder="Data inizio" wire:model="date_from">
  156. </div>
  157. </div>
  158. <div class="col-3 mt-2">
  159. <div class="form--item">
  160. <label for="inputName" class="form-label">Data fine</label>
  161. <input class="form-control" type="date" placeholder="Data fine" wire:model="date_to">
  162. </div>
  163. </div>
  164. @if(false)
  165. <div class="col-6 mt-2">
  166. <div class="form--item">
  167. <label for="inputName" class="form-label">Prezzo mensile</label>
  168. <input class="form-control js-keyupTitle @error('price') is-invalid @enderror" type="text" id="price" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="price">
  169. @error('price')
  170. <div class="invalid-feedback">{{ $message }}</div>
  171. @enderror
  172. </div>
  173. </div>
  174. <div class="col-6 mt-2">
  175. <div class="form--item">
  176. <label for="inputName" class="form-label">Prezzo iscrizione</label>
  177. <input class="form-control js-keyupTitle @error('subscription_price') is-invalid @enderror" type="text" id="subscription_price" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="subscription_price">
  178. @error('subscription_price')
  179. <div class="invalid-feedback">{{ $message }}</div>
  180. @enderror
  181. </div>
  182. </div>
  183. <div class="col-6 mt-2">
  184. <div class="form--item">
  185. <label for="inputName" class="form-label">Causale</label>
  186. <livewire:causals :type="$typeIN" :idx="0" :causal_id="$causal_id" :wire:key="0" />
  187. @error('causal_id')
  188. <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  189. @enderror
  190. </div>
  191. </div>
  192. <div class="col-6 mt-2">
  193. <div class="form--item">
  194. <label for="inputName" class="form-label">Causale iscrizione</label>
  195. <livewire:causals :type="$typeIN" :idx="0" :causal_id="$sub_causal_id" :wire:key="0" :emit="$setSubscriptionCausal" />
  196. @error('sub_causal_id')
  197. <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  198. @enderror
  199. </div>
  200. </div>
  201. @endif
  202. <div class="col-6 mt-2">
  203. <div class="form--item">
  204. <label for="inputName" class="form-label">N° partecipanti</label>
  205. <input class="form-control js-keyupTitle @error('max_members') is-invalid @enderror" type="text" id="max_members" placeholder="Numero massimo partecipanti" wire:model="max_members">
  206. @error('max_members')
  207. <div class="invalid-feedback">{{ $message }}</div>
  208. @enderror
  209. </div>
  210. </div>
  211. <div class="col-6 mt-2">
  212. <div class="form--item">
  213. <label for="inputName" class="form-label">Istruttore</label>
  214. <select class="form-select form-select-lg" wire:model="instructor_id">
  215. <option value="">
  216. @foreach($instructors as $ins)
  217. <option value="{{$ins["id"]}}">{{$ins["name"]}}
  218. @endforeach
  219. </select>
  220. </div>
  221. </div>
  222. <div class="col-6 mt-2">
  223. <div class="form--item">
  224. <label for="inputName" class="form-label">Gruppo di appartenenza</label>
  225. <select class="form-select form-select-lg me-1 @error('category_id') is-invalid @enderror" wire:model="category_id">
  226. <option value="">
  227. @foreach($categories as $category)
  228. <option value="{{$category["id"]}}">{{str_repeat(' ', $category["indentation"])}}{{$category["name"]}}
  229. @endforeach
  230. </select>
  231. </div>
  232. </div>
  233. <div class="col-6 mt-2">
  234. <div class="form--item">
  235. <label for="inputName" class="form-label">Anno</label>
  236. <select class="form-control" wire:model="year">
  237. @for($i=2024; $i<=date("Y") + 1; $i++)
  238. <option value="{{$i . "-" . $i + 1}}">{{$i . "/" . $i + 1}}
  239. @endfor
  240. </select>
  241. @error('year')
  242. <div class="invalid-feedback">{{ $message }}</div>
  243. @enderror
  244. </div>
  245. </div>
  246. <div class="col">
  247. <div class="form--item">
  248. <label for="enabled" class="form-label">Abilitato</label>
  249. <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
  250. </div>
  251. </div>
  252. </div>
  253. <div class="form--item">
  254. <button type="button" class="btn--ui lightGrey" onclick="annulla()">Annulla</button>
  255. @if($add)
  256. <button type="submit" class="btn--ui" wire:click.prevent="store()">Salva</button>
  257. @endif
  258. @if($update)
  259. <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
  260. @endif
  261. </div>
  262. </form>
  263. </div>
  264. </div>
  265. </div>
  266. @endif
  267. </div>
  268. @push('scripts')
  269. <link href="/css/datatables.css" rel="stylesheet" />
  270. <style>
  271. a.notSelected
  272. {
  273. display: flex;
  274. margin-right:10px;
  275. float:left;
  276. height: 2.5rem !important;
  277. width:50px;
  278. align-items: center;
  279. justify-content: center;
  280. color: #006099;
  281. background-color: #d3dce1 !important;
  282. padding: 0 1.25rem;
  283. font-size: 0.875rem;
  284. font-family: greycliff-cf, sans-serif;
  285. border-radius: 1.875rem !important;
  286. -webkit-border-radius: 1.875rem !important;
  287. -moz-border-radius: 1.875rem !important;
  288. -webkit-transition: all 0.3s ease-in-out;
  289. -moz-transition: all 0.3s ease-in-out;
  290. -o-transition: all 0.3s ease-in-out;
  291. transition: all 0.3s ease-in-out;
  292. border: none;
  293. }
  294. a.selected
  295. {
  296. display: flex;
  297. margin-right:10px;
  298. float:left;
  299. height: 2.5rem !important;
  300. width:50px;
  301. align-items: center;
  302. justify-content: center;
  303. color: #fff;
  304. background-color: #006099 !important;
  305. padding: 0 1.25rem;
  306. font-size: 0.875rem;
  307. font-family: greycliff-cf, sans-serif;
  308. border-radius: 1.875rem !important;
  309. -webkit-border-radius: 1.875rem !important;
  310. -moz-border-radius: 1.875rem !important;
  311. -webkit-transition: all 0.3s ease-in-out;
  312. -moz-transition: all 0.3s ease-in-out;
  313. -o-transition: all 0.3s ease-in-out;
  314. transition: all 0.3s ease-in-out;
  315. border: none;
  316. }
  317. div.day
  318. {
  319. margin-top:20px;
  320. color: #006099;
  321. background-color: #ffffff !important;
  322. padding: 20px;
  323. border-radius: 1.875rem !important;
  324. -webkit-border-radius: 1.875rem !important;
  325. -moz-border-radius: 1.875rem !important;
  326. -webkit-transition: all 0.3s ease-in-out;
  327. -moz-transition: all 0.3s ease-in-out;
  328. -o-transition: all 0.3s ease-in-out;
  329. transition: all 0.3s ease-in-out;
  330. border: 2px solid #d3dce1;
  331. }
  332. </style>
  333. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  334. <script src="/assets/js/datatables.js"></script>
  335. <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
  336. <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
  337. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
  338. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
  339. @endpush
  340. @push('scripts')
  341. <script>
  342. function onlyNumberAmount(input) {
  343. let v = input.value.replace(/\D+/g, '');
  344. if (v.length > 14) v = v.slice(0, 14);
  345. input.value = "€ " + v.replace(/(\d)(\d\d)$/, "$1,$2").replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:,|$))/g, '$1.');
  346. }
  347. var isEdit = false;
  348. Livewire.on('setEdit', (x) =>
  349. {
  350. isEdit = x;
  351. console.log(isEdit);
  352. });
  353. function annulla()
  354. {
  355. window.onbeforeunload = null;
  356. document.location.href = '/courses';
  357. }
  358. window.onbeforeunload = function(){
  359. if (isEdit)
  360. return 'Cambiando pagina le eventuali modifiche andranno perse';
  361. };
  362. $(document).ready(function() {
  363. loadDataTable();
  364. } );
  365. Livewire.on('load-data-table', () => {
  366. loadDataTable();
  367. });
  368. function reload()
  369. {
  370. console.log($(".filterYear").val());
  371. window.location.href = '/courses?year=' + $(".filterYear").val();
  372. }
  373. function loadDataTable(){
  374. if ( $.fn.DataTable.isDataTable('#tablesaw-350') ) {
  375. $('#tablesaw-350').DataTable().destroy();
  376. }
  377. $('#tablesaw-350').DataTable({
  378. thead: {
  379. 'th': {'background-color': 'blue'}
  380. },
  381. layout: {
  382. topStart : null,
  383. topEnd : null,
  384. top1A: {
  385. buttons: [
  386. {
  387. extend: 'collection',
  388. text: 'ESPORTA',
  389. buttons: [
  390. {
  391. extend: 'excelHtml5',
  392. title: 'Corsi',
  393. exportOptions: {
  394. columns: ":not(':last')"
  395. }
  396. },
  397. {
  398. extend: 'pdfHtml5',
  399. title: 'Corsi',
  400. exportOptions: {
  401. columns: ":not(':last')"
  402. }
  403. },
  404. {
  405. extend: 'print',
  406. text: 'Stampa',
  407. title: 'Corsi',
  408. exportOptions: {
  409. columns: ":not(':last')"
  410. }
  411. }
  412. ],
  413. dropup: true
  414. }
  415. ]
  416. },
  417. top1B : {
  418. pageLength: {
  419. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  420. }
  421. },
  422. top1C :'search',
  423. },
  424. "columnDefs": [ {
  425. "targets": 0,
  426. "orderable": false
  427. } ],
  428. pagingType: 'numbers',
  429. "language": {
  430. "url": "/assets/js/Italian.json"
  431. },
  432. "fnInitComplete": function (oSettings, json) {
  433. var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  434. $(".dt-search").append(html);
  435. html = '&nbsp;<a href="#" class="duplicateData btn--ui" style="display:none"><i class="fa-solid fa-copy fa-lg" style="height:5px;"></i></a>';
  436. $(".dt-buttons").after(html);
  437. }
  438. });
  439. $('#tablesaw-350 thead tr th').addClass('col');
  440. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  441. var courses = [];
  442. $(".chkCourse").click(function(){
  443. var id = $(this).attr('name');
  444. if(!courses.includes(id)){
  445. courses.push(id);
  446. }else{
  447. courses.splice(courses.indexOf(id), 1); //deleting
  448. }
  449. if (courses.length > 0)
  450. $(".duplicateData").show();
  451. else
  452. $(".duplicateData").hide();
  453. console.log(courses);
  454. });
  455. $(document).ready(function() {
  456. $(document).on("click",".addData",function() {
  457. $(".title--section_addButton").trigger("click");
  458. });
  459. $(document).on("click",".duplicateData",function() {
  460. @this.duplicateMultiple(courses);
  461. });
  462. } );
  463. var all = false;
  464. $(".checkAll").click(function(){
  465. all = !all;
  466. courses = [];
  467. $('.chkCourse').each(function(){
  468. $(this).prop('checked', all);
  469. if (all)
  470. courses.push($(this).attr('name'));
  471. });
  472. if (courses.length > 0)
  473. $(".duplicateData").show();
  474. else
  475. $(".duplicateData").hide();
  476. console.log(courses);
  477. });
  478. }
  479. </script>
  480. @endpush