course.blade.php 26 KB

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