records_out.blade.php 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159
  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. let date = new Date();
  1581. let date_export = `${date.getFullYear()}${date.getMonth()}${date.getDate()}_`;
  1582. $('#tablesaw-350').DataTable({
  1583. ajax: {
  1584. url : "/get_record_out?filterSupplier=" + filterSupplier + "&filterPaymentMethod=" + filterPaymentMethod + "&filterCausals=" + filterCausals + "&filterFrom=" + filterFrom + "&filterTo=" + filterTo,
  1585. dataSrc: function (json){
  1586. if(json.totals){
  1587. $(".totalDiv").html('Totale&nbsp;:&nbsp;<b>' + json.totals + '</b>');
  1588. } else {
  1589. $(".totalDiv").html('');
  1590. }
  1591. @if(Auth::user()->level != 0)
  1592. $(".totalDiv").html('');
  1593. @endif
  1594. return json.data;
  1595. }
  1596. },
  1597. columns: [
  1598. { data: 'numero_fattura' },
  1599. {
  1600. data: "date",
  1601. render: function (data, type){
  1602. if (data == "") return " TOTALE";
  1603. if (type == "sort"){
  1604. return new Date(data).getTime();
  1605. }
  1606. const j = data.split(" ");
  1607. const d = j[0].split("-");
  1608. var ret = d[2] + "/" + d[1] + "/" + d[0];
  1609. return ret;
  1610. }
  1611. },
  1612. { data: 'total', className: "numericCol" },
  1613. { data: 'supplier' },
  1614. { data: 'causals' },
  1615. { data: 'payment' },
  1616. {
  1617. data: 'is_paid',
  1618. render: function (data) {
  1619. if (data === true || data === 'true' || data === 1 || data === '1' || data === 'Pagato') {
  1620. return '<span class="badge bg-success">Pagato</span>';
  1621. } else {
  1622. return '<span class="badge bg-warning">Da Pagare</span>';
  1623. }
  1624. }
  1625. },
  1626. {
  1627. data: "action",
  1628. render: function (data){
  1629. if (data == "") return "";
  1630. const j = data.split("|");
  1631. 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;';
  1632. 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;';
  1633. 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>';
  1634. return ret;
  1635. }
  1636. },
  1637. ],
  1638. order: [[1, 'desc']],
  1639. thead: {
  1640. 'th': {'background-color': 'blue'}
  1641. },
  1642. layout: {
  1643. topStart : null,
  1644. topEnd : null,
  1645. top1A: {
  1646. // buttons: [
  1647. // {
  1648. // extend: 'collection',
  1649. // text: 'ESPORTA',
  1650. buttons: [
  1651. {
  1652. extend: 'excelHtml5',
  1653. text: '<i class="fa-solid fa-file-excel"></i>',
  1654. action: newexportaction,
  1655. title: date_export + 'Uscite',
  1656. exportOptions: {
  1657. columns: ":not(':last')"
  1658. },
  1659. exportLeftCols: [0]
  1660. },
  1661. {
  1662. extend: 'pdfHtml5',
  1663. text: '<i class="fa-solid fa-file-pdf"></i>',
  1664. action: newexportaction,
  1665. title: date_export + 'Uscite',
  1666. exportOptions: {
  1667. columns: ":not(':last')"
  1668. }
  1669. },
  1670. {
  1671. extend: 'print',
  1672. action: newexportaction,
  1673. text: '<i class="fa-solid fa-print"></i>',
  1674. title: date_export + 'Uscite',
  1675. exportOptions: {
  1676. columns: ":not(':last')"
  1677. }
  1678. }
  1679. ],
  1680. // dropup: true
  1681. // }
  1682. // ]
  1683. },
  1684. top1B : {
  1685. pageLength: {
  1686. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  1687. }
  1688. },
  1689. top1C :'search',
  1690. },
  1691. pagingType: 'numbers',
  1692. "language": {
  1693. "url": "/assets/js/Italian.json"
  1694. },
  1695. "fnInitComplete": function (oSettings, json) {
  1696. var html = '&nbsp;<a href="#" class="showHideFilter btn--ui"><i class="fa-solid fa-sliders"></i></a>';
  1697. html += '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  1698. $(".dt-search").append(html);
  1699. }
  1700. });
  1701. $('#tablesaw-350 thead tr th').addClass('col');
  1702. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  1703. $('#tablesaw-350').on('draw.dt', function() {
  1704. $('[data-bs-toggle="popover"]').popover()
  1705. });
  1706. }
  1707. document.addEventListener('livewire:initialized', () => {
  1708. let importModalOpen = false;
  1709. const importModal = document.getElementById('importModal');
  1710. importModal.addEventListener('shown.bs.modal', function () {
  1711. importModalOpen = true;
  1712. });
  1713. importModal.addEventListener('hidden.bs.modal', function () {
  1714. importModalOpen = false;
  1715. setTimeout(() => {
  1716. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1717. loadDataTable();
  1718. }
  1719. }, 100);
  1720. });
  1721. document.addEventListener('livewire:update', function() {
  1722. if (importModalOpen) {
  1723. const modalInstance = bootstrap.Modal.getInstance(importModal);
  1724. if (!modalInstance) {
  1725. const newModal = new bootstrap.Modal(importModal);
  1726. newModal.show();
  1727. } else if (!importModal.classList.contains('show')) {
  1728. modalInstance.show();
  1729. }
  1730. setTimeout(() => {
  1731. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1732. loadDataTable();
  1733. }
  1734. }, 100);
  1735. }
  1736. });
  1737. document.querySelectorAll('.select2-container').forEach(select => {
  1738. select.addEventListener('click', function(e) {
  1739. e.stopPropagation();
  1740. });
  1741. });
  1742. });
  1743. document.addEventListener('DOMContentLoaded', function() {
  1744. if (document.getElementById('importModal')) {
  1745. initImportCausalSelect();
  1746. }
  1747. Livewire.on('load-select', function() {
  1748. if (document.getElementById('importModal') &&
  1749. document.getElementById('importModal').classList.contains('show')) {
  1750. initImportCausalSelect();
  1751. }
  1752. });
  1753. setupCalculationListeners();
  1754. setupDragAndDrop();
  1755. const recordDetailsModal = document.getElementById('recordDetailsModal');
  1756. if (recordDetailsModal) {
  1757. recordDetailsModal.addEventListener('hidden.bs.modal', function() {
  1758. setTimeout(function() {
  1759. window.location.reload();
  1760. }, 100);
  1761. });
  1762. }
  1763. });
  1764. function pollAttachmentStatus(recordId) {
  1765. const pollInterval = setInterval(function() {
  1766. fetch(`/check-attachment-status/${recordId}`)
  1767. .then(response => response.json())
  1768. .then(data => {
  1769. if (data.status === 'completed') {
  1770. clearInterval(pollInterval);
  1771. showSuccess('Allegato caricato con successo!');
  1772. } else if (data.status === 'failed') {
  1773. clearInterval(pollInterval);
  1774. showError('Caricamento allegato fallito');
  1775. }
  1776. });
  1777. }, 2000);
  1778. setTimeout(() => clearInterval(pollInterval), 300000);
  1779. }
  1780. function showRecordDetailsModal(record) {
  1781. const modalElement = document.getElementById('recordDetailsModal');
  1782. if (!modalElement) return;
  1783. try {
  1784. let recordDetailsModal = new bootstrap.Modal(modalElement);
  1785. document.getElementById('recordDate').textContent = record.formatted_date || 'N/A';
  1786. document.getElementById('recordPaymentDate').textContent = record.formatted_data_pagamento || 'N/A';
  1787. document.getElementById('recordSupplier').textContent = record.supplier_name || 'N/A';
  1788. document.getElementById('recordPaymentMethod').textContent = record.payment_method_name || 'N/A';
  1789. document.getElementById('recordTotalAmount').textContent = record.formatted_amount || 'N/A';
  1790. const paymentStatusElement = document.getElementById('recordPaymentStatus');
  1791. if (paymentStatusElement) {
  1792. paymentStatusElement.textContent = record.payment_status || 'N/A';
  1793. paymentStatusElement.className = 'badge ' + (record.is_paid ? 'bg-success' : 'bg-warning');
  1794. }
  1795. const attachmentPresentDiv = document.getElementById('recordAttachmentPresent');
  1796. const attachmentMissingDiv = document.getElementById('recordAttachmentMissing');
  1797. const attachmentLink = document.getElementById('recordAttachmentLink');
  1798. const attachmentName = document.getElementById('recordAttachmentName');
  1799. if (record.attachment && record.attachment_url) {
  1800. attachmentPresentDiv.style.display = 'block';
  1801. attachmentMissingDiv.style.display = 'none';
  1802. // Configura il link per l'allegato
  1803. attachmentLink.href = record.attachment_url;
  1804. // Estrai il nome del file dal percorso
  1805. let fileName = record.attachment;
  1806. if (fileName.includes('/')) {
  1807. fileName = fileName.split('/').pop();
  1808. }
  1809. if (fileName.includes('\\')) {
  1810. fileName = fileName.split('\\').pop();
  1811. }
  1812. // Se il nome è troppo lungo, troncalo
  1813. if (fileName.length > 30) {
  1814. const extension = fileName.substring(fileName.lastIndexOf('.'));
  1815. const baseName = fileName.substring(0, fileName.lastIndexOf('.'));
  1816. fileName = baseName.substring(0, 25) + '...' + extension;
  1817. }
  1818. attachmentName.textContent = fileName;
  1819. // Aggiorna l'icona in base al tipo di file
  1820. const iconElement = attachmentPresentDiv.querySelector('i.fa-file-pdf');
  1821. if (fileName.toLowerCase().includes('.pdf')) {
  1822. iconElement.className = 'fa-solid fa-file-pdf me-2 text-danger';
  1823. } else if (fileName.toLowerCase().includes('.xml')) {
  1824. iconElement.className = 'fa-solid fa-file-code me-2 text-info';
  1825. } else if (fileName.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)) {
  1826. iconElement.className = 'fa-solid fa-file-image me-2 text-success';
  1827. } else if (fileName.toLowerCase().match(/\.(doc|docx)$/)) {
  1828. iconElement.className = 'fa-solid fa-file-word me-2 text-primary';
  1829. } else if (fileName.toLowerCase().match(/\.(xls|xlsx|csv)$/)) {
  1830. iconElement.className = 'fa-solid fa-file-excel me-2 text-success';
  1831. } else {
  1832. iconElement.className = 'fa-solid fa-file me-2 text-secondary';
  1833. }
  1834. } else {
  1835. // Mostra la sezione senza allegato
  1836. attachmentPresentDiv.style.display = 'none';
  1837. attachmentMissingDiv.style.display = 'block';
  1838. }
  1839. // Popola le righe come prima
  1840. const rowsContainer = document.getElementById('recordRowsContainer');
  1841. if (rowsContainer) {
  1842. rowsContainer.innerHTML = '';
  1843. if (record.rows && record.rows.length > 0) {
  1844. record.rows.forEach(function(row, index) {
  1845. const tr = document.createElement('tr');
  1846. tr.innerHTML = `
  1847. <td>${index + 1}</td>
  1848. <td>${row.note && row.note.trim() !== '' ? row.note : (row.causal_name || 'N/A')}</td>
  1849. <td>${row.formatted_imponibile || 'N/A'}</td>
  1850. <td>${row.aliquota_iva ? row.aliquota_iva + '%' : '-'}</td>
  1851. <td>${row.formatted_imposta || 'N/A'}</td>
  1852. <td class="fw-bold">${row.formatted_amount || 'N/A'}</td>
  1853. `;
  1854. rowsContainer.appendChild(tr);
  1855. });
  1856. } else {
  1857. const tr = document.createElement('tr');
  1858. tr.innerHTML = '<td colspan="6" class="text-center">Nessuna riga disponibile</td>';
  1859. rowsContainer.appendChild(tr);
  1860. }
  1861. }
  1862. recordDetailsModal.show();
  1863. } catch (error) {
  1864. console.error('Error displaying modal:', error);
  1865. }
  1866. }
  1867. // Aggiungere questo listener per gestire i cambi di stato del campo commercial
  1868. document.addEventListener('livewire:load', function() {
  1869. // Listener per il cambio del radio button commerciale/non commerciale
  1870. const commercialRadios = document.querySelectorAll('input[name="commercial"]');
  1871. commercialRadios.forEach(radio => {
  1872. radio.addEventListener('change', function() {
  1873. console.log('Commercial value changed to:', this.value);
  1874. // Il campo numero fattura sarà nascosto/mostrato automaticamente da Livewire
  1875. });
  1876. });
  1877. });
  1878. // Listener per gli aggiornamenti di Livewire
  1879. document.addEventListener('livewire:update', function() {
  1880. // Re-attach listeners dopo gli aggiornamenti di Livewire
  1881. const commercialRadios = document.querySelectorAll('input[name="commercial"]');
  1882. commercialRadios.forEach(radio => {
  1883. radio.addEventListener('change', function() {
  1884. console.log('Commercial value changed to:', this.value);
  1885. });
  1886. });
  1887. });
  1888. </script>
  1889. @endpush