records_out.blade.php 102 KB

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