records_out.blade.php 98 KB

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