course.blade.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. <div class="col-6 mt-2">
  107. <div class="form--item">
  108. <label for="inputName" class="form-label">Tipologia</label>
  109. <select class="form-select form-select-lg me-1 @error('course_type_id') is-invalid @enderror" wire:model="course_type_id">
  110. <option value="">
  111. @foreach($course_types as $c)
  112. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  113. @endforeach
  114. </select>
  115. </div>
  116. </div>
  117. <div class="col-6 mt-2">
  118. <div class="form--item">
  119. <label for="inputName" class="form-label">Durata</label>
  120. <select class="form-select form-select-lg me-1 @error('course_duration_id') is-invalid @enderror" wire:model="course_duration_id">
  121. <option value="">
  122. @foreach($course_durations as $c)
  123. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  124. @endforeach
  125. </select>
  126. </div>
  127. </div>
  128. <div class="col-6 mt-2">
  129. <div class="form--item">
  130. <label for="inputName" class="form-label">Frequenza</label>
  131. <select class="form-select form-select-lg me-1 @error('course_frequency_id') is-invalid @enderror" wire:model="course_frequency_id">
  132. <option value="">
  133. @foreach($course_frequencies as $c)
  134. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  135. @endforeach
  136. </select>
  137. </div>
  138. </div>
  139. <div class="col-6 mt-2">
  140. <div class="form--item">
  141. <label for="inputName" class="form-label">Livello</label>
  142. <select class="form-select form-select-lg me-1 @error('course_level_id') is-invalid @enderror" wire:model="course_level_id">
  143. <option value="">
  144. @foreach($course_levels as $c)
  145. <option value="{{$c["id"]}}">{{$c["name"]}}</option>
  146. @endforeach
  147. </select>
  148. </div>
  149. </div>
  150. <div class="col-3 mt-2">
  151. <div class="form--item">
  152. <label for="inputName" class="form-label">Data inizio</label>
  153. <input class="form-control" type="date" placeholder="Data inizio" wire:model="date_from">
  154. </div>
  155. </div>
  156. <div class="col-3 mt-2">
  157. <div class="form--item">
  158. <label for="inputName" class="form-label">Data fine</label>
  159. <input class="form-control" type="date" placeholder="Data fine" wire:model="date_to">
  160. </div>
  161. </div>
  162. <div class="col-6 mt-2">
  163. <div class="form--item">
  164. <label for="inputName" class="form-label">Prezzo mensile</label>
  165. <input class="form-control js-keyupTitle @error('price') is-invalid @enderror" type="text" id="price" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="price">
  166. @error('price')
  167. <div class="invalid-feedback">{{ $message }}</div>
  168. @enderror
  169. </div>
  170. </div>
  171. <div class="col-6 mt-2">
  172. <div class="form--item">
  173. <label for="inputName" class="form-label">Prezzo iscrizione</label>
  174. <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">
  175. @error('subscription_price')
  176. <div class="invalid-feedback">{{ $message }}</div>
  177. @enderror
  178. </div>
  179. </div>
  180. <div class="col-6 mt-2">
  181. <div class="form--item">
  182. <label for="inputName" class="form-label">Causale</label>
  183. <livewire:causals :type="$typeIN" :idx="0" :causal_id="$causal_id" :wire:key="0" />
  184. @error('causal_id')
  185. <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  186. @enderror
  187. </div>
  188. </div>
  189. <div class="col-6 mt-2">
  190. <div class="form--item">
  191. <label for="inputName" class="form-label">Causale iscrizione</label>
  192. <livewire:causals :type="$typeIN" :idx="0" :causal_id="$sub_causal_id" :wire:key="0" :emit="$setSubscriptionCausal" />
  193. @error('sub_causal_id')
  194. <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  195. @enderror
  196. </div>
  197. </div>
  198. <div class="col-6 mt-2">
  199. <div class="form--item">
  200. <label for="inputName" class="form-label">N° partecipanti</label>
  201. <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">
  202. @error('max_members')
  203. <div class="invalid-feedback">{{ $message }}</div>
  204. @enderror
  205. </div>
  206. </div>
  207. <div class="col-6 mt-2">
  208. <div class="form--item">
  209. <label for="inputName" class="form-label">Istruttore</label>
  210. <select class="form-select form-select-lg" wire:model="instructor_id">
  211. <option value="">
  212. @foreach($instructors as $ins)
  213. <option value="{{$ins["id"]}}">{{$ins["name"]}}
  214. @endforeach
  215. </select>
  216. </div>
  217. </div>
  218. <div class="col-6 mt-2">
  219. <div class="form--item">
  220. <label for="inputName" class="form-label">Anno</label>
  221. <select class="form-control" wire:model="year">
  222. @for($i=2024; $i<=date("Y") + 1; $i++)
  223. <option value="{{$i . "-" . $i + 1}}">{{$i . "/" . $i + 1}}
  224. @endfor
  225. </select>
  226. @error('year')
  227. <div class="invalid-feedback">{{ $message }}</div>
  228. @enderror
  229. </div>
  230. </div>
  231. <div class="col-6 mt-2">
  232. <div class="form--item">
  233. <label for="inputName" class="form-label">Gruppo di appartenenza</label>
  234. <select class="form-select form-select-lg me-1 @error('category_id') is-invalid @enderror" wire:model="category_id">
  235. <option value="">
  236. @foreach($categories as $category)
  237. <option value="{{$category["id"]}}">{{str_repeat(' ', $category["indentation"])}}{{$category["name"]}}
  238. @endforeach
  239. </select>
  240. </div>
  241. </div>
  242. <div class="col">
  243. <div class="form--item">
  244. <label for="enabled" class="form-label">Abilitato</label>
  245. <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
  246. </div>
  247. </div>
  248. </div>
  249. <div class="form--item">
  250. <button type="button" class="btn--ui lightGrey" onclick="annulla()">Annulla</button>
  251. @if($add)
  252. <button type="submit" class="btn--ui" wire:click.prevent="store()">Salva</button>
  253. @endif
  254. @if($update)
  255. <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
  256. @endif
  257. </div>
  258. </form>
  259. </div>
  260. </div>
  261. </div>
  262. @endif
  263. </div>
  264. @push('scripts')
  265. <link href="/css/datatables.css" rel="stylesheet" />
  266. <style>
  267. a.notSelected
  268. {
  269. display: flex;
  270. margin-right:10px;
  271. float:left;
  272. height: 2.5rem !important;
  273. width:50px;
  274. align-items: center;
  275. justify-content: center;
  276. color: #006099;
  277. background-color: #d3dce1 !important;
  278. padding: 0 1.25rem;
  279. font-size: 0.875rem;
  280. font-family: greycliff-cf, sans-serif;
  281. border-radius: 1.875rem !important;
  282. -webkit-border-radius: 1.875rem !important;
  283. -moz-border-radius: 1.875rem !important;
  284. -webkit-transition: all 0.3s ease-in-out;
  285. -moz-transition: all 0.3s ease-in-out;
  286. -o-transition: all 0.3s ease-in-out;
  287. transition: all 0.3s ease-in-out;
  288. border: none;
  289. }
  290. a.selected
  291. {
  292. display: flex;
  293. margin-right:10px;
  294. float:left;
  295. height: 2.5rem !important;
  296. width:50px;
  297. align-items: center;
  298. justify-content: center;
  299. color: #fff;
  300. background-color: #006099 !important;
  301. padding: 0 1.25rem;
  302. font-size: 0.875rem;
  303. font-family: greycliff-cf, sans-serif;
  304. border-radius: 1.875rem !important;
  305. -webkit-border-radius: 1.875rem !important;
  306. -moz-border-radius: 1.875rem !important;
  307. -webkit-transition: all 0.3s ease-in-out;
  308. -moz-transition: all 0.3s ease-in-out;
  309. -o-transition: all 0.3s ease-in-out;
  310. transition: all 0.3s ease-in-out;
  311. border: none;
  312. }
  313. div.day
  314. {
  315. margin-top:20px;
  316. color: #006099;
  317. background-color: #ffffff !important;
  318. padding: 20px;
  319. border-radius: 1.875rem !important;
  320. -webkit-border-radius: 1.875rem !important;
  321. -moz-border-radius: 1.875rem !important;
  322. -webkit-transition: all 0.3s ease-in-out;
  323. -moz-transition: all 0.3s ease-in-out;
  324. -o-transition: all 0.3s ease-in-out;
  325. transition: all 0.3s ease-in-out;
  326. border: 2px solid #d3dce1;
  327. }
  328. </style>
  329. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  330. <script src="/assets/js/datatables.js"></script>
  331. <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
  332. <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
  333. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
  334. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
  335. @endpush
  336. @push('scripts')
  337. <script>
  338. function onlyNumberAmount(input) {
  339. let v = input.value.replace(/\D+/g, '');
  340. if (v.length > 14) v = v.slice(0, 14);
  341. input.value = "€ " + v.replace(/(\d)(\d\d)$/, "$1,$2").replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:,|$))/g, '$1.');
  342. }
  343. var isEdit = false;
  344. Livewire.on('setEdit', (x) =>
  345. {
  346. isEdit = x;
  347. console.log(isEdit);
  348. });
  349. function annulla()
  350. {
  351. window.onbeforeunload = null;
  352. document.location.href = '/courses';
  353. }
  354. window.onbeforeunload = function(){
  355. if (isEdit)
  356. return 'Cambiando pagina le eventuali modifiche andranno perse';
  357. };
  358. $(document).ready(function() {
  359. loadDataTable();
  360. } );
  361. Livewire.on('load-data-table', () => {
  362. loadDataTable();
  363. });
  364. function reload()
  365. {
  366. console.log($(".filterYear").val());
  367. window.location.href = '/courses?year=' + $(".filterYear").val();
  368. }
  369. function loadDataTable(){
  370. if ( $.fn.DataTable.isDataTable('#tablesaw-350') ) {
  371. $('#tablesaw-350').DataTable().destroy();
  372. }
  373. $('#tablesaw-350').DataTable({
  374. thead: {
  375. 'th': {'background-color': 'blue'}
  376. },
  377. layout: {
  378. topStart : null,
  379. topEnd : null,
  380. top1A: {
  381. buttons: [
  382. {
  383. extend: 'collection',
  384. text: 'ESPORTA',
  385. buttons: [
  386. {
  387. extend: 'excelHtml5',
  388. title: 'Corsi',
  389. exportOptions: {
  390. columns: ":not(':last')"
  391. }
  392. },
  393. {
  394. extend: 'pdfHtml5',
  395. title: 'Corsi',
  396. exportOptions: {
  397. columns: ":not(':last')"
  398. }
  399. },
  400. {
  401. extend: 'print',
  402. text: 'Stampa',
  403. title: 'Corsi',
  404. exportOptions: {
  405. columns: ":not(':last')"
  406. }
  407. }
  408. ],
  409. dropup: true
  410. }
  411. ]
  412. },
  413. top1B : {
  414. pageLength: {
  415. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  416. }
  417. },
  418. top1C :'search',
  419. },
  420. "columnDefs": [ {
  421. "targets": 0,
  422. "orderable": false
  423. } ],
  424. pagingType: 'numbers',
  425. "language": {
  426. "url": "/assets/js/Italian.json"
  427. },
  428. "fnInitComplete": function (oSettings, json) {
  429. var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  430. $(".dt-search").append(html);
  431. html = '&nbsp;<a href="#" class="duplicateData btn--ui" style="display:none"><i class="fa-solid fa-copy fa-lg" style="height:5px;"></i></a>';
  432. $(".dt-buttons").after(html);
  433. }
  434. });
  435. $('#tablesaw-350 thead tr th').addClass('col');
  436. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  437. var courses = [];
  438. $(".chkCourse").click(function(){
  439. var id = $(this).attr('name');
  440. if(!courses.includes(id)){
  441. courses.push(id);
  442. }else{
  443. courses.splice(courses.indexOf(id), 1); //deleting
  444. }
  445. if (courses.length > 0)
  446. $(".duplicateData").show();
  447. else
  448. $(".duplicateData").hide();
  449. console.log(courses);
  450. });
  451. $(document).ready(function() {
  452. $(document).on("click",".addData",function() {
  453. $(".title--section_addButton").trigger("click");
  454. });
  455. $(document).on("click",".duplicateData",function() {
  456. @this.duplicateMultiple(courses);
  457. });
  458. } );
  459. var all = false;
  460. $(".checkAll").click(function(){
  461. all = !all;
  462. courses = [];
  463. $('.chkCourse').each(function(){
  464. $(this).prop('checked', all);
  465. if (all)
  466. courses.push($(this).attr('name'));
  467. });
  468. if (courses.length > 0)
  469. $(".duplicateData").show();
  470. else
  471. $(".duplicateData").hide();
  472. console.log(courses);
  473. });
  474. }
  475. </script>
  476. @endpush