RecordOUT.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Illuminate\Support\Facades\Auth;
  5. use Illuminate\Support\Facades\Log;
  6. use SimpleXMLElement;
  7. use Livewire\WithFileUploads;
  8. use Illuminate\Support\Facades\DB;
  9. class RecordOUT extends Component
  10. {
  11. use WithFileUploads;
  12. protected $listeners = ['setCausal' => 'setCausal'];
  13. public $sortField = 'date';
  14. public $sortAsc = false;
  15. public $typeOUT = "OUT";
  16. public $fromPage = '';
  17. public $multiP = false;
  18. public $multiMonthTo = 0;
  19. public $multiYearTo = 0;
  20. public $multiMonthFrom = 0;
  21. public $multiYearFrom = 0;
  22. public function sortBy($field)
  23. {
  24. if ($this->sortField === $field) {
  25. $this->sortAsc = ! $this->sortAsc;
  26. } else {
  27. $this->sortAsc = true;
  28. }
  29. $this->sortField = $field;
  30. }
  31. public $records, $dataId, $member_id, $supplier_id,
  32. $causal_id,
  33. $payment_method_id,
  34. $date,
  35. $month,
  36. $year,
  37. $type,
  38. $amount,
  39. $note,
  40. $commercial, $update = false, $add = false;
  41. public $filterSupplier = 0, $filterPaymentMethod = 0, $filterCausals = [], $filterFrom = '', $filterTo = '', $filterCommercial = 0;
  42. public $hasFilter = false;
  43. public $total = 0;
  44. public $selectedFilter = '';
  45. public $multipleIds = [];
  46. public $multipleAction = '';
  47. public $selectId = 0;
  48. public $causals = array();
  49. public $payments = array();
  50. public $suppliers = array();
  51. public $rows = array();
  52. public $receiptFiles = [];
  53. public $selectedCausal = '';
  54. public $importCausals = array();
  55. protected $rules = [
  56. 'supplier_id' => 'required',
  57. 'payment_method_id' => 'required',
  58. 'rows.*.causal_id' => 'required',
  59. 'rows.*.amount' => 'required'
  60. //'causal_id' => 'required',
  61. //'amount' => 'required'
  62. ];
  63. protected $messages = [
  64. 'supplier_id.required' => 'Il fornitore è obbligatorio',
  65. 'payment_method_id.required' => 'Il metodo di pagamento è obbligatorio',
  66. 'rows.*.amount.required' => 'L\'importo è obbligatorio',
  67. 'rows.*.causal_id.required' => 'La causale è obbligatoria'
  68. ];
  69. public function getSupplierProperty()
  70. {
  71. $ret = null;
  72. if ($this->supplier_id > 0) {
  73. $ret = \App\Models\Supplier::findOrFail($this->supplier_id);
  74. }
  75. return $ret;
  76. }
  77. public function getCausalProperty()
  78. {
  79. $ret = null;
  80. if ($this->causal_id > 0) {
  81. $ret = \App\Models\Causal::findOrFail($this->causal_id);
  82. }
  83. return $ret;
  84. }
  85. public function resetFields()
  86. {
  87. $this->member_id = null;
  88. $this->supplier_id = null;
  89. //$this->causal_id = null;
  90. $this->payment_method_id = null;
  91. $this->date = date("Y-m-d");
  92. //$this->month = date("n");
  93. //$this->year = date("Y");
  94. $this->type = 'OUT';
  95. //$this->note = '';
  96. //$this->amount = null;
  97. $this->commercial = 1;
  98. $this->rows = array();
  99. $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')), 'amount' => null, 'note' => '', 'commercial' => 0);
  100. $this->emit('load-data-table');
  101. }
  102. public function getCausale($records, $indentation)
  103. {
  104. foreach ($records as $record) {
  105. $this->causals[] = array('id' => $record->id, 'name' => $record->getTree());
  106. if (count($record->childs))
  107. $this->getCausale($record->childs, $indentation + 1);
  108. }
  109. }
  110. public $isImportModalOpen = false;
  111. public function openImportModal()
  112. {
  113. $this->isImportModalOpen = true;
  114. }
  115. public function closeImportModal()
  116. {
  117. $this->isImportModalOpen = false;
  118. $this->reset(['selectedCausal', 'receiptFiles']);
  119. $this->resetValidation();
  120. }
  121. public function hydrate()
  122. {
  123. $this->emit('load-select');
  124. if (empty($this->importCausals)) {
  125. $this->loadImportCausals();
  126. }
  127. }
  128. public function mount()
  129. {
  130. if (isset($_GET["from"])) {
  131. $this->fromPage = $_GET["from"];
  132. }
  133. if (Auth::user()->level != env('LEVEL_ADMIN', 0))
  134. return redirect()->to('/dashboard');
  135. $this->multiMonthFrom = date("n");
  136. $this->multiYearFrom = date("Y");
  137. $this->multiMonthTo = date("n");
  138. $this->multiYearTo = date("Y");
  139. if (isset($_GET["new"]))
  140. $this->add();
  141. $this->causals = array();
  142. $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'OUT')->orderBy('name')->get(), 0);
  143. $this->suppliers = \App\Models\Supplier::select('name', 'id')->orderBy('name')->get();
  144. $this->payments = \App\Models\PaymentMethod::select('id', 'name')->whereIn('type', array('ALL', 'OUT'))->where('enabled', true)->orderBy('name')->get();
  145. $this->importCausals = [];
  146. $this->loadImportCausals();
  147. }
  148. public function loadImportCausals()
  149. {
  150. $causals = \App\Models\Causal::select('id', 'name')
  151. ->where('type', 'OUT')
  152. ->orderBy('name')
  153. ->get();
  154. $this->importCausals = [];
  155. foreach ($causals as $causal) {
  156. $this->importCausals[] = [
  157. 'id' => $causal->id,
  158. 'name' => $causal->getTree()
  159. ];
  160. }
  161. }
  162. public function getCausal($causal)
  163. {
  164. $ret = '';
  165. if ($causal > 0) {
  166. $ret = \App\Models\Causal::findOrFail($causal)->getTree();
  167. }
  168. return $ret;
  169. }
  170. public function search()
  171. {
  172. $this->hasFilter = true;
  173. }
  174. public function disableSearch()
  175. {
  176. $this->filterSupplier = 0;
  177. $this->filterPaymentMethod = 0;
  178. $this->filterCausals = [];
  179. $this->filterTo = '';
  180. $this->filterFrom = '';
  181. $this->filterCommercial = 0;
  182. $this->hasFilter = false;
  183. $this->hasFilter = false;
  184. }
  185. public function render()
  186. {
  187. $datas = [];
  188. if (false) {
  189. if ($this->hasFilter) {
  190. $datas = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  191. /*if ($this->filterCommercial > 0)
  192. {
  193. $datas = $datas->where('commercial', $this->filterCommercial == 1 ? true : false);
  194. }*/
  195. if ($this->filterSupplier > 0) {
  196. $datas = $datas->where('supplier_id', $this->filterSupplier);
  197. }
  198. if ($this->filterPaymentMethod > 0) {
  199. $datas = $datas->where('payment_method_id', $this->filterPaymentMethod);
  200. }
  201. /*if (sizeof($this->filterCausals) > 0)
  202. {
  203. $datas = $datas->whereIn('causal_id', $this->filterCausals);
  204. }*/
  205. if ($this->filterFrom != '') {
  206. $datas = $datas->where('date', '>=', $this->filterFrom);
  207. }
  208. if ($this->filterTo != '') {
  209. $datas = $datas->where('date', '<=', $this->filterTo);
  210. }
  211. //$this->records = $datas->orderBy('date', 'DESC')->get();
  212. $this->records = $datas->get();
  213. //$this->total = $this->records->sum('amount');
  214. $this->total = 0;
  215. foreach ($this->records as $r) {
  216. foreach ($r->rows as $rr) {
  217. $this->total += $rr->amount;
  218. }
  219. }
  220. } else {
  221. if ($this->selectedFilter == '') {
  222. $this->records = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method')->limit(20)->orderBy('date', 'DESC')->orderBy('id', 'DESC')->get();
  223. } else {
  224. if ($this->selectedFilter == 0) {
  225. $fromDate = date("Y-m-d");
  226. $toDate = date("Y-m-d");
  227. }
  228. if ($this->selectedFilter == 1) {
  229. $fromDate = date("Y-m-01");
  230. $toDate = date("Y-m-t");
  231. }
  232. if ($this->selectedFilter == 2) {
  233. $fromDate = date("Y-01-01");
  234. $toDate = date("Y-12-31");
  235. }
  236. if ($this->selectedFilter == 3) {
  237. $fromDate = date("2000-01-01");
  238. $toDate = date("Y-12-31");
  239. }
  240. $this->records = \App\Models\Record::where('type', 'OUT')->whereBetween('date', [$fromDate, $toDate])->with('supplier', 'payment_method')->get();
  241. }
  242. }
  243. foreach ($this->records as $r) {
  244. $r->total = $r->getTotal();
  245. $r->supplier = $r->supplier ? $r->supplier->name : '';
  246. $r->payment = $r->payment_method ? $r->payment_method->name : '';
  247. }
  248. }
  249. /*if ($this->sortField != '')
  250. {
  251. if ($this->sortAsc)
  252. $this->records = $this->records->sortBy($this->sortField);
  253. else
  254. $this->records = $this->records->sortByDesc($this->sortField);
  255. }
  256. else
  257. $this->records = $this->records->sortByDesc('id');*/
  258. return view('livewire.records_out');
  259. }
  260. public function executeMultipleAction()
  261. {
  262. if ($this->multipleAction == 'delete')
  263. $this->multipleDelete();
  264. }
  265. public function add()
  266. {
  267. $this->emit('load-select');
  268. //if ($this->hasFilter)
  269. $this->emit('hide-search');
  270. $this->resetFields();
  271. $this->add = true;
  272. $this->update = false;
  273. $this->emit('setEdit', true);
  274. }
  275. public function store()
  276. {
  277. $this->emit('refresh');
  278. $this->validate();
  279. try {
  280. $record = \App\Models\Record::create([
  281. 'member_id' => $this->member_id,
  282. 'supplier_id' => $this->supplier_id,
  283. //'causal_id' => $this->causal_id,
  284. 'payment_method_id' => $this->payment_method_id,
  285. 'date' => $this->date,
  286. //'month' => $this->month,
  287. //'year' => $this->year,
  288. //'note' => $this->note,
  289. 'type' => $this->type,
  290. //'amount' => $this->currencyToDouble($this->amount),
  291. 'commercial' => $this->commercial,
  292. ]);
  293. $this->dataId = $record->id;
  294. $tot = 0;
  295. foreach ($this->rows as $row) {
  296. foreach ($row["when"] as $x => $y) {
  297. $row["when"][$x]['period'] = $row["when"][$x]['month'] . "-" . $row["when"][$x]['year'];
  298. }
  299. \App\Models\RecordRow::create([
  300. 'record_id' => $this->dataId,
  301. 'causal_id' => $row["causal_id"],
  302. 'note' => $row["note"],
  303. 'amount' => $this->currencyToDouble($row["amount"]),
  304. 'commercial' => $row["commercial"],
  305. 'when' => json_encode($row["when"])
  306. ]);
  307. $tot += $this->currencyToDouble($row["amount"]);
  308. }
  309. $record->amount = $tot;
  310. $record->save();
  311. session()->flash('success', 'Movimento creato');
  312. $this->resetFields();
  313. $this->add = false;
  314. $this->emit('setEdit', false);
  315. } catch (\Exception $ex) {
  316. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  317. }
  318. }
  319. public function edit($id)
  320. {
  321. if (!isset($_GET["from"]) && $this->fromPage == '')
  322. $this->fromPage = 'out';
  323. $this->emit('setEdit', true);
  324. $this->emit('load-select');
  325. //if ($this->hasFilter)
  326. $this->emit('hide-search');
  327. try {
  328. $record = \App\Models\Record::findOrFail($id);
  329. if (!$record) {
  330. session()->flash('error', 'Movimento non trovato');
  331. } else {
  332. $this->member_id = $record->member_id;
  333. $this->supplier_id = $record->supplier_id;
  334. //$this->causal_id = $record->causal_id;
  335. $this->payment_method_id = $record->payment_method_id;
  336. $this->date = date("Y-m-d", strtotime($record->date));
  337. //$this->month = $record->month;
  338. //$this->year = $record->year;
  339. //$this->note = $record->note;
  340. $this->type = $record->type;
  341. //$this->amount = formatPrice($record->amount);
  342. $this->commercial = $record->commercial;
  343. $this->dataId = $record->id;
  344. $this->update = true;
  345. $this->add = false;
  346. $this->rows = \App\Models\RecordRow::where('record_id', $this->dataId)->select('causal_id', 'note', 'commercial', 'when', 'amount')->get()->toArray();
  347. foreach ($this->rows as $i => $r) {
  348. $this->rows[$i]['amount'] = formatPrice($this->rows[$i]['amount']);
  349. $this->rows[$i]['when'] = json_decode($this->rows[$i]['when']);
  350. }
  351. }
  352. } catch (\Exception $ex) {
  353. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  354. }
  355. }
  356. public function update()
  357. {
  358. $this->emit('refresh');
  359. $this->validate();
  360. try {
  361. \App\Models\Record::whereId($this->dataId)->update([
  362. 'member_id' => $this->member_id,
  363. 'supplier_id' => $this->supplier_id,
  364. //'causal_id' => $this->causal_id,
  365. 'payment_method_id' => $this->payment_method_id,
  366. 'date' => $this->date,
  367. //'month' => $this->month,
  368. //'year' => $this->year,
  369. //'note' => $this->note,
  370. 'type' => $this->type,
  371. //'amount' => $this->currencyToDouble($this->amount),
  372. 'commercial' => $this->commercial,
  373. ]);
  374. $tot = 0;
  375. // Elimino le righe
  376. \App\Models\RecordRow::where('record_id', $this->dataId)->delete();
  377. // Inserisco le righe
  378. foreach ($this->rows as $row) {
  379. foreach ($row["when"] as $x => $y) {
  380. $row["when"][$x]['period'] = $row["when"][$x]['month'] . "-" . $row["when"][$x]['year'];
  381. }
  382. \App\Models\RecordRow::create([
  383. 'record_id' => $this->dataId,
  384. 'causal_id' => $row["causal_id"],
  385. 'note' => $row["note"],
  386. 'amount' => $this->currencyToDouble($row["amount"]),
  387. 'commercial' => $row["commercial"],
  388. 'when' => json_encode($row["when"])
  389. ]);
  390. $tot += $this->currencyToDouble($row["amount"]);
  391. }
  392. $rec = \App\Models\Record::findOrFail($this->dataId);
  393. $rec->amount = $tot;
  394. $rec->save();
  395. session()->flash('success', 'Movimento aggiornato');
  396. $this->resetFields();
  397. $this->update = false;
  398. $this->emit('setEdit', false);
  399. } catch (\Exception $ex) {
  400. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  401. }
  402. }
  403. public function cancel()
  404. {
  405. $this->add = false;
  406. $this->update = false;
  407. $this->emit('setEdit', false);
  408. $this->resetFields();
  409. }
  410. public function delete($id)
  411. {
  412. try {
  413. \App\Models\Record::find($id)->delete();
  414. session()->flash('success', "Movimento eliminato");
  415. } catch (\Exception $e) {
  416. session()->flash('error', 'Errore (' . $e->getMessage() . ')');
  417. }
  418. }
  419. public function multipleDelete()
  420. {
  421. try {
  422. foreach ($this->multipleIds as $id) {
  423. \App\Models\Record::find($id)->delete();
  424. }
  425. } catch (\Exception $e) {
  426. session()->flash('error', 'Errore (' . $e->getMessage() . ')');
  427. }
  428. $this->multipleAction = '';
  429. }
  430. /*
  431. public function createReceipt()
  432. {
  433. $receipt = \App\Models\Receipt::where('record_id', $this->dataId)->first();
  434. if ($receipt != null)
  435. {
  436. $receipt->update([
  437. 'member_id' => $this->member_id,
  438. 'supplier_id' => $this->supplier_id,
  439. 'causal_id' => $this->causal_id,
  440. 'payment_method_id' => $this->payment_method_id,
  441. 'date' => date("Y-m-d", strtotime($this->date)),
  442. 'month' => $this->month,
  443. 'year' => $this->year,
  444. 'type' => $this->type,
  445. 'amount' => $this->currencyToDouble($this->amount),
  446. 'commercial' => $this->commercial,
  447. 'status' => 1,
  448. ]);
  449. }
  450. else
  451. {
  452. $number = 1;
  453. $exist = \App\Models\Receipt::where('year', $this->year)->orderBy('number', 'DESC')->first();
  454. if ($exist != null)
  455. $number = $exist->number + 1;
  456. $receipt = \App\Models\Receipt::create([
  457. 'record_id' => $this->dataId,
  458. 'member_id' => $this->member_id,
  459. 'supplier_id' => $this->supplier_id,
  460. 'causal_id' => $this->causal_id,
  461. 'payment_method_id' => $this->payment_method_id,
  462. 'number' => $number,
  463. 'date' => $this->date,
  464. 'month' => $this->month,
  465. 'year' => $this->year,
  466. 'type' => $this->type,
  467. 'amount' => $this->currencyToDouble($this->amount),
  468. 'commercial' => $this->commercial,
  469. 'status' => 1,
  470. ]);
  471. }
  472. }
  473. public function removeReceipt()
  474. {
  475. $receipt = \App\Models\Receipt::findOrFail($this->currentReceip->id);
  476. $receipt->status = 99;
  477. $receipt->save();
  478. $this->currentReceip = $receipt;
  479. }
  480. */
  481. function currencyToDouble($val)
  482. {
  483. $x = str_replace("€", "", $val);
  484. $x = str_replace(".", "", $x);
  485. $x = str_replace(",", ".", $x);
  486. return floatval(trim($x));
  487. }
  488. public function addRow()
  489. {
  490. $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')), 'amount' => null, 'note' => '', 'commercial' => 0);
  491. $this->emit('load-select');
  492. }
  493. public function delRow($idx)
  494. {
  495. unset($this->rows[$idx]);
  496. // $this->emit('load-select');
  497. }
  498. public function addPeriod($idx)
  499. {
  500. $x = sizeof($this->rows[$idx]['when']) - 1;
  501. $newDate = \Carbon\Carbon::create($this->rows[$idx]['when'][$x]["year"] . "-" . $this->rows[$idx]['when'][$x]["month"] . '-01')->addMonth();
  502. $this->rows[$idx]['when'][] = array('month' => $newDate->format("n"), 'year' => $newDate->format("Y"), 'period' => '');
  503. //$this->rows[$idx]['when'][] = array('month' => date("n"), 'year' => date("Y"), 'period' => '');
  504. }
  505. public function delPeriod($idx, $xxx)
  506. {
  507. array_splice($this->rows[$idx]['when'], $xxx, 1);
  508. // $this->emit('load-select');
  509. }
  510. public function getTotal()
  511. {
  512. $total = 0.00;
  513. foreach ($this->rows as $r) {
  514. $total += $this->currencyToDouble($r["amount"] != null ? $r["amount"] : 0);
  515. }
  516. return formatPrice($total);
  517. // $this->emit('load-select');
  518. }
  519. public function setCausal($id, $idx)
  520. {
  521. $this->rows[$idx]["causal_id"] = $id;
  522. }
  523. public function multiPeriod()
  524. {
  525. $this->multiP = true;
  526. }
  527. public function multiPeriodCreate($idx)
  528. {
  529. $period = \Carbon\CarbonPeriod::create($this->multiYearFrom . '-' . $this->multiMonthFrom . '-01', '1 month', $this->multiYearTo . '-' . $this->multiMonthTo . '-01');
  530. $this->rows[$idx]['when'] = [];
  531. foreach ($period as $dt) {
  532. if (!in_array(array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => ''), $this->rows[$idx]['when']))
  533. $this->rows[$idx]['when'][] = array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => '');
  534. }
  535. $this->multiP = false;
  536. }
  537. public function multiPeriodCancel()
  538. {
  539. $this->multiP = false;
  540. }
  541. public function importReceipts()
  542. {
  543. $this->validate([
  544. 'receiptFiles.*' => 'required|mimes:xml|max:2048',
  545. 'selectedCausal' => 'required|exists:causals,id',
  546. ]);
  547. try {
  548. $importCount = 0;
  549. $errorsCount = 0;
  550. foreach ($this->receiptFiles as $receiptFile) {
  551. try {
  552. // Carica e analizza il file XML
  553. $xmlString = file_get_contents($receiptFile->getRealPath());
  554. $xml = simplexml_load_string($xmlString);
  555. if (!$xml) {
  556. throw new \Exception("Impossibile analizzare il file XML");
  557. }
  558. // Estrai i dati dalla fattura elettronica
  559. $fatturaData = $this->extractFatturaData($xml);
  560. // Trova o crea il fornitore
  561. $supplier = $this->findOrCreateSupplier($fatturaData);
  562. // Trova il metodo di pagamento
  563. $paymentMethodId = $this->findPaymentMethod($fatturaData['modalitaPagamento']);
  564. // Crea il record principale
  565. $record = $this->createRecord($supplier->id, $paymentMethodId, $fatturaData);
  566. // Crea il record row
  567. $this->createRecordRow($record->id, $fatturaData);
  568. // Crea la ricevuta
  569. $receipt = $this->createReceipt($record->id, $supplier->id, $paymentMethodId, $fatturaData);
  570. // Crea le righe della ricevuta
  571. $this->createReceiptRows($receipt->id, $fatturaData);
  572. $importCount++;
  573. Log::info("Fattura importata con successo: {$fatturaData['numeroFattura']}, Fornitore: {$fatturaData['denominazione']}");
  574. } catch (\Exception $e) {
  575. Log::error('Errore durante l\'importazione della fattura: ' . $e->getMessage());
  576. $errorsCount++;
  577. }
  578. }
  579. // Mostra messaggi appropriati
  580. $this->showResultMessages($importCount, $errorsCount);
  581. } catch (\Exception $e) {
  582. Log::error('Errore durante l\'importazione dei file XML: ' . $e->getMessage());
  583. session()->flash('error', 'Errore durante l\'importazione: ' . $e->getMessage());
  584. }
  585. $this->closeImportModal();
  586. }
  587. /**
  588. * Estrae i dati dalla fattura elettronica XML
  589. */
  590. private function extractFatturaData($xml)
  591. {
  592. $data = [];
  593. try {
  594. // Stampa la struttura XML per debug
  595. Log::info("Nomi dei children dell'elemento radice: " . implode(", ", array_map(function ($node) {
  596. return $node->getName();
  597. }, iterator_to_array($xml->children()))));
  598. $headerNode = $xml->FatturaElettronicaHeader;
  599. $bodyNode = $xml->FatturaElettronicaBody;
  600. if (!$headerNode || !$bodyNode) {
  601. throw new \Exception("Struttura XML non standard, FatturaElettronicaHeader o FatturaElettronicaBody non trovati");
  602. }
  603. // Estrai dati del fornitore (cedente/prestatore)
  604. $cedenteNode = $headerNode->CedentePrestatore;
  605. $datiAnagrafici = $cedenteNode->DatiAnagrafici;
  606. $idFiscaleIVA = $datiAnagrafici->IdFiscaleIVA;
  607. $data['idPaese'] = (string)$idFiscaleIVA->IdPaese;
  608. $data['idCodice'] = (string)$idFiscaleIVA->IdCodice;
  609. $data['partitaIva'] = $data['idPaese'] . $data['idCodice'];
  610. $data['codiceFiscale'] = (string)$datiAnagrafici->CodiceFiscale;
  611. $data['denominazione'] = (string)$datiAnagrafici->Anagrafica->Denominazione;
  612. // Estrai dati della sede
  613. $sede = $cedenteNode->Sede;
  614. $data['indirizzo'] = (string)$sede->Indirizzo;
  615. $data['cap'] = (string)$sede->CAP;
  616. $data['comune'] = (string)$sede->Comune;
  617. $data['provincia'] = (string)$sede->Provincia;
  618. $data['nazione'] = (string)$sede->Nazione ?: 'IT';
  619. // Email, se presente
  620. $data['email'] = '';
  621. if (isset($cedenteNode->Contatti) && isset($cedenteNode->Contatti->Email)) {
  622. $data['email'] = (string)$cedenteNode->Contatti->Email;
  623. }
  624. // Dati generali della fattura
  625. $datiGeneraliDocumento = $bodyNode->DatiGenerali->DatiGeneraliDocumento;
  626. $data['tipoDocumento'] = (string)$datiGeneraliDocumento->TipoDocumento;
  627. $data['divisa'] = (string)$datiGeneraliDocumento->Divisa ?: 'EUR';
  628. $data['dataDocumento'] = (string)$datiGeneraliDocumento->Data;
  629. $data['numeroFattura'] = (string)$datiGeneraliDocumento->Numero;
  630. $data['importoTotale'] = (float)$datiGeneraliDocumento->ImportoTotaleDocumento;
  631. // Dati di pagamento
  632. $data['condizioniPagamento'] = '';
  633. $data['modalitaPagamento'] = '';
  634. $data['dataScadenza'] = '';
  635. $data['iban'] = '';
  636. $data['bic'] = '';
  637. $data['istitutoFinanziario'] = '';
  638. if (isset($bodyNode->DatiPagamento)) {
  639. $datiPagamento = $bodyNode->DatiPagamento;
  640. $data['condizioniPagamento'] = (string)$datiPagamento->CondizioniPagamento;
  641. if (isset($datiPagamento->DettaglioPagamento)) {
  642. $dettaglioPagamento = $datiPagamento->DettaglioPagamento;
  643. $data['modalitaPagamento'] = (string)$dettaglioPagamento->ModalitaPagamento;
  644. $data['dataScadenza'] = (string)$dettaglioPagamento->DataScadenzaPagamento;
  645. $data['iban'] = (string)$dettaglioPagamento->IBAN;
  646. $data['bic'] = (string)$dettaglioPagamento->BIC;
  647. $data['istitutoFinanziario'] = (string)$dettaglioPagamento->IstitutoFinanziario;
  648. }
  649. }
  650. // Estrai le linee di dettaglio
  651. $data['linee'] = [];
  652. if (isset($bodyNode->DatiBeniServizi) && isset($bodyNode->DatiBeniServizi->DettaglioLinee)) {
  653. foreach ($bodyNode->DatiBeniServizi->DettaglioLinee as $index => $linea) {
  654. $lineaData = [
  655. 'numeroLinea' => (int)($linea->NumeroLinea ?? ($index + 1)),
  656. 'descrizione' => (string)($linea->Descrizione ?? ''),
  657. 'quantita' => (float)($linea->Quantita ?? 1),
  658. 'prezzoUnitario' => (float)($linea->PrezzoUnitario ?? 0),
  659. 'prezzoTotale' => (float)($linea->PrezzoTotale ?? 0),
  660. 'aliquotaIva' => (float)($linea->AliquotaIVA ?? 0),
  661. ];
  662. // Calcola il prezzo totale se non presente
  663. if ($lineaData['prezzoTotale'] == 0) {
  664. $lineaData['prezzoTotale'] = $lineaData['quantita'] * $lineaData['prezzoUnitario'];
  665. }
  666. $data['linee'][] = $lineaData;
  667. }
  668. }
  669. $data['riepilogo'] = null;
  670. if (isset($bodyNode->DatiBeniServizi) && isset($bodyNode->DatiBeniServizi->DatiRiepilogo)) {
  671. $riepilogoNode = $bodyNode->DatiBeniServizi->DatiRiepilogo;
  672. if ($riepilogoNode) {
  673. $data['riepilogo'] = [
  674. 'aliquotaIva' => (float)($riepilogoNode->AliquotaIVA ?? 0),
  675. 'imponibile' => (float)($riepilogoNode->ImponibileImporto ?? 0),
  676. 'imposta' => (float)($riepilogoNode->Imposta ?? 0),
  677. ];
  678. }
  679. }
  680. Log::info("Dati estratti dalla fattura: P.IVA={$data['partitaIva']}, Denominazione={$data['denominazione']}, Numero={$data['numeroFattura']}, Importo={$data['importoTotale']}");
  681. return $data;
  682. } catch (\Exception $e) {
  683. Log::error("Errore nell'estrazione dei dati XML: " . $e->getMessage());
  684. throw $e;
  685. }
  686. }
  687. /**
  688. * Trova o crea un fornitore basato sui dati della fattura
  689. */
  690. private function findOrCreateSupplier($fatturaData)
  691. {
  692. $supplier = \App\Models\Supplier::where('vat', $fatturaData['partitaIva'])->first();
  693. if (!$supplier) {
  694. Log::info("Creazione nuovo fornitore con P.IVA: {$fatturaData['partitaIva']} ({$fatturaData['denominazione']})");
  695. $countryId = $this->getCountryId($fatturaData['nazione']);
  696. $provinceId = $this->getProvinceId($fatturaData['provincia']);
  697. $cityId = $this->getCityId($fatturaData['comune']);
  698. $supplier = new \App\Models\Supplier();
  699. $supplier->name = $fatturaData['denominazione'];
  700. $supplier->vat = $fatturaData['partitaIva'];
  701. $supplier->fiscal_code = $fatturaData['codiceFiscale'];
  702. $supplier->address = $fatturaData['indirizzo'];
  703. $supplier->city_id = $cityId;
  704. $supplier->cap = $fatturaData['cap'];
  705. $supplier->province_id = $provinceId;
  706. $supplier->country_id = $countryId;
  707. $supplier->email = $fatturaData['email'];
  708. $supplier->save();
  709. Log::info("Fornitore creato con ID: " . $supplier->id);
  710. }
  711. return $supplier;
  712. }
  713. /**
  714. * Trova l'ID della nazione dal codice
  715. */
  716. private function getCountryId($nationCode)
  717. {
  718. $country = DB::table('nations')->where('code', $nationCode)->first();
  719. return $country ? $country->id : null;
  720. }
  721. /**
  722. * Trova l'ID della provincia dal codice
  723. */
  724. private function getProvinceId($provinceCode)
  725. {
  726. $province = DB::table('provinces')->where('code', $provinceCode)->first();
  727. return $province ? $province->id : null;
  728. }
  729. /**
  730. * Trova l'ID della città dal nome
  731. */
  732. private function getCityId($cityName)
  733. {
  734. if (empty($cityName)) return null;
  735. $city = DB::table('cities')->where('name', $cityName)->first();
  736. return $city ? $city->id : null;
  737. }
  738. /**
  739. * Trova l'ID del metodo di pagamento dal codice
  740. */
  741. private function findPaymentMethod($paymentCode)
  742. {
  743. if (!empty($paymentCode)) {
  744. $paymentMethod = DB::table('payment_methods')->where('code', $paymentCode)->first();
  745. if ($paymentMethod) {
  746. Log::info("Metodo di pagamento trovato: $paymentCode (ID: {$paymentMethod->id})");
  747. return $paymentMethod->id;
  748. }
  749. }
  750. $defaultPaymentMethod = DB::table('payment_methods')->where('default', 1)->first()
  751. ?? DB::table('payment_methods')->first();
  752. if ($defaultPaymentMethod) {
  753. Log::info("Usando metodo di pagamento predefinito ID: {$defaultPaymentMethod->id}");
  754. return $defaultPaymentMethod->id;
  755. }
  756. throw new \Exception("Nessun metodo di pagamento disponibile nel sistema");
  757. }
  758. /**
  759. * Crea un record nella tabella records
  760. */
  761. private function createRecord($supplierId, $paymentMethodId, $fatturaData)
  762. {
  763. $record = new \App\Models\Record();
  764. $record->supplier_id = $supplierId;
  765. $record->payment_method_id = $paymentMethodId;
  766. $record->date = $fatturaData['dataDocumento'];
  767. $record->type = 'OUT';
  768. $record->commercial = 0;
  769. $record->corrispettivo_fiscale = 0;
  770. $record->deleted = 0;
  771. $record->financial_movement = 1;
  772. $record->amount = $fatturaData['importoTotale'];
  773. $record->save();
  774. Log::info("Record creato con ID: " . $record->id);
  775. return $record;
  776. }
  777. /**
  778. * Crea un record row per il record specificato
  779. */
  780. private function createRecordRow($recordId, $fatturaData)
  781. {
  782. Log::info("Inizio creazione RecordRow per Record ID: " . $recordId);
  783. $dataObj = new \DateTime($fatturaData['dataDocumento']);
  784. $month = $dataObj->format('n');
  785. $year = $dataObj->format('Y');
  786. $period = "$month-$year";
  787. $whenData = [[
  788. 'month' => $month,
  789. 'year' => $year,
  790. 'period' => $period
  791. ]];
  792. Log::info("Dati whenData: " . json_encode($whenData));
  793. $recordRow = new \App\Models\RecordRow();
  794. $recordRow->record_id = $recordId;
  795. $recordRow->causal_id = $this->selectedCausal;
  796. $recordRow->when = json_encode($whenData);
  797. $recordRow->amount = $fatturaData['importoTotale'];
  798. $recordRow->commercial = 0;
  799. $noteData = '';
  800. if (isset($fatturaData['linee']) && is_array($fatturaData['linee'])) {
  801. $descriptions = array_map(function ($linea) {
  802. return $linea['descrizione'];
  803. }, $fatturaData['linee']);
  804. $noteData = implode(', ', $descriptions);
  805. }
  806. $recordRow->note = $noteData;
  807. Log::info("Dati RecordRow prima del salvataggio: " . json_encode([
  808. 'record_id' => $recordRow->record_id,
  809. 'causal_id' => $recordRow->causal_id,
  810. 'when' => $recordRow->when,
  811. 'amount' => $recordRow->amount,
  812. 'commercial' => $recordRow->commercial,
  813. 'note' => $recordRow->note
  814. ]));
  815. $recordRow->save();
  816. Log::info("RecordRow creato per il Record ID: " . $recordId);
  817. return $recordRow;
  818. }
  819. /**
  820. * Crea una ricevuta collegata al record
  821. */
  822. private function createReceipt($recordId, $supplierId, $paymentMethodId, $fatturaData)
  823. {
  824. Log::info("Inizio creazione ricevuta per Record ID: " . $recordId);
  825. $receipt = new \App\Models\Receipt();
  826. $receipt->record_id = $recordId;
  827. $receipt->supplier_id = $supplierId;
  828. $receipt->payment_method_id = $paymentMethodId;
  829. $receipt->date = $fatturaData['dataDocumento'];
  830. $receipt->data_documento = $fatturaData['dataDocumento'];
  831. $receipt->numero_fattura = $fatturaData['numeroFattura'];
  832. $receipt->number = preg_replace('/[^0-9]/', '', $fatturaData['numeroFattura']);
  833. $receipt->tipo_documento = $this->mapTipoDocumento($fatturaData['tipoDocumento']);
  834. $receipt->year = date('Y', strtotime($fatturaData['dataDocumento']));
  835. $receipt->type = 'OUT';
  836. $receipt->status = 1;
  837. $receipt->is_ricevuta = true;
  838. if (isset($fatturaData['condizioniPagamento']) && !empty($fatturaData['condizioniPagamento'])) {
  839. $receipt->condizioni_pagamento = $this->mapCondizioniPagamento($fatturaData['condizioniPagamento']);
  840. }
  841. if (isset($fatturaData['iban']) && !empty($fatturaData['iban'])) {
  842. $receipt->IBAN = $fatturaData['iban'];
  843. }
  844. if (isset($fatturaData['bic']) && !empty($fatturaData['bic'])) {
  845. $receipt->BIC = $fatturaData['bic'];
  846. }
  847. if (isset($fatturaData['dataScadenza']) && !empty($fatturaData['dataScadenza'])) {
  848. $receipt->data_scadenza = $fatturaData['dataScadenza'];
  849. }
  850. Log::info("Dati ricevuta prima del salvataggio: " . json_encode([
  851. 'record_id' => $receipt->record_id,
  852. 'supplier_id' => $receipt->supplier_id,
  853. 'payment_method_id' => $receipt->payment_method_id,
  854. 'date' => $receipt->date,
  855. 'number' => $receipt->number,
  856. 'tipo_documento' => $receipt->tipo_documento,
  857. 'year' => $receipt->year,
  858. 'type' => $receipt->type,
  859. 'status' => $receipt->status,
  860. ]));
  861. $receipt->save();
  862. Log::info("Ricevuta creata con ID: " . $receipt->id);
  863. return $receipt;
  864. }
  865. private function createReceiptRows($receiptId, $fatturaData)
  866. {
  867. Log::info("Inizio creazione righe ricevuta per Ricevuta ID: " . $receiptId);
  868. if (!empty($fatturaData['linee'])) {
  869. foreach ($fatturaData['linee'] as $linea) {
  870. $this->createSingleReceiptRow($receiptId, $fatturaData, $linea);
  871. }
  872. } else if ($fatturaData['riepilogo']) {
  873. $this->createReceiptRowFromRiepilogo($receiptId, $fatturaData);
  874. Log::info("Creata una riga di ricevuta dai dati di riepilogo");
  875. } else {
  876. $this->createDefaultReceiptRow($receiptId, $fatturaData);
  877. Log::info("Creata una riga di ricevuta predefinita dall'importo totale");
  878. }
  879. }
  880. private function createSingleReceiptRow($receiptId, $fatturaData, $linea)
  881. {
  882. Log::info("Inizio creazione riga ricevuta singola per Ricevuta ID: " . $receiptId . ", Linea: " . json_encode($linea));
  883. $dataObj = new \DateTime($fatturaData['dataDocumento']);
  884. $month = $dataObj->format('n');
  885. $year = $dataObj->format('Y');
  886. $period = "$month-$year";
  887. $whenData = [[
  888. 'month' => $month,
  889. 'year' => $year,
  890. 'period' => $period
  891. ]];
  892. $receiptRow = new \App\Models\ReceiptRow();
  893. $receiptRow->receip_id = $receiptId;
  894. $receiptRow->causal_id = $this->selectedCausal;
  895. $receiptRow->amount = $linea['prezzoTotale'];
  896. $receiptRow->note = $linea['descrizione'];
  897. $receiptRow->commercial = true;
  898. $receiptRow->when = json_encode($whenData);
  899. $receiptRow->aliquota_iva = $linea['aliquotaIva'];
  900. $receiptRow->imponibile = $linea['prezzoTotale'];
  901. $receiptRow->imposta = $linea['prezzoTotale'] * ($linea['aliquotaIva'] / 100);
  902. $receiptRow->divisa = $fatturaData['divisa'];
  903. $receiptRow->numero_linea = $linea['numeroLinea'];
  904. $receiptRow->prezzo_unitario = $linea['prezzoUnitario'];
  905. $receiptRow->quantita = $linea['quantita'];
  906. Log::info("Dati riga ricevuta prima del salvataggio: " . json_encode([
  907. 'receip_id' => $receiptRow->receip_id,
  908. 'causal_id' => $receiptRow->causal_id,
  909. 'amount' => $receiptRow->amount,
  910. 'note' => $receiptRow->note,
  911. 'aliquota_iva' => $receiptRow->aliquota_iva,
  912. 'imponibile' => $receiptRow->imponibile,
  913. 'imposta' => $receiptRow->imposta,
  914. 'divisa' => $receiptRow->divisa,
  915. 'numero_linea' => $receiptRow->numero_linea,
  916. 'prezzo_unitario' => $receiptRow->prezzo_unitario,
  917. 'quantita' => $receiptRow->quantita,
  918. ]));
  919. $receiptRow->save();
  920. Log::info("Riga ricevuta creata per linea {$linea['numeroLinea']}: {$linea['descrizione']} (€{$linea['prezzoTotale']})");
  921. }
  922. private function createReceiptRowFromRiepilogo($receiptId, $fatturaData)
  923. {
  924. Log::info("Inizio creazione riga ricevuta da riepilogo per Ricevuta ID: " . $receiptId . ", Riepilogo: " . json_encode($fatturaData['riepilogo']));
  925. $riepilogo = $fatturaData['riepilogo'];
  926. $dataObj = new \DateTime($fatturaData['dataDocumento']);
  927. $month = $dataObj->format('n');
  928. $year = $dataObj->format('Y');
  929. $period = "$month-$year";
  930. $whenData = [[
  931. 'month' => $month,
  932. 'year' => $year,
  933. 'period' => $period
  934. ]];
  935. $receiptRow = new \App\Models\ReceiptRow();
  936. $receiptRow->receip_id = $receiptId;
  937. $receiptRow->causal_id = $this->selectedCausal;
  938. $receiptRow->amount = $riepilogo['imponibile'];
  939. $receiptRow->commercial = true;
  940. $receiptRow->when = json_encode($whenData);
  941. $receiptRow->aliquota_iva = $riepilogo['aliquotaIva'];
  942. $receiptRow->imponibile = $riepilogo['imponibile'];
  943. $receiptRow->imposta = $riepilogo['imposta'];
  944. $receiptRow->divisa = $fatturaData['divisa'];
  945. $receiptRow->numero_linea = 1;
  946. $receiptRow->quantita = 1;
  947. Log::info("Dati riga ricevuta da riepilogo prima del salvataggio: " . json_encode([
  948. 'receip_id' => $receiptRow->receip_id,
  949. 'causal_id' => $receiptRow->causal_id,
  950. 'amount' => $receiptRow->amount,
  951. 'aliquota_iva' => $receiptRow->aliquota_iva,
  952. 'imponibile' => $receiptRow->imponibile,
  953. 'imposta' => $receiptRow->imposta,
  954. 'divisa' => $receiptRow->divisa,
  955. ]));
  956. $receiptRow->save();
  957. Log::info("Riga ricevuta creata da riepilogo: Imponibile={$riepilogo['imponibile']}, IVA={$riepilogo['aliquotaIva']}%");
  958. }
  959. private function createDefaultReceiptRow($receiptId, $fatturaData)
  960. {
  961. Log::info("Inizio creazione riga ricevuta predefinita per Ricevuta ID: " . $receiptId . ", Importo Totale: " . $fatturaData['importoTotale']);
  962. $dataObj = new \DateTime($fatturaData['dataDocumento']);
  963. $month = $dataObj->format('n');
  964. $year = $dataObj->format('Y');
  965. $period = "$month-$year";
  966. $whenData = [[
  967. 'month' => $month,
  968. 'year' => $year,
  969. 'period' => $period
  970. ]];
  971. $receiptRow = new \App\Models\ReceiptRow();
  972. $receiptRow->receip_id = $receiptId;
  973. $receiptRow->causal_id = $this->selectedCausal;
  974. $receiptRow->amount = $fatturaData['importoTotale'];
  975. $receiptRow->commercial = true;
  976. $receiptRow->when = json_encode($whenData);
  977. $receiptRow->divisa = $fatturaData['divisa'];
  978. $receiptRow->numero_linea = 1;
  979. $receiptRow->quantita = 1;
  980. Log::info("Dati riga ricevuta predefinita prima del salvataggio: " . json_encode([
  981. 'receip_id' => $receiptRow->receip_id,
  982. 'causal_id' => $receiptRow->causal_id,
  983. 'amount' => $receiptRow->amount,
  984. 'divisa' => $receiptRow->divisa,
  985. ]));
  986. $receiptRow->save();
  987. Log::info("Riga ricevuta predefinita creata con importo totale: {$fatturaData['importoTotale']}");
  988. }
  989. private function mapTipoDocumento($codice)
  990. {
  991. $tipiDocumento = [
  992. 'TD01' => 'Fattura',
  993. 'TD02' => 'Acconto/Anticipo su fattura',
  994. 'TD03' => 'Acconto/Anticipo su parcella',
  995. 'TD04' => 'Nota di credito',
  996. 'TD05' => 'Nota di debito',
  997. 'TD06' => 'Parcella',
  998. 'TD16' => 'Integrazione fattura reverse charge interno',
  999. 'TD17' => 'Integrazione/autofattura per acquisto servizi dall\'estero',
  1000. 'TD18' => 'Integrazione per acquisto di beni intracomunitari',
  1001. 'TD19' => 'Integrazione/autofattura per acquisto di beni ex art.17 c.2 DPR 633/72',
  1002. 'TD20' => 'Autofattura per regolarizzazione e integrazione delle fatture',
  1003. 'TD21' => 'Autofattura per splafonamento',
  1004. 'TD22' => 'Estrazione beni da Deposito IVA',
  1005. 'TD23' => 'Estrazione beni da Deposito IVA con versamento dell\'IVA',
  1006. 'TD24' => 'Fattura differita di cui all\'art.21, comma 4, lett. a)',
  1007. 'TD25' => 'Fattura differita di cui all\'art.21, comma 4, terzo periodo lett. b)',
  1008. 'TD26' => 'Cessione di beni ammortizzabili e per passaggi interni',
  1009. 'TD27' => 'Fattura per autoconsumo o per cessioni gratuite senza rivalsa'
  1010. ];
  1011. return $tipiDocumento[$codice] ?? $codice;
  1012. }
  1013. private function mapCondizioniPagamento($codice)
  1014. {
  1015. $condizioniPagamento = [
  1016. 'TP01' => 'Pagamento a rate',
  1017. 'TP02' => 'Pagamento completo',
  1018. 'TP03' => 'Anticipo'
  1019. ];
  1020. return $condizioniPagamento[$codice] ?? $codice;
  1021. }
  1022. private function showResultMessages($importCount, $errorsCount)
  1023. {
  1024. if ($importCount > 0) {
  1025. $message = "Importate $importCount fatture con successo.";
  1026. if ($errorsCount > 0) {
  1027. $message .= " $errorsCount fatture non sono state importate.";
  1028. }
  1029. session()->flash('message', $message);
  1030. } else {
  1031. session()->flash('error', 'Nessuna fattura importata. Controlla i file XML e riprova.');
  1032. }
  1033. }
  1034. }