records_out.blade.php 99 KB

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