records_out.blade.php 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  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 uscite me-2"></i>
  5. <h2 class="primary" >@if(!$add && !$update)Uscite @else Inserimento/modifica uscita @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. <div class="title--section_addButton d-flex justify-content-end">
  17. <button type="button" class="btn--ui entrata"
  18. wire:click="openImportModal" onclick="openImportModal()">
  19. Importa
  20. </button>
  21. </div>
  22. <div class="modal fade" id="importModal" tabindex="-1" aria-labelledby="importModalLabel" aria-hidden="true"
  23. wire:ignore.self>
  24. <div class="modal-dialog">
  25. <div class="modal-content">
  26. <div class="modal-header" style="background-color: #0C6197!important;">
  27. <h5 class="modal-title" id="importModalLabel">Importa fatture passive</h5>
  28. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>onclick="closeImportModal()" aria-label="Close"></button>
  29. </div>
  30. <div class="modal-body">
  31. <form wire:submit.prevent="importReceipts">
  32. <div class="mb-3" wire:ignore>
  33. <label for="selectedCausal" class="form-label">Seleziona causale uscita*</label>
  34. <select class="form-select import-causal-select" required id="selectedCausal" wire:model.defer="selectedCausal">
  35. <option value="">Seleziona una causale</option>
  36. @forelse($importCausals as $causal)
  37. <option value="{{ $causal['id'] }}">{{ $causal['name'] }}</option>
  38. @empty
  39. <option value="" disabled>Nessuna causale disponibile</option>
  40. @endforelse
  41. </select>
  42. @error('selectedCausal') <span class="text-danger">{{ $message }}</span> @enderror
  43. </div>
  44. <div class="mb-3">
  45. <label for="receiptFiles" class="form-label">Seleziona files xml</label>
  46. <input type="file" class="form-control" id="receiptFiles" wire:model="receiptFiles" multiple>
  47. @error('receiptFiles.*') <span class="text-danger">{{ $message }}</span> @enderror
  48. <small class="form-text text-muted">Massimo {{ ini_get('max_file_uploads') }} file consentiti.</small>
  49. </div>
  50. <div class="progress mb-2" wire:ignore>
  51. <div class="progress-bar" role="progressbar" style="width: 0%" aria-valuenow="0"
  52. aria-valuemin="0" aria-valuemax="100">0%
  53. </div>
  54. </div>
  55. <div class="d-flex justify-content-end">
  56. <button type="button" class="btn--ui lightGrey me-2" onclick="closeImportModal()">Annulla</button>
  57. <button type="submit" class="btn--ui" >Importa</button>
  58. </div>
  59. </form>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <section id="subheader" class="d-flex align-items-center justify-content-between">
  65. @if(false)
  66. <form action="" class="group--action d-flex align-items-center">
  67. <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="multipleAction">
  68. <option selected>Azione multipla</option>
  69. <option value="delete"><i class="fa-regular fa-trash-can"></i></option>
  70. </select>
  71. <button type="submit" class="btn--ui" wire:click.prevent="executeMultipleAction()">applica</button>
  72. </form>
  73. <form action="" class="compare--form d-flex align-items-center">
  74. <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="selectedFilter">
  75. <option value="">--Seleziona--</option>
  76. <option value="0">Oggi</option>
  77. <option value="1">Questo mese: <span class="date-range">{{date("01/m/Y")}} - {{date("t/m/Y")}}</span></option>
  78. <option value="2">Questo anno: <span class="date-range">{{date("01/01/Y")}} - {{date("31/12/Y")}}</span></option>
  79. <option value="3">Tutte</option>
  80. </select>
  81. </form>
  82. @endif
  83. </section>
  84. <div class="showFilter" style="display:none">
  85. <hr size="1">
  86. <div class="row g-3">
  87. <div class="col-md-2">
  88. <div class="row">
  89. <div class="col-md-12" style="margin-bottom:10px;">
  90. <b>Periodo</b>
  91. </div>
  92. <div class="col-12">
  93. <input id="dateFrom" type="date" class="form-control filterFrom mb-2" >
  94. </div>
  95. <div class="col-12">
  96. <input id="dateTo" type="date" class="form-control filterTo" >
  97. </div>
  98. <div class="col-6 mt-2">
  99. <button class="btn--ui lightGrey todayButton" style="width:100%" onclick="setToday('{{date("Y-m-d")}}')">OGGI</button>
  100. </div>
  101. <div class="col-6 mt-2">
  102. <button class="btn--ui lightGrey yesterdayButton" style="width:100%" onclick="setYesterday('{{date("Y-m-d",strtotime("-1 days"))}}')">IERI</button>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="col-md-2">
  107. <div class="row">
  108. <div class="col-md-12" style="margin-bottom:10px;">
  109. <b>Fornitore</b>
  110. </div>
  111. <div class="col-12">
  112. <select name="search_supplier_id" class="form-select filterSupplier">
  113. <option value="">--Seleziona--
  114. @foreach($suppliers as $supplier)
  115. <option value="{{$supplier->id}}">{{$supplier->name}}
  116. @endforeach
  117. </select>
  118. </div>
  119. </div>
  120. </div>
  121. <div class="col-md-2">
  122. <div class="row">
  123. <div class="col-md-12" style="margin-bottom:10px;">
  124. <b>Metodi di pagamento</b>
  125. </div>
  126. <div class="col-12">
  127. <select name="search_payment_method_id" class="form-select filterPaymentMethod" multiple="multiple">
  128. @foreach($payments as $payment)
  129. <option value="{{$payment->id}}">{{$payment->name}}
  130. @endforeach
  131. </select>
  132. </div>
  133. </div>
  134. </div>
  135. <div class="col-md-2">
  136. <div class="row">
  137. <div class="col-md-12" style="margin-bottom:10px;">
  138. <b>Causali</b>
  139. </div>
  140. <div class="col-12">
  141. <select name="search_causal_id" class="form-select filterCausals" multiple="multiple">
  142. @foreach($causals as $causal)
  143. <option value="{{$causal["id"]}}">{!!$causal["name"]!!}
  144. @endforeach
  145. </select>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. <div class="row g-3">
  151. <div class="col-md-12" style="text-align:right">
  152. <button class="btn--ui lightGrey" onclick="reset()">Reset</button>
  153. <button class="btn--ui" onclick="loadDataTable()">FILTRA</button>
  154. </div>
  155. </div>
  156. <hr size="1">
  157. </div>
  158. <section id="resume-table">
  159. <div class="compare--chart_wrapper d-none"></div>
  160. <table class="table tablesaw tableHead tablesaw-stack table--lista_entrate tableHead" id="tablesaw-350" width="100%">
  161. <thead>
  162. <tr>
  163. <th scope="col">N° Fattura</th>
  164. <th scope="col">Data</th>
  165. <th scope="col">Importo</th>
  166. <th scope="col">Fornitore</th>
  167. <th scope="col">Causale</th>
  168. <th scope="col">Pagamento</th>
  169. <th scope="col">Stato</th>
  170. <th scope="col">...</th>
  171. </tr>
  172. </thead>
  173. <tbody id="checkall-target">
  174. </tbody>
  175. </table>
  176. <br><b class="totalDiv"></b>
  177. </section>
  178. @else
  179. <a style="margin-top:20px" class="btn--ui lightGrey" href="/{{$fromPage != '' ? ($fromPage . '?showFilters=1') : 'out'}}"><i class="fa-solid fa-arrow-left"></i></a><br><br>
  180. @if (session()->has('error'))
  181. <div class="alert alert-danger" role="alert">
  182. {{ session()->get('error') }}
  183. </div>
  184. @endif
  185. <section id="accountingExit" class="d-flex" wire:key='reload-{{$selectId}}'>
  186. <div class="accountingExit_data">
  187. <form class="form--accounting">
  188. <div class="row gx-2">
  189. <div class="col-md-12">
  190. <span class="title-form d-block w-100">Tipologia</span>
  191. <div class="input-group mb-3">
  192. <div class="check--invoice d-flex align-items-center">
  193. <div class="form-check me-3">
  194. <input class="form-check-input" type="radio" value="1" wire:model="commercial" id="commercial_1">
  195. <label class="form-check-label" for="commercial_1" style="cursor: pointer;">&nbsp;Commerciale</label>
  196. </div>
  197. <div class="form-check">
  198. <input class="form-check-input" type="radio" value="0" wire:model="commercial" id="commercial_0">
  199. <label class="form-check-label" for="commercial_0" style="cursor: pointer;">&nbsp;Non Commerciale</label>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. <span class="title-form d-block w-100">N° Fattura</span>
  205. <div class="input-group mb-3">
  206. <div class="col-md-6">
  207. <input class="form-control " type="text" placeholder="Numero fattura" wire:model="numero_fattura">
  208. </div>
  209. </div>
  210. <div class="col-md-6">
  211. <span class="title-form d-block w-100">Data</span>
  212. <div class="input-group mb-3">
  213. <input id="date" type="date" class="form-control" wire:model="date">
  214. </div>
  215. </div>
  216. <div class="col-md-6">
  217. <span class="title-form d-block w-100">Data Pagamento</span>
  218. <div class="input-group mb-3">
  219. <input id="datePagamento" type="date" class="form-control" wire:model="data_pagamento">
  220. </div>
  221. </div>
  222. <div class="col-12">
  223. <span class="title-form d-block w-100">Fornitore</span>
  224. <select name="supplier_id" class="form-select supplierClass @error('supplier_id') is-invalid @enderror" aria-label="Seleziona un fornitore" wire:model="supplier_id">
  225. <option value="">--Seleziona--
  226. @foreach($suppliers as $supplier)
  227. <option value="{{$supplier->id}}">{{$supplier->name}}
  228. @endforeach
  229. </select>
  230. @error('supplier_id')
  231. <div class="invalid-feedback">{{ $message }}</div>
  232. @enderror
  233. </div>
  234. </div>
  235. <div class="row gx-2 mt-5">
  236. <span class="title-form d-block w-100">Metodo di pagamento</span>
  237. <div class="col-md-6">
  238. <select name="payment_method_id" class="form-select paymentClass @error('payment_method_id') is-invalid @enderror" aria-label="Seleziona un metodo di pagamento" wire:model="payment_method_id">
  239. <option value="">--Seleziona--
  240. @foreach($payments as $payment)
  241. <option value="{{$payment->id}}">{{$payment->name}}
  242. @endforeach
  243. </select>
  244. @error('payment_method_id')
  245. <div class="invalid-feedback">{{ $message }}</div>
  246. @enderror
  247. </div>
  248. </div>
  249. <div class="row gx-2 mt-5">
  250. <span class="title-form d-block w-100">
  251. Allegato
  252. </span>
  253. <div class="col-md-12">
  254. @if ($attachment_old != '')
  255. <div class="alert alert-info d-flex align-items-center justify-content-between mb-3">
  256. <div class="d-flex align-items-center">
  257. <i class="fa-solid fa-file-check me-2"></i>
  258. <div>
  259. <strong>Allegato presente:</strong>
  260. <a href="{{ $this->getAttachmentUrl($attachment_old) }}" target="_blank" class="ms-2 btn btn-sm btn-outline-primary">
  261. <i class="fa-regular fa-eye me-1"></i>Visualizza
  262. </a>
  263. </div>
  264. </div>
  265. <button type="button"
  266. wire:click.prevent="removeAttachment()"
  267. class="btn btn-sm btn-outline-danger"
  268. data-bs-toggle="popover"
  269. data-bs-trigger="hover focus"
  270. data-bs-placement="bottom"
  271. data-bs-content="Elimina allegato corrente">
  272. <i class="fa-regular fa-trash-can me-1"></i>Rimuovi
  273. </button>
  274. </div>
  275. @endif
  276. <div class="mb-3">
  277. <label for="attachment" class="form-label d-flex align-items-center">
  278. <i class="fa-solid fa-cloud-upload-alt me-2"></i>
  279. @if ($attachment_old != '')
  280. Sostituisci allegato esistente
  281. @else
  282. Carica nuovo allegato
  283. @endif
  284. </label>
  285. <div class="file-upload-container position-relative">
  286. <input class="form-control file-input"
  287. type="file"
  288. id="attachment"
  289. wire:model="attachment"
  290. accept="image/*,.pdf,.doc,.docx,.xml,.txt,.csv,.xls,.xlsx"
  291. style="opacity: 0; position: absolute; top: 0; left: 0; width: 100%; height: 100%; cursor: pointer; z-index: 2;">
  292. <div class="file-drop-zone border-2 border-dashed rounded p-4 text-center position-relative"
  293. id="file-drop-zone"
  294. style="border-color: #dee2e6; background-color: #f8f9fa; min-height: 120px; display: flex; flex-direction: column; justify-content: center;">
  295. <div class="file-drop-content">
  296. <i class="fa-solid fa-cloud-upload-alt fa-2x text-muted mb-2"></i>
  297. <p class="mb-1"><strong>Clicca per selezionare</strong> o trascina qui il file</p>
  298. <small class="text-muted">
  299. Formati: Immagini, PDF, Word, XML, TXT, CSV, Excel<br>
  300. Dimensione massima: 10MB
  301. </small>
  302. </div>
  303. </div>
  304. </div>
  305. </div>
  306. <div id="upload-progress" class="mb-3" style="display: none;">
  307. <div class="d-flex justify-content-between mb-1">
  308. <span class="upload-status">
  309. <i class="fa-solid fa-spinner fa-spin me-2"></i>
  310. Caricamento in corso...
  311. </span>
  312. <span class="upload-percentage">0%</span>
  313. </div>
  314. <div class="progress" style="height: 8px;">
  315. <div class="progress-bar bg-primary progress-bar-striped progress-bar-animated"
  316. role="progressbar" style="width: 0%"></div>
  317. </div>
  318. <small class="text-muted mt-1 d-block upload-details"></small>
  319. </div>
  320. @if($attachment)
  321. <div class="alert alert-success d-flex align-items-center mb-3 file-selected-info">
  322. <i class="fa-solid fa-check-circle me-2"></i>
  323. <div class="flex-grow-1">
  324. <strong>Nuovo allegato selezionato:</strong>
  325. <span class="text-muted">{{ $attachment->getClientOriginalName() }}</span>
  326. <br><small class="text-muted">
  327. Dimensione: <span class="file-size-display">{{ number_format($attachment->getSize() / 1024, 1) }} KB</span>
  328. @if($attachment->getSize() > 10 * 1024 * 1024)
  329. <span class="badge bg-warning ms-2">
  330. <i class="fa-solid fa-exclamation-triangle me-1"></i>
  331. File di grandi dimensioni
  332. </span>
  333. @endif
  334. </small>
  335. </div>
  336. <button type="button" class="btn btn-sm btn-outline-secondary" onclick="clearFileSelection()">
  337. <i class="fa-solid fa-times"></i>
  338. </button>
  339. </div>
  340. @endif
  341. @error('attachment')
  342. <div class="alert alert-danger">
  343. <i class="fa-solid fa-exclamation-triangle me-2"></i>{{ $message }}
  344. </div>
  345. @enderror
  346. </div>
  347. </div>
  348. @foreach($rows as $idx => $row)
  349. <div class="row gx-2 mt-5" wire:ignore.self>
  350. <span class="title-form d-block w-100">Causale</span>
  351. <div class="col-md-12">
  352. <livewire:causals :type="$typeOUT" :idx="$idx" :causal_id="$rows[$idx]['causal_id']" :wire:key="$idx" />
  353. @if(false)
  354. <select name="rows.{{$idx}}.causal_id" class="form-select causalClass @error('row.' . $idx . '.causal_id') is-invalid @enderror" aria-label="Seleziona una causale" wire:model="rows.{{$idx}}.causal_id">
  355. <option value="">--Seleziona--
  356. @foreach($causals as $causal)
  357. <option value="{{$causal["id"]}}">{!!$causal["name"]!!}
  358. @endforeach
  359. </select>
  360. @error('causal_id')
  361. <div class="invalid-feedback">{{ $message }}</div>
  362. @enderror
  363. @endif
  364. @error('rows.'. $idx . '.causal_id')
  365. <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  366. @enderror
  367. </div>
  368. </div>
  369. <div class="row gx-2 mt-5">
  370. <span class="title-form d-block w-100">Dettaglio causale</span>
  371. <div class="col-md-12">
  372. <textarea class="form-control" style ="background-color: #E9F0F5 !important;" placeholder="Dettaglio causale" wire:model="rows.{{$idx}}.note"></textarea>
  373. </div>
  374. </div>
  375. <div class="row gx-2 mt-5 align-items-center">
  376. <div class="col-md-6">
  377. <span class="total primary">Imponibile</span>
  378. </div>
  379. <div class="col-md-6">
  380. @if($add)
  381. <input type="text" class="form-control totalInput text-end @error('rows.{{$idx}}.imponibile') is-invalid @enderror"
  382. id="rows.{{$idx}}.imponibile" wire:model="rows.{{$idx}}.imponibile"
  383. wire:keydown.enter="store(false)" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00">
  384. @endif
  385. @if($update)
  386. <input type="text" class="form-control totalInput text-end @error('rows.{{$idx}}.imponibile') is-invalid @enderror"
  387. id="rows.{{$idx}}.imponibile" placeholder="€ 0,00" wire:model="rows.{{$idx}}.imponibile"
  388. onkeyup="onlyNumberAmount(this)" wire:keydown.enter="update(false)">
  389. @endif
  390. @error('rows.'. $idx . '.imponibile')
  391. <span style="margin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  392. @enderror
  393. </div>
  394. </div>
  395. @if($commercial)
  396. <div class="row gx-2 mt-5 align-items-center">
  397. <div class="col-md-6">
  398. <span class="total primary">Aliquota IVA</span>
  399. </div>
  400. <div class="col-md-2 ms-auto">
  401. @if($add || $update )
  402. <select class="form-select text-end @error('rows.'.$idx.'.aliquota_iva') is-invalid @enderror"
  403. id="rows.{{$idx}}.aliquota_iva"
  404. wire:model="rows.{{$idx}}.aliquota_iva">
  405. <option value="">--Seleziona--</option>
  406. @foreach($vats as $vat)
  407. <option value="{{$vat->value}}">{{$vat->name}}</option>
  408. @endforeach
  409. </select>
  410. @error('rows.'. $idx . '.aliquota_iva')
  411. <span style="margin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  412. @enderror
  413. @endif
  414. </div>
  415. </div>
  416. @endif
  417. <div class="row gx-2 mt-5 align-items-center">
  418. <div class="col-md-6">
  419. <span class="total primary">Importo</span>
  420. </div>
  421. <div class="col-md-6">
  422. @if($add)
  423. <input type="text" class="form-control totalInput text-end @error('amount') is-invalid @enderror" id="rows.{{$idx}}.amount" wire:model="rows.{{$idx}}.amount" wire:keydown.enter="store(false)" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00">
  424. @endif
  425. @if($update)
  426. <input type="text" class="form-control totalInput text-end @error('amount') is-invalid @enderror" id="rows.{{$idx}}.amount" placeholder="€ 0,00" wire:model="rows.{{$idx}}.amount" onkeyup="onlyNumberAmount(this)" wire:keydown.enter="update(false)">
  427. @endif
  428. @error('rows.'. $idx . '.amount')
  429. <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
  430. @enderror
  431. </div>
  432. </div>
  433. <div class="row gx-2 mt-5 align-items-center">
  434. <div class="col-md-4">
  435. <span class="total primary">Periodo</span>
  436. </div>
  437. <div class="col-md-8">
  438. @if($multiP)
  439. <div class="row">
  440. <div class="col-md-3">
  441. <span class="title-form d-block w-100">Dal mese</span>
  442. <div class="input-group mb-3">
  443. <select class="form-select form-select-lg me-1" wire:model="multiMonthFrom">
  444. @foreach(getMonthList() as $mid => $mname)
  445. <option value="{{$mid}}">{{$mname}}</option>
  446. @endforeach
  447. </select>
  448. </div>
  449. </div>
  450. <div class="col-md-3">
  451. <span class="title-form d-block w-100">Anno</span>
  452. <div class="input-group mb-3">
  453. <input type="number" class="form-control" wire:model="multiYearFrom" >
  454. </div>
  455. </div>
  456. <div class="col-md-3">
  457. <span class="title-form d-block w-100">Dal mese</span>
  458. <div class="input-group mb-3">
  459. <select class="form-select form-select-lg me-1" wire:model="multiMonthTo">
  460. @foreach(getMonthList() as $mid => $mname)
  461. <option value="{{$mid}}">{{$mname}}</option>
  462. @endforeach
  463. </select>
  464. </div>
  465. </div>
  466. <div class="col-md-3">
  467. <span class="title-form d-block w-100">Anno</span>
  468. <div class="input-group mb-3">
  469. <input type="number" class="form-control" wire:model="multiYearTo" >
  470. </div>
  471. </div>
  472. <div class="col-md-6">
  473. <button type="button" class="btn--ui primary" wire:click.prevent="multiPeriodCreate({{$idx}})" style="margin-top:20px">
  474. Crea multi periodo
  475. </button>
  476. </div>
  477. <div class="col-md-6">
  478. <button type="button" class="btn--ui lightGrey" wire:click.prevent="multiPeriodCancel()" style="margin-top:20px">
  479. Annulla multi periodo
  480. </button>
  481. </div>
  482. </div>
  483. @else
  484. <div class="row">
  485. @foreach($row["when"] as $xxx => $w)
  486. <div class="col-md-4">
  487. <span class="title-form d-block w-100">Mese</span>
  488. <div class="input-group mb-3">
  489. <select class="form-select form-select-lg me-1" wire:model="rows.{{$idx}}.when.{{$xxx}}.month">
  490. @foreach(getMonthList() as $mid => $mname)
  491. <option value="{{$mid}}">{{$mname}}</option>
  492. @endforeach
  493. </select>
  494. </div>
  495. </div>
  496. <div class="col-md-3">
  497. <span class="title-form d-block w-100">Anno</span>
  498. <div class="input-group mb-3">
  499. <input type="number" class="form-control" wire:model="rows.{{$idx}}.when.{{$xxx}}.year" >
  500. </div>
  501. </div>
  502. <div class="col-md-3">
  503. <span class="title-form d-block w-100">Valore</span>
  504. <span class="netprice_p total--wrapper_netprice"><b>{{$this->currencyToDouble($rows[$idx]["amount"]) > 0 ? formatPrice($this->currencyToDouble($rows[$idx]["amount"]) / sizeof($rows[$idx]["when"])) : ""}}</b></span>
  505. </div>
  506. <div class="col-md-2"><br>
  507. <button type="button" class="btn--ui primary" wire:click.prevent="delPeriod({{$idx}}, {{$xxx}})" style="float:right">
  508. -
  509. </button>
  510. </div>
  511. @endforeach
  512. <div class="d-flex justify-content-between mt-3">
  513. <button type="button" class="btn--ui primary order-2" wire:click.prevent="addPeriod({{$idx}})">
  514. Aggiungi periodo
  515. </button>
  516. <button type="button" class="btn--ui_tertiary primary order-1" wire:click.prevent="multiPeriod()">
  517. Imposta multi periodo
  518. </button>
  519. </div>
  520. </div>
  521. @endif
  522. </div>
  523. </div>
  524. <br><br>
  525. @if($idx > 0)
  526. <button type="button" class="btn--ui primary" wire:click.prevent="delRow({{$idx}})" style="float:right">
  527. Rimuovi causale
  528. </button>
  529. <br><br>
  530. @endif
  531. <hr size="1">
  532. @endforeach
  533. <br>
  534. <button type="button" class="btn--ui primary" wire:click.prevent="addRow()">
  535. Aggiungi causale
  536. </button>
  537. <div class="accountingExit--btn d-flex align-items-center justify-content-between">
  538. <button class="btn--ui lightGrey" onclick="annulla()">annulla</button>
  539. @if($add)
  540. <button class="btn--ui primary" type="submit" wire:click.prevent="store()">inserisci</button>
  541. @endif
  542. @if($update)
  543. <button class="btn--ui primary" type="submit" wire:click.prevent="update()">salva</button>
  544. @endif
  545. </div>
  546. </form>
  547. </div>
  548. </section>
  549. @endif
  550. <div class="modal fade" id="importResultModal" tabindex="-1" aria-labelledby="importResultModalLabel" aria-hidden="true">
  551. <div class="modal-dialog">
  552. <div class="modal-content">
  553. <div class="modal-header">
  554. <h5 class="modal-title" id="importResultModalLabel">Importazione Completata</h5>
  555. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  556. </div>
  557. <div class="modal-body">
  558. <div id="importResultMessage"></div>
  559. </div>
  560. <div class="modal-footer">
  561. <button type="button" class="btn--ui lightGrey" data-bs-dismiss="modal">Chiudi</button>
  562. </div>
  563. </div>
  564. </div>
  565. </div>
  566. <div class="modal fade" id="recordDetailsModal" tabindex="-1" aria-labelledby="recordDetailsModalLabel" aria-hidden="true">
  567. <div class="modal-dialog modal-lg">
  568. <div class="modal-content">
  569. <div class="modal-header" style="background-color: #0C6197!important;">
  570. <h5 class="modal-title" id="recordDetailsModalLabel">Dettaglio uscita</h5>
  571. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  572. </div>
  573. <div class="modal-body">
  574. <div class="row mb-4">
  575. <div class="col-md-6">
  576. <h6 class="primary">Informazioni generali</h6>
  577. <table class="table table-sm table-borderless">
  578. <tr>
  579. <th>Data:</th>
  580. <td id="recordDate"></td>
  581. </tr>
  582. <tr>
  583. <th>Data pagamento:</th>
  584. <td id="recordPaymentDate"></td>
  585. </tr>
  586. <tr>
  587. <th>Fornitore:</th>
  588. <td id="recordSupplier"></td>
  589. </tr>
  590. <tr>
  591. <th>Metodo di pagamento:</th>
  592. <td id="recordPaymentMethod"></td>
  593. </tr>
  594. </table>
  595. </div>
  596. <div class="col-md-6">
  597. <h6 class="primary">Importo e pagamento</h6>
  598. <table class="table table-sm table-borderless">
  599. <tr>
  600. <th>Importo totale:</th>
  601. <td id="recordTotalAmount" class="primary fw-bold"></td>
  602. </tr>
  603. <tr>
  604. <th>Stato pagamento:</th>
  605. <td><span id="recordPaymentStatus" class="badge"></span></td>
  606. </tr>
  607. </table>
  608. </div>
  609. </div>
  610. <h6 class="primary">Dettaglio causali</h6>
  611. <div class="table-responsive">
  612. <table class="table table-striped table-hover">
  613. <thead>
  614. <tr>
  615. <th scope="col">N.</th>
  616. <th scope="col">Descrizione</th>
  617. <th scope="col">Imponibile</th>
  618. <th scope="col">IVA</th>
  619. <th scope="col">Imposta</th>
  620. <th scope="col">Totale</th>
  621. </tr>
  622. </thead>
  623. <tbody id="recordRowsContainer">
  624. </tbody>
  625. </table>
  626. </div>
  627. </div>
  628. <div class="modal-footer" style="background-color: #FFF!important;">
  629. <button type="button" class="btn--ui lightGrey" data-bs-dismiss="modal">Chiudi</button>
  630. </div>
  631. </div>
  632. </div>
  633. </div>
  634. <div id="loadingOverlay" class="loading-overlay" style="display: none;">
  635. <div class="loading-content">
  636. <div class="loading-spinner"></div>
  637. <div class="loading-text">Caricamento...</div>
  638. <div class="loading-progress">
  639. <div class="progress-bar-custom">
  640. <div class="progress-fill"></div>
  641. </div>
  642. <div class="progress-details mt-2">
  643. <small class="text-muted d-block loading-details"></small>
  644. </div>
  645. </div>
  646. </div>
  647. </div>
  648. </div>
  649. @push('scripts')
  650. <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  651. <style>
  652. table.tableHead thead {
  653. position: sticky;
  654. z-index: 100;
  655. top: 0;
  656. }
  657. .select2-container--default .select2-selection--single{
  658. background-color: #E9F0F5;
  659. border: 0.0625rem solid #DFE5EB;
  660. font-size: 0.75rem;
  661. }
  662. .select2-selection {
  663. height: 38px !important;
  664. }
  665. .select2-selection__rendered {
  666. padding-top:3px;
  667. }
  668. .select2 {
  669. width:100% !important;
  670. }
  671. .select2-selection--multiple{
  672. overflow: hidden !important;
  673. height: auto !important;
  674. }
  675. .file-upload-container {
  676. position: relative;
  677. }
  678. .file-drop-zone {
  679. transition: all 0.3s ease;
  680. cursor: pointer;
  681. }
  682. .file-drop-zone:hover {
  683. border-color: #0C6197 !important;
  684. background-color: #f0f8ff !important;
  685. transform: translateY(-2px);
  686. box-shadow: 0 4px 12px rgba(12, 97, 151, 0.15);
  687. }
  688. .file-drop-zone.dragover {
  689. border-color: #0C6197 !important;
  690. background-color: #e6f3ff !important;
  691. transform: scale(1.02);
  692. box-shadow: 0 8px 25px rgba(12, 97, 151, 0.25);
  693. }
  694. .file-input:focus + .file-drop-zone {
  695. border-color: #0C6197 !important;
  696. box-shadow: 0 0 0 0.25rem rgba(12, 97, 151, 0.25);
  697. }
  698. .file-requirements ul {
  699. list-style-type: none;
  700. padding-left: 1rem;
  701. }
  702. .file-requirements li:before {
  703. content: "•";
  704. color: #6c757d;
  705. margin-right: 0.5rem;
  706. }
  707. .loading-overlay {
  708. position: fixed;
  709. top: 0;
  710. left: 0;
  711. width: 100%;
  712. height: 100%;
  713. background: rgba(0, 0, 0, 0.8);
  714. display: flex;
  715. justify-content: center;
  716. align-items: center;
  717. z-index: 9999;
  718. backdrop-filter: blur(3px);
  719. }
  720. .loading-content {
  721. background: white;
  722. padding: 40px;
  723. border-radius: 15px;
  724. text-align: center;
  725. box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  726. min-width: 350px;
  727. max-width: 90vw;
  728. }
  729. .loading-spinner {
  730. width: 50px;
  731. height: 50px;
  732. border: 5px solid #f3f3f3;
  733. border-top: 5px solid #0C6197;
  734. border-radius: 50%;
  735. animation: spin 1s linear infinite;
  736. margin: 0 auto 25px;
  737. }
  738. @keyframes spin {
  739. 0% { transform: rotate(0deg); }
  740. 100% { transform: rotate(360deg); }
  741. }
  742. .loading-text {
  743. font-size: 18px;
  744. font-weight: 600;
  745. color: #333;
  746. margin-bottom: 20px;
  747. }
  748. .progress-bar-custom {
  749. width: 100%;
  750. height: 6px;
  751. background: #f0f0f0;
  752. border-radius: 3px;
  753. overflow: hidden;
  754. margin-bottom: 10px;
  755. }
  756. .progress-fill {
  757. height: 100%;
  758. background: linear-gradient(90deg, #0C6197, #1e7bb8, #0C6197);
  759. width: 0%;
  760. transition: width 0.5s ease;
  761. animation: progressShimmer 2s ease-in-out infinite;
  762. }
  763. @keyframes progressShimmer {
  764. 0%, 100% { opacity: 1; }
  765. 50% { opacity: 0.8; }
  766. }
  767. .loading-details {
  768. color: #666;
  769. font-size: 0.9em;
  770. min-height: 1.2em;
  771. }
  772. #upload-progress {
  773. background: #f8f9fa;
  774. border: 1px solid #dee2e6;
  775. border-radius: 8px;
  776. padding: 15px;
  777. }
  778. #upload-progress .progress {
  779. height: 10px;
  780. border-radius: 5px;
  781. overflow: hidden;
  782. }
  783. #upload-progress .progress-bar {
  784. transition: width 0.3s ease;
  785. }
  786. .upload-status {
  787. font-weight: 600;
  788. color: #0C6197;
  789. }
  790. .upload-percentage {
  791. font-weight: bold;
  792. color: #28a745;
  793. }
  794. .loading-active {
  795. pointer-events: none;
  796. opacity: 0.7;
  797. transition: opacity 0.3s ease;
  798. }
  799. .file-selected-info {
  800. border-left: 4px solid #28a745;
  801. background-color: #f8fff9;
  802. }
  803. .file-size-display {
  804. font-weight: 600;
  805. }
  806. @media (max-width: 768px) {
  807. .loading-content {
  808. padding: 30px 20px;
  809. min-width: 300px;
  810. }
  811. .file-drop-zone {
  812. min-height: 100px;
  813. padding: 20px 15px;
  814. }
  815. }
  816. @keyframes fileUploadSuccess {
  817. 0% { transform: scale(0.8); opacity: 0; }
  818. 50% { transform: scale(1.05); }
  819. 100% { transform: scale(1); opacity: 1; }
  820. }
  821. .file-selected-info {
  822. animation: fileUploadSuccess 0.5s ease-out;
  823. }
  824. </style>
  825. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  826. <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
  827. @endpush
  828. @push('scripts')
  829. <script>
  830. function matchStart(params, data) {
  831. params.term = params.term || '';
  832. if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
  833. return data;
  834. }
  835. return false;
  836. }
  837. function onlyNumberAmount(input) {
  838. let v = input.value.replace(/\D+/g, '');
  839. if (v.length > 14) v = v.slice(0, 14);
  840. input.value = "€ " + v.replace(/(\d)(\d\d)$/, "$1,$2").replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:,|$))/g, '$1.');
  841. }
  842. let selectedFileInfo = null;
  843. let fileUploadProgressInterval = null;
  844. function formatFileSize(bytes) {
  845. if (bytes === 0) return '0 Bytes';
  846. const k = 1024;
  847. const sizes = ['Bytes', 'KB', 'MB', 'GB'];
  848. const i = Math.floor(Math.log(bytes) / Math.log(k));
  849. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  850. }
  851. function getFileTypeDescription(mimeType) {
  852. const typeMap = {
  853. 'image/jpeg': 'Immagine JPEG',
  854. 'image/jpg': 'Immagine JPG',
  855. 'image/png': 'Immagine PNG',
  856. 'image/gif': 'Immagine GIF',
  857. 'application/pdf': 'Documento PDF',
  858. 'application/msword': 'Documento Word',
  859. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'Documento Word',
  860. 'text/xml': 'File XML',
  861. 'application/xml': 'File XML',
  862. 'text/plain': 'File di testo',
  863. 'text/csv': 'File CSV',
  864. 'application/vnd.ms-excel': 'File Excel',
  865. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'File Excel'
  866. };
  867. return typeMap[mimeType] || 'Documento';
  868. }
  869. function validateFile(file) {
  870. const maxSize = 50 * 1024 * 1024;
  871. if (file.size > maxSize) {
  872. alert('File troppo grande. Dimensione massima: 50MB');
  873. return false;
  874. }
  875. const allowedTypes = [
  876. 'image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp',
  877. 'application/pdf',
  878. 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  879. 'text/xml', 'application/xml', 'text/plain', 'text/csv',
  880. 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  881. ];
  882. if (!allowedTypes.includes(file.type)) {
  883. alert('Tipo di file non supportato. Formati consentiti: immagini, PDF, documenti Word, XML, TXT, CSV, Excel');
  884. return false;
  885. }
  886. return true;
  887. }
  888. function clearFileSelection() {
  889. const attachmentInput = document.getElementById('attachment');
  890. if (attachmentInput) {
  891. attachmentInput.value = '';
  892. }
  893. const fileInfo = document.querySelector('.file-selected-info');
  894. if (fileInfo) {
  895. fileInfo.remove();
  896. }
  897. selectedFileInfo = null;
  898. if (window.Livewire) {
  899. Livewire.first().set('attachment', null);
  900. }
  901. }
  902. function showLoading(message = 'Caricamento...', details = '') {
  903. const loadingOverlay = document.getElementById('loadingOverlay');
  904. const loadingText = loadingOverlay.querySelector('.loading-text');
  905. const loadingDetails = loadingOverlay.querySelector('.loading-details');
  906. const progressFill = loadingOverlay.querySelector('.progress-fill');
  907. const form = document.getElementById('accountingExit');
  908. if (loadingText) {
  909. loadingText.textContent = message;
  910. }
  911. if (loadingDetails) {
  912. loadingDetails.textContent = details;
  913. }
  914. if (progressFill) {
  915. progressFill.style.width = '0%';
  916. }
  917. if (form) {
  918. form.classList.add('loading-active');
  919. }
  920. loadingOverlay.style.display = 'flex';
  921. startProgressAnimation();
  922. }
  923. function showFileUploadLoading(fileName, fileSize) {
  924. const estimatedTime = Math.max(3, Math.floor(fileSize / (1024 * 1024)) * 2);
  925. const details = `File: ${fileName} (${formatFileSize(fileSize)})`;
  926. showLoading('Caricamento allegato in corso...', details);
  927. startFileUploadProgress(estimatedTime);
  928. }
  929. function updateLoading(message, details = '') {
  930. const loadingOverlay = document.getElementById('loadingOverlay');
  931. if (!loadingOverlay || loadingOverlay.style.display === 'none') return;
  932. const loadingText = loadingOverlay.querySelector('.loading-text');
  933. const loadingDetails = loadingOverlay.querySelector('.loading-details');
  934. const progressFill = loadingOverlay.querySelector('.progress-fill');
  935. if (loadingText) {
  936. loadingText.textContent = message;
  937. }
  938. if (loadingDetails && details) {
  939. loadingDetails.textContent = details;
  940. }
  941. // Increase progress
  942. if (progressFill) {
  943. const currentWidth = parseInt(progressFill.style.width) || 0;
  944. const newWidth = Math.min(currentWidth + 20, 90);
  945. progressFill.style.width = newWidth + '%';
  946. }
  947. }
  948. function hideLoading() {
  949. const loadingOverlay = document.getElementById('loadingOverlay');
  950. if (!loadingOverlay) return;
  951. const progressFill = loadingOverlay.querySelector('.progress-fill');
  952. const form = document.getElementById('accountingExit');
  953. if (progressFill) {
  954. progressFill.style.width = '100%';
  955. }
  956. setTimeout(() => {
  957. loadingOverlay.style.display = 'none';
  958. if (form) {
  959. form.classList.remove('loading-active');
  960. }
  961. if (fileUploadProgressInterval) {
  962. clearInterval(fileUploadProgressInterval);
  963. fileUploadProgressInterval = null;
  964. }
  965. }, 500);
  966. }
  967. function startProgressAnimation() {
  968. const progressFill = document.querySelector('#loadingOverlay .progress-fill');
  969. if (!progressFill) return;
  970. let progress = 0;
  971. const interval = setInterval(() => {
  972. if (progress < 15) {
  973. progress += 1;
  974. progressFill.style.width = progress + '%';
  975. }
  976. }, 200);
  977. window.baseProgressInterval = interval;
  978. }
  979. function startFileUploadProgress(estimatedSeconds) {
  980. const progressFill = document.querySelector('#loadingOverlay .progress-fill');
  981. if (!progressFill) return;
  982. let progress = 15;
  983. const increment = 75 / (estimatedSeconds * 10);
  984. fileUploadProgressInterval = setInterval(() => {
  985. if (progress < 90) {
  986. progress += increment;
  987. progressFill.style.width = Math.min(progress, 90) + '%';
  988. }
  989. }, 100);
  990. }
  991. function setupDragAndDrop() {
  992. const fileDropZone = document.getElementById('file-drop-zone');
  993. const fileInput = document.getElementById('attachment');
  994. if (!fileDropZone || !fileInput) return;
  995. ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
  996. fileDropZone.addEventListener(eventName, preventDefaults, false);
  997. document.body.addEventListener(eventName, preventDefaults, false);
  998. });
  999. ['dragenter', 'dragover'].forEach(eventName => {
  1000. fileDropZone.addEventListener(eventName, highlight, false);
  1001. });
  1002. ['dragleave', 'drop'].forEach(eventName => {
  1003. fileDropZone.addEventListener(eventName, unhighlight, false);
  1004. });
  1005. fileDropZone.addEventListener('drop', handleDrop, false);
  1006. function preventDefaults(e) {
  1007. e.preventDefault();
  1008. e.stopPropagation();
  1009. }
  1010. function highlight(e) {
  1011. fileDropZone.classList.add('dragover');
  1012. }
  1013. function unhighlight(e) {
  1014. fileDropZone.classList.remove('dragover');
  1015. }
  1016. function handleDrop(e) {
  1017. const dt = e.dataTransfer;
  1018. const files = dt.files;
  1019. if (files.length > 0) {
  1020. const file = files[0];
  1021. if (validateFile(file)) {
  1022. fileInput.files = files;
  1023. const event = new Event('change', { bubbles: true });
  1024. fileInput.dispatchEvent(event);
  1025. }
  1026. }
  1027. }
  1028. }
  1029. $(document).ready(function() {
  1030. setupDragAndDrop();
  1031. const attachmentInput = document.getElementById('attachment');
  1032. if (attachmentInput) {
  1033. attachmentInput.addEventListener('change', function(e) {
  1034. const file = e.target.files[0];
  1035. if (!file) return;
  1036. if (!validateFile(file)) {
  1037. e.target.value = '';
  1038. return;
  1039. }
  1040. selectedFileInfo = {
  1041. name: file.name,
  1042. size: file.size,
  1043. type: file.type
  1044. };
  1045. if (file.size > 10 * 1024 * 1024) {
  1046. const warning = document.createElement('div');
  1047. warning.className = 'alert alert-warning mt-2 large-file-warning';
  1048. warning.innerHTML = `
  1049. <i class="fa-solid fa-exclamation-triangle me-2"></i>
  1050. <strong>File di grandi dimensioni:</strong> ${file.name} (${formatFileSize(file.size)})
  1051. <br><small>Il caricamento richiederà tempo aggiuntivo. Assicurati di avere una connessione stabile.</small>
  1052. `;
  1053. const existingWarning = document.querySelector('.large-file-warning');
  1054. if (existingWarning) {
  1055. existingWarning.remove();
  1056. }
  1057. const container = attachmentInput.closest('.col-md-12');
  1058. container.appendChild(warning);
  1059. setTimeout(() => {
  1060. warning.remove();
  1061. }, 5000);
  1062. }
  1063. });
  1064. }
  1065. });
  1066. document.addEventListener('click', function(e) {
  1067. const target = e.target;
  1068. if ((target.textContent.includes('inserisci') || target.textContent.includes('salva')) &&
  1069. target.classList.contains('btn--ui')) {
  1070. const fileInput = document.getElementById('attachment');
  1071. const hasFile = fileInput && fileInput.files.length > 0;
  1072. if (hasFile && selectedFileInfo) {
  1073. setTimeout(() => {
  1074. showFileUploadLoading(selectedFileInfo.name, selectedFileInfo.size);
  1075. }, 100);
  1076. } else {
  1077. setTimeout(() => {
  1078. const action = target.textContent.includes('inserisci') ? 'Salvataggio' : 'Aggiornamento';
  1079. showLoading(action + ' in corso...');
  1080. }, 100);
  1081. }
  1082. }
  1083. });
  1084. window.livewire.on('refresh', () => {
  1085. $('.causalClass').select2({
  1086. matcher: function(params, data) {
  1087. return matchStart(params, data);
  1088. }
  1089. });
  1090. $('.supplierClass').select2({});
  1091. $('.paymentClass').select2({
  1092. matcher: function(params, data) {
  1093. return matchStart(params, data);
  1094. }
  1095. });
  1096. });
  1097. Livewire.on('load-select', () => {
  1098. $('.causalClass').each(function(i, obj) {
  1099. $(obj).select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  1100. $(obj).on('change', function (e) {
  1101. var data = $(obj).select2("val");
  1102. var name = $(obj).select2().attr("name");
  1103. @this.set(name, data);
  1104. });
  1105. });
  1106. $('.supplierClass').select2({});
  1107. $('.supplierClass').on('change', function (e) {
  1108. var data = $('.supplierClass').select2("val");
  1109. @this.set('supplier_id', data);
  1110. });
  1111. $('.paymentClass').select2({
  1112. matcher: function(params, data) {
  1113. return matchStart(params, data);
  1114. }
  1115. });
  1116. $('.paymentClass').on('change', function (e) {
  1117. var data = $('.paymentClass').select2("val");
  1118. @this.set('payment_method_id', data);
  1119. });
  1120. $('.filterSupplier').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  1121. $('.filterPaymentMethod').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  1122. $('.filterCausals').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  1123. setTimeout(setupDragAndDrop, 100);
  1124. });
  1125. Livewire.on('start-loading', message => {
  1126. showLoading(message);
  1127. });
  1128. Livewire.on('update-loading', message => {
  1129. updateLoading(message);
  1130. });
  1131. Livewire.on('stop-loading', () => {
  1132. hideLoading();
  1133. });
  1134. Livewire.on('flash-error', message => {
  1135. hideLoading();
  1136. const alert = document.createElement('div');
  1137. alert.classList.add('alert', 'alert-danger', 'alert-dismissible', 'fade', 'show');
  1138. alert.setAttribute('role', 'alert');
  1139. alert.innerHTML = `
  1140. <i class="fa-solid fa-exclamation-triangle me-2"></i>
  1141. ${message}
  1142. <button type="button" class="btn-close"`;
  1143. const accountingExit = document.getElementById('accountingExit');
  1144. if (accountingExit) {
  1145. accountingExit.prepend(alert);
  1146. } else {
  1147. const mainContainer = document.querySelector('.col.card--ui');
  1148. if (mainContainer) {
  1149. mainContainer.prepend(alert);
  1150. }
  1151. }
  1152. setTimeout(() => {
  1153. alert.remove();
  1154. }, 7000);
  1155. });
  1156. Livewire.on('hide-search', () => {
  1157. });
  1158. var isEdit = false;
  1159. Livewire.on('setEdit', (x) => {
  1160. isEdit = x;
  1161. });
  1162. function annulla() {
  1163. window.onbeforeunload = null;
  1164. document.location.href = '/out';
  1165. }
  1166. window.onbeforeunload = function() {
  1167. if (isEdit)
  1168. return 'Cambiando pagina le eventuali modifiche andranno perse';
  1169. };
  1170. function initImportCausalSelect() {
  1171. $('.import-causal-select').select2({
  1172. dropdownParent: $('#importModal'),
  1173. language: {
  1174. noResults: function() {
  1175. return "Nessun risultato";
  1176. }
  1177. }
  1178. });
  1179. $('.import-causal-select').on('change', function() {
  1180. let selectedValue = $(this).val();
  1181. Livewire.first().set('selectedCausal', selectedValue);
  1182. });
  1183. }
  1184. function openImportModal() {
  1185. let tableState = null;
  1186. if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
  1187. tableState = $('#tablesaw-350').DataTable().state.save();
  1188. }
  1189. const importModal = new bootstrap.Modal(document.getElementById('importModal'));
  1190. importModal.show();
  1191. setTimeout(function() {
  1192. initImportCausalSelect();
  1193. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1194. loadDataTable();
  1195. if (tableState) {
  1196. $('#tablesaw-350').DataTable().state.load(tableState);
  1197. }
  1198. }
  1199. }, 200);
  1200. }
  1201. function closeImportModal() {
  1202. const importModal = bootstrap.Modal.getInstance(document.getElementById('importModal'));
  1203. if (importModal) {
  1204. importModal.hide();
  1205. }
  1206. setTimeout(function() {
  1207. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1208. loadDataTable();
  1209. }
  1210. }, 100);
  1211. }
  1212. // IMPORT PROGRESS AND RESULTS
  1213. Livewire.on('update-progress', (progress) => {
  1214. const progressBar = document.querySelector('.progress-bar');
  1215. if (progressBar) {
  1216. progressBar.style.width = `${progress}%`;
  1217. progressBar.setAttribute('aria-valuenow', progress);
  1218. progressBar.textContent = `${Math.round(progress)}%`;
  1219. }
  1220. });
  1221. Livewire.on('import-started', () => {
  1222. const closeButton = document.querySelector('#importModal .btn-close');
  1223. const submitButton = document.querySelector('#importModal button[type="submit"]');
  1224. if (closeButton) closeButton.disabled = true;
  1225. if (submitButton) submitButton.disabled = true;
  1226. });
  1227. let transitioningToResultModal = false;
  1228. Livewire.on('show-import-result', data => {
  1229. transitioningToResultModal = true;
  1230. const resultDiv = document.getElementById('importResultMessage');
  1231. resultDiv.innerHTML = data.message;
  1232. const importModal = bootstrap.Modal.getInstance(document.getElementById('importModal'));
  1233. if (importModal) {
  1234. importModal.hide();
  1235. }
  1236. setTimeout(() => {
  1237. const resultModal = new bootstrap.Modal(document.getElementById('importResultModal'));
  1238. resultModal.show();
  1239. }, 300);
  1240. });
  1241. document.getElementById('importModal').addEventListener('hidden.bs.modal', function () {
  1242. if (!transitioningToResultModal) {
  1243. setTimeout(function() {
  1244. window.location.reload();
  1245. }, 500);
  1246. } else {
  1247. transitioningToResultModal = false;
  1248. }
  1249. });
  1250. document.getElementById('importResultModal').addEventListener('hidden.bs.modal', function () {
  1251. window.location.reload();
  1252. });
  1253. function calculateAmount(rowIndex) {
  1254. const imponibileField = document.getElementById(`rows.${rowIndex}.imponibile`);
  1255. const aliquotaField = document.getElementById(`rows.${rowIndex}.aliquota_iva`);
  1256. const amountField = document.getElementById(`rows.${rowIndex}.amount`);
  1257. if (imponibileField && aliquotaField && amountField) {
  1258. let imponibile = imponibileField.value.replace('€', '').replace(/\./g, '').replace(',', '.').trim();
  1259. imponibile = parseFloat(imponibile) || 0;
  1260. let aliquota = parseFloat(aliquotaField.value) || 0;
  1261. const imposta = imponibile * (aliquota / 100);
  1262. const totalAmount = imponibile + imposta;
  1263. let formattedAmount = "€ " + totalAmount.toFixed(2).replace('.', ',').replace(/\B(?=(\d{3})+(?!\d))/g, ".");
  1264. amountField.value = formattedAmount;
  1265. const component = Livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id'));
  1266. if (component) {
  1267. component.set(`rows.${rowIndex}.amount`, formattedAmount);
  1268. }
  1269. }
  1270. }
  1271. function setupCalculationListeners() {
  1272. const rows = document.querySelectorAll('input[id^="rows."][id$=".imponibile"], select[id^="rows."][id$=".aliquota_iva"]');
  1273. rows.forEach(field => {
  1274. field.addEventListener('blur', function() {
  1275. const match = this.id.match(/rows\.(\d+)\./);
  1276. if (match) {
  1277. const rowIndex = match[1];
  1278. calculateAmount(rowIndex);
  1279. }
  1280. });
  1281. field.addEventListener('change', function() {
  1282. const match = this.id.match(/rows\.(\d+)\./);
  1283. if (match) {
  1284. const rowIndex = match[1];
  1285. calculateAmount(rowIndex);
  1286. }
  1287. });
  1288. });
  1289. }
  1290. document.addEventListener('livewire:load', setupCalculationListeners);
  1291. document.addEventListener('livewire:update', setupCalculationListeners);
  1292. Livewire.on('load-select', function() {
  1293. setTimeout(setupCalculationListeners, 300);
  1294. });
  1295. function viewData(id) {
  1296. Livewire.first().viewData(id);
  1297. setTimeout(function() {
  1298. const modalElement = document.getElementById('recordDetailsModal');
  1299. if (modalElement) {
  1300. const modal = new bootstrap.Modal(modalElement);
  1301. modal.show();
  1302. modalElement.addEventListener('hidden.bs.modal', function() {
  1303. setTimeout(function() {
  1304. window.location.reload();
  1305. }, 100);
  1306. });
  1307. }
  1308. }, 300);
  1309. }
  1310. window.addEventListener('show-record-details', function(event) {
  1311. showRecordDetailsModal(event.detail.record);
  1312. });
  1313. function showRecordDetailsModal(record) {
  1314. const modalElement = document.getElementById('recordDetailsModal');
  1315. if (!modalElement) return;
  1316. try {
  1317. let recordDetailsModal = new bootstrap.Modal(modalElement);
  1318. document.getElementById('recordDate').textContent = record.formatted_date || 'N/A';
  1319. document.getElementById('recordPaymentDate').textContent = record.formatted_data_pagamento || 'N/A';
  1320. document.getElementById('recordSupplier').textContent = record.supplier_name || 'N/A';
  1321. document.getElementById('recordPaymentMethod').textContent = record.payment_method_name || 'N/A';
  1322. document.getElementById('recordTotalAmount').textContent = record.formatted_amount || 'N/A';
  1323. const paymentStatusElement = document.getElementById('recordPaymentStatus');
  1324. if (paymentStatusElement) {
  1325. paymentStatusElement.textContent = record.payment_status || 'N/A';
  1326. paymentStatusElement.className = 'badge ' + (record.is_paid ? 'bg-success' : 'bg-warning');
  1327. }
  1328. const rowsContainer = document.getElementById('recordRowsContainer');
  1329. if (rowsContainer) {
  1330. rowsContainer.innerHTML = '';
  1331. if (record.rows && record.rows.length > 0) {
  1332. record.rows.forEach(function(row, index) {
  1333. const tr = document.createElement('tr');
  1334. tr.innerHTML = `
  1335. <td>${index + 1}</td>
  1336. <td>${row.note && row.note.trim() !== '' ? row.note : (row.causal_name || 'N/A')}</td>
  1337. <td>${row.formatted_imponibile || 'N/A'}</td>
  1338. <td>${row.aliquota_iva ? row.aliquota_iva + '%' : '-'}</td>
  1339. <td>${row.formatted_imposta || 'N/A'}</td>
  1340. <td class="fw-bold">${row.formatted_amount || 'N/A'}</td>
  1341. `;
  1342. rowsContainer.appendChild(tr);
  1343. });
  1344. } else {
  1345. const tr = document.createElement('tr');
  1346. tr.innerHTML = '<td colspan="6" class="text-center">Nessuna riga disponibile</td>';
  1347. rowsContainer.appendChild(tr);
  1348. }
  1349. }
  1350. recordDetailsModal.show();
  1351. } catch (error) {
  1352. console.error('Error displaying modal:', error);
  1353. }
  1354. }
  1355. window.addEventListener('beforeunload', function() {
  1356. hideLoading();
  1357. if (fileUploadProgressInterval) {
  1358. clearInterval(fileUploadProgressInterval);
  1359. }
  1360. if (window.baseProgressInterval) {
  1361. clearInterval(window.baseProgressInterval);
  1362. }
  1363. });
  1364. </script>
  1365. <link href="/css/datatables.css" rel="stylesheet" />
  1366. <script src="/assets/js/datatables.js"></script>
  1367. <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
  1368. <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
  1369. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
  1370. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
  1371. <script>
  1372. $(document).ready(function() {
  1373. loadDataTable();
  1374. });
  1375. @if(isset($_GET["showFilters"]))
  1376. var filterSupplier = localStorage.getItem("filterSupplierRecordOut");
  1377. if (filterSupplier && filterSupplier != "null" && filterSupplier != "undefined") {
  1378. $('.filterSupplier').val(filterSupplier);
  1379. $('.filterSupplier').trigger('change');
  1380. }
  1381. var filterPaymentMethod = localStorage.getItem("filterPaymentMethodRecordOut");
  1382. if (filterPaymentMethod && filterPaymentMethod != "null" && filterPaymentMethod != "undefined") {
  1383. $('.filterPaymentMethod').val(filterPaymentMethod);
  1384. $('.filterPaymentMethod').trigger('change');
  1385. }
  1386. var filterCausals = localStorage.getItem("filterCausalsRecordOut");
  1387. if (filterCausals && filterCausals != "null" && filterCausals != "undefined") {
  1388. $('.filterCausals').val(filterCausals);
  1389. $('.filterCausals').trigger('change');
  1390. }
  1391. var filterFrom = localStorage.getItem("filterFromRecordOut");
  1392. if (filterFrom && filterFrom != "" && filterFrom != "undefined") {
  1393. $('.filterFrom').val(filterFrom);
  1394. }
  1395. var filterTo = localStorage.getItem("filterToRecordOut");
  1396. if (filterTo && filterTo != "" && filterTo != "undefined") {
  1397. $('.filterTo').val(filterTo);
  1398. }
  1399. @endif
  1400. var isFilter = false;
  1401. $(document).ready(function() {
  1402. $(document).on("click",".showHideFilter",function() {
  1403. if (isFilter) {
  1404. isFilter = false;
  1405. $(".showFilter").hide();
  1406. } else {
  1407. isFilter = true;
  1408. $(".showFilter").show();
  1409. }
  1410. });
  1411. $(document).on("select2:open",".filterCausals",function() {
  1412. setTimeout(() => {
  1413. $(".select2-results__option").each(function(){
  1414. var txt = $(this).html();
  1415. var count = (txt.match(/-/g) || []).length;
  1416. $(this).addClass('paddingLeftSelect' + count);
  1417. });
  1418. }, 100);
  1419. });
  1420. $(document).on("click",".addData",function() {
  1421. $(".title--section_addButton").trigger("click")
  1422. });
  1423. });
  1424. function editData(id) {
  1425. @this.edit(id);
  1426. }
  1427. function deleteData(id) {
  1428. if (confirm('Sei sicuro?'))
  1429. @this.delete(id).then(() => {
  1430. window.location.reload();
  1431. });
  1432. }
  1433. Livewire.on('load-data-table', () => {
  1434. setTimeout(function() { loadDataTable() }, 100);
  1435. });
  1436. Livewire.on('destroy-data-table', () => {
  1437. $('#tablesaw-350').DataTable().destroy();
  1438. });
  1439. function destroyDataTable() {
  1440. $('#tablesaw-350').DataTable().destroy();
  1441. }
  1442. function reset() {
  1443. $(".todayButton").addClass("lightGrey");
  1444. $(".yesterdayButton").addClass("lightGrey");
  1445. $('.filterSupplier').val('');
  1446. $('.filterSupplier').trigger('change');
  1447. $('.filterPaymentMethod').val('');
  1448. $('.filterPaymentMethod').trigger('change');
  1449. $('.filterCausals').val('');
  1450. $('.filterCausals').trigger('change');
  1451. $('.filterFrom').val('');
  1452. $('.filterTo').val('');
  1453. localStorage.clear();
  1454. loadDataTable();
  1455. }
  1456. function loadDataTable() {
  1457. if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
  1458. $('#tablesaw-350').DataTable().destroy();
  1459. }
  1460. var filterSupplier = $('.filterSupplier').val();
  1461. var filterPaymentMethod = $('.filterPaymentMethod').val();
  1462. var filterCausals = $('.filterCausals').val();
  1463. var filterFrom = $('.filterFrom').val();
  1464. var filterTo = $('.filterTo').val();
  1465. localStorage.setItem("filterSupplierRecordOut", filterSupplier);
  1466. localStorage.setItem("filterPaymentMethodRecordOut", filterPaymentMethod);
  1467. localStorage.setItem("filterCausalsRecordOut", filterCausals);
  1468. localStorage.setItem("filterFromRecordOut", filterFrom);
  1469. localStorage.setItem("filterToRecordOut", filterTo);
  1470. $('#tablesaw-350').DataTable({
  1471. ajax: {
  1472. url : "/get_record_out?filterSupplier=" + filterSupplier + "&filterPaymentMethod=" + filterPaymentMethod + "&filterCausals=" + filterCausals + "&filterFrom=" + filterFrom + "&filterTo=" + filterTo,
  1473. dataSrc: function (json){
  1474. if(json.totals){
  1475. $(".totalDiv").html('Totale&nbsp;:&nbsp;<b>' + json.totals + '</b>');
  1476. } else {
  1477. $(".totalDiv").html('');
  1478. }
  1479. @if(Auth::user()->level != 0)
  1480. $(".totalDiv").html('');
  1481. @endif
  1482. return json.data;
  1483. }
  1484. },
  1485. columns: [
  1486. { data: 'numero_fattura' },
  1487. {
  1488. data: "date",
  1489. render: function (data, type){
  1490. if (data == "") return " TOTALE";
  1491. if (type == "sort"){
  1492. return new Date(data).getTime();
  1493. }
  1494. const j = data.split(" ");
  1495. const d = j[0].split("-");
  1496. var ret = d[2] + "/" + d[1] + "/" + d[0];
  1497. return ret;
  1498. }
  1499. },
  1500. { data: 'total', className: "numericCol" },
  1501. { data: 'supplier' },
  1502. { data: 'causals' },
  1503. { data: 'payment' },
  1504. {
  1505. data: 'is_paid',
  1506. render: function (data) {
  1507. if (data === true || data === 'true' || data === 1 || data === '1' || data === 'Pagato') {
  1508. return '<span class="badge bg-success">Pagato</span>';
  1509. } else {
  1510. return '<span class="badge bg-warning">Da Pagare</span>';
  1511. }
  1512. }
  1513. },
  1514. {
  1515. data: "action",
  1516. render: function (data){
  1517. if (data == "") return "";
  1518. const j = data.split("|");
  1519. var ret = '<button type="button" class="btn" onclick="editData(' + j[0] + ')" 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>&nbsp;';
  1520. ret += '<button type="button" class="btn" onclick="viewData(' + j[0] + ')" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Info"><i class="fa-regular fa-eye"></i></button>&nbsp;';
  1521. ret += '<button type="button" class="btn" onclick="deleteData(' + j[0] + ')" 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>';
  1522. return ret;
  1523. }
  1524. },
  1525. ],
  1526. order: [[1, 'desc']],
  1527. thead: {
  1528. 'th': {'background-color': 'blue'}
  1529. },
  1530. layout: {
  1531. topStart : null,
  1532. topEnd : null,
  1533. top1A: {
  1534. buttons: [
  1535. {
  1536. extend: 'collection',
  1537. text: 'ESPORTA',
  1538. buttons: [
  1539. {
  1540. extend: 'excelHtml5',"action":newexportaction,
  1541. title: 'Uscite',
  1542. exportOptions: {
  1543. columns: ":not(':last')"
  1544. }
  1545. },
  1546. {
  1547. extend: 'pdfHtml5',"action":newexportaction,
  1548. title: 'Uscite',
  1549. exportOptions: {
  1550. columns: ":not(':last')"
  1551. }
  1552. },
  1553. {
  1554. extend: 'print',"action":newexportaction,
  1555. text: 'Stampa',
  1556. title: 'Uscite',
  1557. exportOptions: {
  1558. columns: ":not(':last')"
  1559. }
  1560. }
  1561. ],
  1562. dropup: true
  1563. }
  1564. ]
  1565. },
  1566. top1B : {
  1567. pageLength: {
  1568. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  1569. }
  1570. },
  1571. top1C :'search',
  1572. },
  1573. pagingType: 'numbers',
  1574. "language": {
  1575. "url": "/assets/js/Italian.json"
  1576. },
  1577. "fnInitComplete": function (oSettings, json) {
  1578. var html = '&nbsp;<a href="#" class="showHideFilter btn--ui"><i class="fa-solid fa-sliders"></i></a>';
  1579. html += '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  1580. $(".dt-search").append(html);
  1581. }
  1582. });
  1583. $('#tablesaw-350 thead tr th').addClass('col');
  1584. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  1585. $('#tablesaw-350').on('draw.dt', function() {
  1586. $('[data-bs-toggle="popover"]').popover()
  1587. });
  1588. }
  1589. document.addEventListener('livewire:initialized', () => {
  1590. let importModalOpen = false;
  1591. const importModal = document.getElementById('importModal');
  1592. importModal.addEventListener('shown.bs.modal', function () {
  1593. importModalOpen = true;
  1594. });
  1595. importModal.addEventListener('hidden.bs.modal', function () {
  1596. importModalOpen = false;
  1597. setTimeout(() => {
  1598. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1599. loadDataTable();
  1600. }
  1601. }, 100);
  1602. });
  1603. document.addEventListener('livewire:update', function() {
  1604. if (importModalOpen) {
  1605. const modalInstance = bootstrap.Modal.getInstance(importModal);
  1606. if (!modalInstance) {
  1607. const newModal = new bootstrap.Modal(importModal);
  1608. newModal.show();
  1609. } else if (!importModal.classList.contains('show')) {
  1610. modalInstance.show();
  1611. }
  1612. setTimeout(() => {
  1613. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1614. loadDataTable();
  1615. }
  1616. }, 100);
  1617. }
  1618. });
  1619. document.querySelectorAll('.select2-container').forEach(select => {
  1620. select.addEventListener('click', function(e) {
  1621. e.stopPropagation();
  1622. });
  1623. });
  1624. });
  1625. document.addEventListener('DOMContentLoaded', function() {
  1626. if (document.getElementById('importModal')) {
  1627. initImportCausalSelect();
  1628. }
  1629. Livewire.on('load-select', function() {
  1630. if (document.getElementById('importModal') &&
  1631. document.getElementById('importModal').classList.contains('show')) {
  1632. initImportCausalSelect();
  1633. }
  1634. });
  1635. setupCalculationListeners();
  1636. setupDragAndDrop();
  1637. const recordDetailsModal = document.getElementById('recordDetailsModal');
  1638. if (recordDetailsModal) {
  1639. recordDetailsModal.addEventListener('hidden.bs.modal', function() {
  1640. setTimeout(function() {
  1641. window.location.reload();
  1642. }, 100);
  1643. });
  1644. }
  1645. });
  1646. function pollAttachmentStatus(recordId) {
  1647. const pollInterval = setInterval(function() {
  1648. fetch(`/check-attachment-status/${recordId}`)
  1649. .then(response => response.json())
  1650. .then(data => {
  1651. if (data.status === 'completed') {
  1652. clearInterval(pollInterval);
  1653. showSuccess('Allegato caricato con successo!');
  1654. } else if (data.status === 'failed') {
  1655. clearInterval(pollInterval);
  1656. showError('Caricamento allegato fallito');
  1657. }
  1658. });
  1659. }, 2000);
  1660. setTimeout(() => clearInterval(pollInterval), 300000);
  1661. }
  1662. </script>
  1663. @endpush