records_out.blade.php 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. <div class="col card--ui" id="card--dashboard">
  2. <header id="title--section" style="display:none !important" class="d-flex align-items-center justify-content-between">
  3. <div class="title--section_name d-flex align-items-center justify-content-between">
  4. <i class="ico--ui title_section uscite me-2"></i>
  5. <h2 class="primary" >@if(!$add && !$update)Uscite @else Inserimento/modifica uscita @endif</h2>
  6. </div>
  7. @if(!$add && !$update)
  8. <div class="title--section_addButton" wire:click="add()" style="cursor: pointer;">
  9. <div class="btn--ui entrata d-flex justify-items-between">
  10. <a href="#" wire:click="add()" style="color:white">Aggiungi</a>
  11. </div>
  12. </div>
  13. @endif
  14. </header>
  15. @if(!$add && !$update)
  16. <div class="title--section_addButton d-flex justify-content-end">
  17. <button type="button" class="btn--ui entrata"
  18. wire:click="openImportModal" onclick="openImportModal()">
  19. Importa
  20. </button>
  21. </div>
  22. <div class="modal fade" id="importModal" tabindex="-1" aria-labelledby="importModalLabel" aria-hidden="true"
  23. wire:ignore.self>
  24. <div class="modal-dialog">
  25. <div class="modal-content">
  26. <div class="modal-header" style="background-color: var(--color-blu)!important;">
  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" :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" style="background-color: var(--color-blu)!important;">
  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" style="background-color: var(--color-blu)!important;">
  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. Livewire.on('start-loading', message => {
  1233. showLoading(message);
  1234. });
  1235. Livewire.on('update-loading', message => {
  1236. updateLoading(message);
  1237. });
  1238. Livewire.on('stop-loading', () => {
  1239. hideLoading();
  1240. });
  1241. Livewire.on('flash-error', message => {
  1242. hideLoading();
  1243. const alert = document.createElement('div');
  1244. alert.classList.add('alert', 'alert-danger', 'alert-dismissible', 'fade', 'show');
  1245. alert.setAttribute('role', 'alert');
  1246. alert.innerHTML = `
  1247. <i class="fa-solid fa-exclamation-triangle me-2"></i>
  1248. ${message}
  1249. <button type="button" class="btn-close"`;
  1250. const accountingExit = document.getElementById('accountingExit');
  1251. if (accountingExit) {
  1252. accountingExit.prepend(alert);
  1253. } else {
  1254. const mainContainer = document.querySelector('.col.card--ui');
  1255. if (mainContainer) {
  1256. mainContainer.prepend(alert);
  1257. }
  1258. }
  1259. setTimeout(() => {
  1260. alert.remove();
  1261. }, 7000);
  1262. });
  1263. Livewire.on('hide-search', () => {
  1264. });
  1265. var isEdit = false;
  1266. Livewire.on('setEdit', (x) => {
  1267. isEdit = x;
  1268. });
  1269. function annulla() {
  1270. window.onbeforeunload = null;
  1271. document.location.href = '/out';
  1272. }
  1273. window.onbeforeunload = function() {
  1274. if (isEdit)
  1275. return 'Cambiando pagina le eventuali modifiche andranno perse';
  1276. };
  1277. function initImportCausalSelect() {
  1278. $('.import-causal-select').select2({
  1279. dropdownParent: $('#importModal .modal-content'),
  1280. language: {
  1281. noResults: function() {
  1282. return "Nessun risultato";
  1283. }
  1284. }
  1285. });
  1286. $('.import-causal-select').on('change', function() {
  1287. let selectedValue = $(this).val();
  1288. Livewire.first().set('selectedCausal', selectedValue);
  1289. });
  1290. }
  1291. function openImportModal() {
  1292. let tableState = null;
  1293. if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
  1294. tableState = $('#tablesaw-350').DataTable().state.save();
  1295. }
  1296. const importModal = new bootstrap.Modal(document.getElementById('importModal'));
  1297. importModal.show();
  1298. setTimeout(function() {
  1299. initImportCausalSelect();
  1300. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1301. loadDataTable();
  1302. if (tableState) {
  1303. $('#tablesaw-350').DataTable().state.load(tableState);
  1304. }
  1305. }
  1306. }, 200);
  1307. }
  1308. function closeImportModal() {
  1309. const importModal = bootstrap.Modal.getInstance(document.getElementById('importModal'));
  1310. if (importModal) {
  1311. importModal.hide();
  1312. }
  1313. setTimeout(function() {
  1314. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1315. loadDataTable();
  1316. }
  1317. }, 100);
  1318. }
  1319. // IMPORT PROGRESS AND RESULTS
  1320. Livewire.on('update-progress', (progress) => {
  1321. const progressBar = document.querySelector('.progress-bar');
  1322. if (progressBar) {
  1323. progressBar.style.width = `${progress}%`;
  1324. progressBar.setAttribute('aria-valuenow', progress);
  1325. progressBar.textContent = `${Math.round(progress)}%`;
  1326. }
  1327. });
  1328. Livewire.on('import-started', () => {
  1329. const closeButton = document.querySelector('#importModal .btn-close');
  1330. const submitButton = document.querySelector('#importModal button[type="submit"]');
  1331. if (closeButton) closeButton.disabled = true;
  1332. if (submitButton) submitButton.disabled = true;
  1333. });
  1334. let transitioningToResultModal = false;
  1335. Livewire.on('show-import-result', data => {
  1336. transitioningToResultModal = true;
  1337. const resultDiv = document.getElementById('importResultMessage');
  1338. resultDiv.innerHTML = data.message;
  1339. const importModal = bootstrap.Modal.getInstance(document.getElementById('importModal'));
  1340. if (importModal) {
  1341. importModal.hide();
  1342. }
  1343. setTimeout(() => {
  1344. const resultModal = new bootstrap.Modal(document.getElementById('importResultModal'));
  1345. resultModal.show();
  1346. }, 300);
  1347. });
  1348. document.getElementById('importModal').addEventListener('hidden.bs.modal', function () {
  1349. if (!transitioningToResultModal) {
  1350. setTimeout(function() {
  1351. window.location.reload();
  1352. }, 500);
  1353. } else {
  1354. transitioningToResultModal = false;
  1355. }
  1356. });
  1357. document.getElementById('importResultModal').addEventListener('hidden.bs.modal', function () {
  1358. window.location.reload();
  1359. });
  1360. function calculateAmount(rowIndex) {
  1361. const imponibileField = document.getElementById(`rows.${rowIndex}.imponibile`);
  1362. const aliquotaField = document.getElementById(`rows.${rowIndex}.aliquota_iva`);
  1363. const amountField = document.getElementById(`rows.${rowIndex}.amount`);
  1364. if (imponibileField && aliquotaField && amountField) {
  1365. let imponibile = imponibileField.value.replace('€', '').replace(/\./g, '').replace(',', '.').trim();
  1366. imponibile = parseFloat(imponibile) || 0;
  1367. let aliquota = parseFloat(aliquotaField.value) || 0;
  1368. const imposta = imponibile * (aliquota / 100);
  1369. const totalAmount = imponibile + imposta;
  1370. let formattedAmount = "€ " + totalAmount.toFixed(2).replace('.', ',').replace(/\B(?=(\d{3})+(?!\d))/g, ".");
  1371. amountField.value = formattedAmount;
  1372. const component = Livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id'));
  1373. if (component) {
  1374. component.set(`rows.${rowIndex}.amount`, formattedAmount);
  1375. }
  1376. }
  1377. }
  1378. function setupCalculationListeners() {
  1379. const rows = document.querySelectorAll('input[id^="rows."][id$=".imponibile"], select[id^="rows."][id$=".aliquota_iva"]');
  1380. rows.forEach(field => {
  1381. field.addEventListener('blur', function() {
  1382. const match = this.id.match(/rows\.(\d+)\./);
  1383. if (match) {
  1384. const rowIndex = match[1];
  1385. calculateAmount(rowIndex);
  1386. }
  1387. });
  1388. field.addEventListener('change', function() {
  1389. const match = this.id.match(/rows\.(\d+)\./);
  1390. if (match) {
  1391. const rowIndex = match[1];
  1392. calculateAmount(rowIndex);
  1393. }
  1394. });
  1395. });
  1396. }
  1397. document.addEventListener('livewire:load', setupCalculationListeners);
  1398. document.addEventListener('livewire:update', setupCalculationListeners);
  1399. Livewire.on('load-select', function() {
  1400. setTimeout(setupCalculationListeners, 300);
  1401. });
  1402. function viewData(id) {
  1403. Livewire.first().viewData(id);
  1404. setTimeout(function() {
  1405. const modalElement = document.getElementById('recordDetailsModal');
  1406. if (modalElement) {
  1407. const modal = new bootstrap.Modal(modalElement);
  1408. modal.show();
  1409. modalElement.addEventListener('hidden.bs.modal', function() {
  1410. setTimeout(function() {
  1411. window.location.reload();
  1412. }, 100);
  1413. });
  1414. }
  1415. }, 300);
  1416. }
  1417. window.addEventListener('show-record-details', function(event) {
  1418. showRecordDetailsModal(event.detail.record);
  1419. });
  1420. function showRecordDetailsModal(record) {
  1421. const modalElement = document.getElementById('recordDetailsModal');
  1422. if (!modalElement) return;
  1423. try {
  1424. let recordDetailsModal = new bootstrap.Modal(modalElement);
  1425. document.getElementById('recordDate').textContent = record.formatted_date || 'N/A';
  1426. document.getElementById('recordPaymentDate').textContent = record.formatted_data_pagamento || 'N/A';
  1427. document.getElementById('recordSupplier').textContent = record.supplier_name || 'N/A';
  1428. document.getElementById('recordPaymentMethod').textContent = record.payment_method_name || 'N/A';
  1429. document.getElementById('recordTotalAmount').textContent = record.formatted_amount || 'N/A';
  1430. const paymentStatusElement = document.getElementById('recordPaymentStatus');
  1431. if (paymentStatusElement) {
  1432. paymentStatusElement.textContent = record.payment_status || 'N/A';
  1433. paymentStatusElement.className = 'badge ' + (record.is_paid ? 'bg-success' : 'bg-warning');
  1434. }
  1435. const rowsContainer = document.getElementById('recordRowsContainer');
  1436. if (rowsContainer) {
  1437. rowsContainer.innerHTML = '';
  1438. if (record.rows && record.rows.length > 0) {
  1439. record.rows.forEach(function(row, index) {
  1440. const tr = document.createElement('tr');
  1441. tr.innerHTML = `
  1442. <td>${index + 1}</td>
  1443. <td>${row.note && row.note.trim() !== '' ? row.note : (row.causal_name || 'N/A')}</td>
  1444. <td>${row.formatted_imponibile || 'N/A'}</td>
  1445. <td>${row.aliquota_iva ? row.aliquota_iva + '%' : '-'}</td>
  1446. <td>${row.formatted_imposta || 'N/A'}</td>
  1447. <td class="fw-bold">${row.formatted_amount || 'N/A'}</td>
  1448. `;
  1449. rowsContainer.appendChild(tr);
  1450. });
  1451. } else {
  1452. const tr = document.createElement('tr');
  1453. tr.innerHTML = '<td colspan="6" class="text-center">Nessuna riga disponibile</td>';
  1454. rowsContainer.appendChild(tr);
  1455. }
  1456. }
  1457. recordDetailsModal.show();
  1458. } catch (error) {
  1459. console.error('Error displaying modal:', error);
  1460. }
  1461. }
  1462. window.addEventListener('beforeunload', function() {
  1463. hideLoading();
  1464. if (fileUploadProgressInterval) {
  1465. clearInterval(fileUploadProgressInterval);
  1466. }
  1467. if (window.baseProgressInterval) {
  1468. clearInterval(window.baseProgressInterval);
  1469. }
  1470. });
  1471. </script>
  1472. <link href="/css/datatables.css" rel="stylesheet" />
  1473. <script src="/assets/js/datatables.js"></script>
  1474. <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
  1475. <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
  1476. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
  1477. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
  1478. <script>
  1479. $(document).ready(function() {
  1480. loadDataTable();
  1481. });
  1482. @if(isset($_GET["showFilters"]))
  1483. var filterSupplier = localStorage.getItem("filterSupplierRecordOut");
  1484. if (filterSupplier && filterSupplier != "null" && filterSupplier != "undefined") {
  1485. $('.filterSupplier').val(filterSupplier);
  1486. $('.filterSupplier').trigger('change');
  1487. }
  1488. var filterPaymentMethod = localStorage.getItem("filterPaymentMethodRecordOut");
  1489. if (filterPaymentMethod && filterPaymentMethod != "null" && filterPaymentMethod != "undefined") {
  1490. $('.filterPaymentMethod').val(filterPaymentMethod);
  1491. $('.filterPaymentMethod').trigger('change');
  1492. }
  1493. var filterCausals = localStorage.getItem("filterCausalsRecordOut");
  1494. if (filterCausals && filterCausals != "null" && filterCausals != "undefined") {
  1495. $('.filterCausals').val(filterCausals);
  1496. $('.filterCausals').trigger('change');
  1497. }
  1498. var filterFrom = localStorage.getItem("filterFromRecordOut");
  1499. if (filterFrom && filterFrom != "" && filterFrom != "undefined") {
  1500. $('.filterFrom').val(filterFrom);
  1501. }
  1502. var filterTo = localStorage.getItem("filterToRecordOut");
  1503. if (filterTo && filterTo != "" && filterTo != "undefined") {
  1504. $('.filterTo').val(filterTo);
  1505. }
  1506. @endif
  1507. var isFilter = false;
  1508. $(document).ready(function() {
  1509. $(document).on("click",".showHideFilter",function() {
  1510. if (isFilter) {
  1511. isFilter = false;
  1512. $(".showFilter").hide();
  1513. } else {
  1514. isFilter = true;
  1515. $(".showFilter").show();
  1516. }
  1517. });
  1518. $(document).on("select2:open",".filterCausals",function() {
  1519. setTimeout(() => {
  1520. $(".select2-results__option").each(function(){
  1521. var txt = $(this).html();
  1522. var count = (txt.match(/-/g) || []).length;
  1523. $(this).addClass('paddingLeftSelect' + count);
  1524. });
  1525. }, 100);
  1526. });
  1527. $(document).on("click",".addData",function() {
  1528. $(".title--section_addButton").trigger("click")
  1529. });
  1530. });
  1531. function editData(id) {
  1532. @this.edit(id);
  1533. }
  1534. function deleteData(id) {
  1535. if (confirm('Sei sicuro?'))
  1536. @this.delete(id).then(() => {
  1537. window.location.reload();
  1538. });
  1539. }
  1540. Livewire.on('load-data-table', () => {
  1541. setTimeout(function() { loadDataTable() }, 100);
  1542. });
  1543. Livewire.on('destroy-data-table', () => {
  1544. $('#tablesaw-350').DataTable().destroy();
  1545. });
  1546. function destroyDataTable() {
  1547. $('#tablesaw-350').DataTable().destroy();
  1548. }
  1549. function reset() {
  1550. $(".todayButton").addClass("lightGrey");
  1551. $(".yesterdayButton").addClass("lightGrey");
  1552. $('.filterSupplier').val('');
  1553. $('.filterSupplier').trigger('change');
  1554. $('.filterPaymentMethod').val('');
  1555. $('.filterPaymentMethod').trigger('change');
  1556. $('.filterCausals').val('');
  1557. $('.filterCausals').trigger('change');
  1558. $('.filterFrom').val('');
  1559. $('.filterTo').val('');
  1560. localStorage.clear();
  1561. loadDataTable();
  1562. }
  1563. function loadDataTable() {
  1564. if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
  1565. $('#tablesaw-350').DataTable().destroy();
  1566. }
  1567. var filterSupplier = $('.filterSupplier').val();
  1568. var filterPaymentMethod = $('.filterPaymentMethod').val();
  1569. var filterCausals = $('.filterCausals').val();
  1570. var filterFrom = $('.filterFrom').val();
  1571. var filterTo = $('.filterTo').val();
  1572. localStorage.setItem("filterSupplierRecordOut", filterSupplier);
  1573. localStorage.setItem("filterPaymentMethodRecordOut", filterPaymentMethod);
  1574. localStorage.setItem("filterCausalsRecordOut", filterCausals);
  1575. localStorage.setItem("filterFromRecordOut", filterFrom);
  1576. localStorage.setItem("filterToRecordOut", filterTo);
  1577. $('#tablesaw-350').DataTable({
  1578. ajax: {
  1579. url : "/get_record_out?filterSupplier=" + filterSupplier + "&filterPaymentMethod=" + filterPaymentMethod + "&filterCausals=" + filterCausals + "&filterFrom=" + filterFrom + "&filterTo=" + filterTo,
  1580. dataSrc: function (json){
  1581. if(json.totals){
  1582. $(".totalDiv").html('Totale&nbsp;:&nbsp;<b>' + json.totals + '</b>');
  1583. } else {
  1584. $(".totalDiv").html('');
  1585. }
  1586. @if(Auth::user()->level != 0)
  1587. $(".totalDiv").html('');
  1588. @endif
  1589. return json.data;
  1590. }
  1591. },
  1592. columns: [
  1593. { data: 'numero_fattura' },
  1594. {
  1595. data: "date",
  1596. render: function (data, type){
  1597. if (data == "") return " TOTALE";
  1598. if (type == "sort"){
  1599. return new Date(data).getTime();
  1600. }
  1601. const j = data.split(" ");
  1602. const d = j[0].split("-");
  1603. var ret = d[2] + "/" + d[1] + "/" + d[0];
  1604. return ret;
  1605. }
  1606. },
  1607. { data: 'total', className: "numericCol" },
  1608. { data: 'supplier' },
  1609. { data: 'causals' },
  1610. { data: 'payment' },
  1611. {
  1612. data: 'is_paid',
  1613. render: function (data) {
  1614. if (data === true || data === 'true' || data === 1 || data === '1' || data === 'Pagato') {
  1615. return '<span class="badge bg-success">Pagato</span>';
  1616. } else {
  1617. return '<span class="badge bg-warning">Da Pagare</span>';
  1618. }
  1619. }
  1620. },
  1621. {
  1622. data: "action",
  1623. render: function (data){
  1624. if (data == "") return "";
  1625. const j = data.split("|");
  1626. 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;';
  1627. 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;';
  1628. 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>';
  1629. return ret;
  1630. }
  1631. },
  1632. ],
  1633. order: [[1, 'desc']],
  1634. thead: {
  1635. 'th': {'background-color': 'blue'}
  1636. },
  1637. layout: {
  1638. topStart : null,
  1639. topEnd : null,
  1640. top1A: {
  1641. buttons: [
  1642. {
  1643. extend: 'collection',
  1644. text: 'ESPORTA',
  1645. buttons: [
  1646. {
  1647. extend: 'excelHtml5',"action":newexportaction,
  1648. title: 'Uscite',
  1649. exportOptions: {
  1650. columns: ":not(':last')"
  1651. }
  1652. },
  1653. {
  1654. extend: 'pdfHtml5',"action":newexportaction,
  1655. title: 'Uscite',
  1656. exportOptions: {
  1657. columns: ":not(':last')"
  1658. }
  1659. },
  1660. {
  1661. extend: 'print',"action":newexportaction,
  1662. text: 'Stampa',
  1663. title: 'Uscite',
  1664. exportOptions: {
  1665. columns: ":not(':last')"
  1666. }
  1667. }
  1668. ],
  1669. dropup: true
  1670. }
  1671. ]
  1672. },
  1673. top1B : {
  1674. pageLength: {
  1675. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  1676. }
  1677. },
  1678. top1C :'search',
  1679. },
  1680. pagingType: 'numbers',
  1681. "language": {
  1682. "url": "/assets/js/Italian.json"
  1683. },
  1684. "fnInitComplete": function (oSettings, json) {
  1685. var html = '&nbsp;<a href="#" class="showHideFilter btn--ui"><i class="fa-solid fa-sliders"></i></a>';
  1686. html += '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  1687. $(".dt-search").append(html);
  1688. }
  1689. });
  1690. $('#tablesaw-350 thead tr th').addClass('col');
  1691. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  1692. $('#tablesaw-350').on('draw.dt', function() {
  1693. $('[data-bs-toggle="popover"]').popover()
  1694. });
  1695. }
  1696. document.addEventListener('livewire:initialized', () => {
  1697. let importModalOpen = false;
  1698. const importModal = document.getElementById('importModal');
  1699. importModal.addEventListener('shown.bs.modal', function () {
  1700. importModalOpen = true;
  1701. });
  1702. importModal.addEventListener('hidden.bs.modal', function () {
  1703. importModalOpen = false;
  1704. setTimeout(() => {
  1705. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1706. loadDataTable();
  1707. }
  1708. }, 100);
  1709. });
  1710. document.addEventListener('livewire:update', function() {
  1711. if (importModalOpen) {
  1712. const modalInstance = bootstrap.Modal.getInstance(importModal);
  1713. if (!modalInstance) {
  1714. const newModal = new bootstrap.Modal(importModal);
  1715. newModal.show();
  1716. } else if (!importModal.classList.contains('show')) {
  1717. modalInstance.show();
  1718. }
  1719. setTimeout(() => {
  1720. if (!$.fn.DataTable.isDataTable('#tablesaw-350')) {
  1721. loadDataTable();
  1722. }
  1723. }, 100);
  1724. }
  1725. });
  1726. document.querySelectorAll('.select2-container').forEach(select => {
  1727. select.addEventListener('click', function(e) {
  1728. e.stopPropagation();
  1729. });
  1730. });
  1731. });
  1732. document.addEventListener('DOMContentLoaded', function() {
  1733. if (document.getElementById('importModal')) {
  1734. initImportCausalSelect();
  1735. }
  1736. Livewire.on('load-select', function() {
  1737. if (document.getElementById('importModal') &&
  1738. document.getElementById('importModal').classList.contains('show')) {
  1739. initImportCausalSelect();
  1740. }
  1741. });
  1742. setupCalculationListeners();
  1743. setupDragAndDrop();
  1744. const recordDetailsModal = document.getElementById('recordDetailsModal');
  1745. if (recordDetailsModal) {
  1746. recordDetailsModal.addEventListener('hidden.bs.modal', function() {
  1747. setTimeout(function() {
  1748. window.location.reload();
  1749. }, 100);
  1750. });
  1751. }
  1752. });
  1753. function pollAttachmentStatus(recordId) {
  1754. const pollInterval = setInterval(function() {
  1755. fetch(`/check-attachment-status/${recordId}`)
  1756. .then(response => response.json())
  1757. .then(data => {
  1758. if (data.status === 'completed') {
  1759. clearInterval(pollInterval);
  1760. showSuccess('Allegato caricato con successo!');
  1761. } else if (data.status === 'failed') {
  1762. clearInterval(pollInterval);
  1763. showError('Caricamento allegato fallito');
  1764. }
  1765. });
  1766. }, 2000);
  1767. setTimeout(() => clearInterval(pollInterval), 300000);
  1768. }
  1769. function showRecordDetailsModal(record) {
  1770. const modalElement = document.getElementById('recordDetailsModal');
  1771. if (!modalElement) return;
  1772. try {
  1773. let recordDetailsModal = new bootstrap.Modal(modalElement);
  1774. document.getElementById('recordDate').textContent = record.formatted_date || 'N/A';
  1775. document.getElementById('recordPaymentDate').textContent = record.formatted_data_pagamento || 'N/A';
  1776. document.getElementById('recordSupplier').textContent = record.supplier_name || 'N/A';
  1777. document.getElementById('recordPaymentMethod').textContent = record.payment_method_name || 'N/A';
  1778. document.getElementById('recordTotalAmount').textContent = record.formatted_amount || 'N/A';
  1779. const paymentStatusElement = document.getElementById('recordPaymentStatus');
  1780. if (paymentStatusElement) {
  1781. paymentStatusElement.textContent = record.payment_status || 'N/A';
  1782. paymentStatusElement.className = 'badge ' + (record.is_paid ? 'bg-success' : 'bg-warning');
  1783. }
  1784. const attachmentPresentDiv = document.getElementById('recordAttachmentPresent');
  1785. const attachmentMissingDiv = document.getElementById('recordAttachmentMissing');
  1786. const attachmentLink = document.getElementById('recordAttachmentLink');
  1787. const attachmentName = document.getElementById('recordAttachmentName');
  1788. if (record.attachment && record.attachment_url) {
  1789. attachmentPresentDiv.style.display = 'block';
  1790. attachmentMissingDiv.style.display = 'none';
  1791. // Configura il link per l'allegato
  1792. attachmentLink.href = record.attachment_url;
  1793. // Estrai il nome del file dal percorso
  1794. let fileName = record.attachment;
  1795. if (fileName.includes('/')) {
  1796. fileName = fileName.split('/').pop();
  1797. }
  1798. if (fileName.includes('\\')) {
  1799. fileName = fileName.split('\\').pop();
  1800. }
  1801. // Se il nome è troppo lungo, troncalo
  1802. if (fileName.length > 30) {
  1803. const extension = fileName.substring(fileName.lastIndexOf('.'));
  1804. const baseName = fileName.substring(0, fileName.lastIndexOf('.'));
  1805. fileName = baseName.substring(0, 25) + '...' + extension;
  1806. }
  1807. attachmentName.textContent = fileName;
  1808. // Aggiorna l'icona in base al tipo di file
  1809. const iconElement = attachmentPresentDiv.querySelector('i.fa-file-pdf');
  1810. if (fileName.toLowerCase().includes('.pdf')) {
  1811. iconElement.className = 'fa-solid fa-file-pdf me-2 text-danger';
  1812. } else if (fileName.toLowerCase().includes('.xml')) {
  1813. iconElement.className = 'fa-solid fa-file-code me-2 text-info';
  1814. } else if (fileName.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)) {
  1815. iconElement.className = 'fa-solid fa-file-image me-2 text-success';
  1816. } else if (fileName.toLowerCase().match(/\.(doc|docx)$/)) {
  1817. iconElement.className = 'fa-solid fa-file-word me-2 text-primary';
  1818. } else if (fileName.toLowerCase().match(/\.(xls|xlsx|csv)$/)) {
  1819. iconElement.className = 'fa-solid fa-file-excel me-2 text-success';
  1820. } else {
  1821. iconElement.className = 'fa-solid fa-file me-2 text-secondary';
  1822. }
  1823. } else {
  1824. // Mostra la sezione senza allegato
  1825. attachmentPresentDiv.style.display = 'none';
  1826. attachmentMissingDiv.style.display = 'block';
  1827. }
  1828. // Popola le righe come prima
  1829. const rowsContainer = document.getElementById('recordRowsContainer');
  1830. if (rowsContainer) {
  1831. rowsContainer.innerHTML = '';
  1832. if (record.rows && record.rows.length > 0) {
  1833. record.rows.forEach(function(row, index) {
  1834. const tr = document.createElement('tr');
  1835. tr.innerHTML = `
  1836. <td>${index + 1}</td>
  1837. <td>${row.note && row.note.trim() !== '' ? row.note : (row.causal_name || 'N/A')}</td>
  1838. <td>${row.formatted_imponibile || 'N/A'}</td>
  1839. <td>${row.aliquota_iva ? row.aliquota_iva + '%' : '-'}</td>
  1840. <td>${row.formatted_imposta || 'N/A'}</td>
  1841. <td class="fw-bold">${row.formatted_amount || 'N/A'}</td>
  1842. `;
  1843. rowsContainer.appendChild(tr);
  1844. });
  1845. } else {
  1846. const tr = document.createElement('tr');
  1847. tr.innerHTML = '<td colspan="6" class="text-center">Nessuna riga disponibile</td>';
  1848. rowsContainer.appendChild(tr);
  1849. }
  1850. }
  1851. recordDetailsModal.show();
  1852. } catch (error) {
  1853. console.error('Error displaying modal:', error);
  1854. }
  1855. }
  1856. // Aggiungere questo listener per gestire i cambi di stato del campo commercial
  1857. document.addEventListener('livewire:load', function() {
  1858. // Listener per il cambio del radio button commerciale/non commerciale
  1859. const commercialRadios = document.querySelectorAll('input[name="commercial"]');
  1860. commercialRadios.forEach(radio => {
  1861. radio.addEventListener('change', function() {
  1862. console.log('Commercial value changed to:', this.value);
  1863. // Il campo numero fattura sarà nascosto/mostrato automaticamente da Livewire
  1864. });
  1865. });
  1866. });
  1867. // Listener per gli aggiornamenti di Livewire
  1868. document.addEventListener('livewire:update', function() {
  1869. // Re-attach listeners dopo gli aggiornamenti di Livewire
  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. });
  1875. });
  1876. });
  1877. </script>
  1878. @endpush