RecordINOUT.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  5. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  6. use Illuminate\Support\Facades\Log;
  7. use SimpleXMLElement;
  8. use Illuminate\Support\Facades\Auth;
  9. class RecordINOUT extends Component
  10. {
  11. //public $records_in, $records_out;
  12. public $total_in = 0;
  13. public $total_out = 0;
  14. public $datas = [];
  15. public $month;
  16. public $year;
  17. public $months_1 = [];
  18. public $year_1;
  19. public $months_2 = [];
  20. public $year_2;
  21. public $show_block_2;
  22. //public $borsellino_id = 0;
  23. public $columns = array();
  24. public $rows_in = array();
  25. public $rows_out = array();
  26. public $records_in = array();
  27. public $records_out = array();
  28. public $showData = true;
  29. public $hasFilter = false;
  30. public $total = 0;
  31. public $selectedFilter = '';
  32. public $causalsIn = array();
  33. public $causalsOut = array();
  34. public $payments = array();
  35. public $members = array();
  36. public $filterCausalsIn = null;
  37. public $filterCausalsOut = null;
  38. public $excludeCausals = array();
  39. public function mount()
  40. {
  41. if(Auth::user()->level != env('LEVEL_ADMIN', 0))
  42. return redirect()->to('/dashboard');
  43. $borsellino = \App\Models\Causal::where('money', true)->first();
  44. if ($borsellino)
  45. $this->excludeCausals[] = $borsellino->id;
  46. //$this->borsellino_id = $borsellino->id;
  47. // Aggiungo
  48. $excludes = \App\Models\Causal::where('no_records', true)->get();
  49. foreach($excludes as $e)
  50. {
  51. $this->excludeCausals[] = $e->id;
  52. }
  53. $this->month = date("m");
  54. $this->year = date("Y");
  55. $this->year_1 = date("Y");
  56. $this->year_2 = date("Y");
  57. $this->show_block_2 = false;
  58. $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->whereNotIn('id', $this->excludeCausals)->get(), 'IN', 0);
  59. $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'OUT')->whereNotIn('id', $this->excludeCausals)->get(), 'OUT', 0);
  60. $this->getCausalsIn(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->get(), 0);
  61. $this->getCausalsOut(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'OUT')->get(), 0);
  62. //$this->causalsIn = \App\Models\Causal::where('parent_id', null)->where('type', 'IN')->whereNotIn('id', $this->excludeCausals)->get();
  63. //$this->causalsOut = \App\Models\Causal::where('parent_id', null)->where('type', 'OUT')->whereNotIn('id', $this->excludeCausals)->get();
  64. }
  65. public function getCausalsIn($records, $indentation)
  66. {
  67. foreach($records as $record)
  68. {
  69. $this->causalsIn[] = array('id' => $record->id, 'name' => $record->getTree(), 'text' => $record->getTree(), 'level' => $indentation);
  70. if(count($record->childs))
  71. $this->getCausalsIn($record->childs, $indentation + 1);
  72. }
  73. }
  74. public function getCausalsOut($records, $indentation)
  75. {
  76. foreach($records as $record)
  77. {
  78. $this->causalsOut[] = array('id' => $record->id, 'name' => $record->getTree(), 'text' => $record->getTree(), 'level' => $indentation);
  79. if(count($record->childs))
  80. $this->getCausalsOut($record->childs, $indentation + 1);
  81. }
  82. }
  83. public function getCausale($records, $type, $indentation)
  84. {
  85. foreach($records as $record)
  86. {
  87. $first_parent_id = null;
  88. if ($record->parent_id != null)
  89. {
  90. $first_parent_id = \App\Models\Causal::where('id', $record->parent_id)->first()->parent_id;
  91. }
  92. if ($type == 'IN')
  93. $this->rows_in[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id), 'all_childs' => $this->getAllChild($record->id));
  94. if ($type == 'OUT')
  95. $this->rows_out[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id), 'all_childs' => $this->getAllChild($record->id));
  96. if(count($record->childs))
  97. $this->getCausale($record->childs, $type, $indentation + 1);
  98. }
  99. }
  100. public function getAllChild($id)
  101. {
  102. $aChilds = array();
  103. $aChilds[] = $id;
  104. $record = \App\Models\Causal::findOrFail($id);
  105. $aChilds[] = $record->parent_id;
  106. if ($record->parent_id != null)
  107. {
  108. $first_parent_id = \App\Models\Causal::where('id', $record->parent_id)->first()->parent_id;
  109. $aChilds[] = $first_parent_id;
  110. }
  111. $childs = \App\Models\Causal::where('parent_id', $id)->get();
  112. foreach($childs as $child)
  113. {
  114. $aChilds[] = $child->id;
  115. $childs2 = \App\Models\Causal::where('parent_id', $child->id)->get();
  116. foreach($childs2 as $child2)
  117. {
  118. $aChilds[] = $child2->id;
  119. $childs3 = \App\Models\Causal::where('parent_id', $child2->id)->get();
  120. foreach($childs3 as $child3)
  121. {
  122. $aChilds[] = $child3->id;
  123. }
  124. }
  125. }
  126. return $aChilds;
  127. }
  128. public function getCausalName($id)
  129. {
  130. if ($id > 0)
  131. return \App\Models\Causal::findOrFail($id)->name;
  132. else
  133. return "";
  134. }
  135. public function render()
  136. {
  137. return view('livewire.records_in_out');
  138. }
  139. public function hydrate()
  140. {
  141. $this->emit('load-select');
  142. }
  143. public function show($m, $y)
  144. {
  145. if ($m != "" && $y != "" && !in_array($m . "-" . $y, $this->datas))
  146. $this->datas[] = $m . "-" . $y;
  147. $this->columns = array();
  148. $this->records_in = [];
  149. $this->records_out = [];
  150. $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
  151. if (sizeof($this->datas) > 0)
  152. {
  153. foreach($this->datas as $filter)
  154. {
  155. $this->columns[] = $filter;
  156. $f = $filter;
  157. if ($m == 'x')
  158. $f = str_replace("x-", "", $filter);
  159. $records = \App\Models\Record::where('type', 'IN')
  160. ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
  161. ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
  162. ->where(function ($query) {
  163. $query->where('deleted', false)->orWhere('deleted', null);
  164. })
  165. ->where(function ($query) {
  166. $query->where('financial_movement', false)->orWhere('financial_movement', null);
  167. })
  168. ->whereNotIn('member_id', $exclude_from_records)
  169. ->where('records_rows.when', 'like', '%"' . $f . '"%')
  170. ->get();
  171. foreach($records as $record)
  172. {
  173. $amount = $record->amount;
  174. $amount += getVatValue($amount, $record->vat_id);
  175. $when = sizeof(json_decode($record->when));
  176. if ($when > 1)
  177. {
  178. $amount = $amount / $when;
  179. $record->amount = $amount;
  180. }
  181. // Aggiungo/aggiorno i dati
  182. if (isset($this->records_in[$filter][$record->causal_id]))
  183. $this->records_in[$filter][$record->causal_id] += $amount;
  184. else
  185. $this->records_in[$filter][$record->causal_id] = $amount;
  186. // Aggiorno i dati del padre
  187. $this->updateParent("IN", $record->causal_id, $amount, $filter);
  188. }
  189. $records = \App\Models\Record::where('type', 'OUT')
  190. ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
  191. ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
  192. ->where(function ($query) {
  193. $query->where('deleted', false)->orWhere('deleted', null);
  194. })
  195. ->where(function ($query) {
  196. $query->where('financial_movement', false)->orWhere('financial_movement', null);
  197. })
  198. ->orWhere(function ($subquery) use ($exclude_from_records) {
  199. $subquery->whereNotIn('member_id', $exclude_from_records);
  200. })
  201. ->where('records_rows.when', 'like', '%"' . $f . '"%')->get();
  202. foreach($records as $record)
  203. {
  204. $amount = $record->amount;
  205. $amount += getVatValue($amount, $record->vat_id);
  206. $when = sizeof(json_decode($record->when));
  207. if ($when > 1)
  208. {
  209. $amount = $amount / $when;
  210. $record->amount = $amount;
  211. }
  212. // Aggiungo/aggiorno i dati
  213. if (isset($this->records_out[$filter][$record->causal_id]))
  214. $this->records_out[$filter][$record->causal_id] += $amount;
  215. else
  216. $this->records_out[$filter][$record->causal_id] = $amount;
  217. $this->updateParent("OUT", $record->causal_id, $amount, $filter);
  218. }
  219. }
  220. }
  221. //$this->showData = true;
  222. $this->emit('load-table');
  223. }
  224. public function updateParent($type, $causal_id, $amount, $filter)
  225. {
  226. if ($type == "IN")
  227. {
  228. foreach($this->rows_in as $r)
  229. {
  230. if ($r["id"] == $causal_id)
  231. {
  232. if (isset($this->records_in[$filter][$r["parent_id"]]))
  233. $this->records_in[$filter][$r["parent_id"]] += $amount;
  234. else
  235. $this->records_in[$filter][$r["parent_id"]] = $amount;
  236. if ($r["parent_id"] > 0)
  237. $this->updateParent("IN", $r["parent_id"], $amount, $filter);
  238. }
  239. }
  240. }
  241. if ($type == "OUT")
  242. {
  243. foreach($this->rows_out as $r)
  244. {
  245. if ($r["id"] == $causal_id)
  246. {
  247. if (isset($this->records_out[$filter][$r["parent_id"]]))
  248. $this->records_out[$filter][$r["parent_id"]] += $amount;
  249. else
  250. $this->records_out[$filter][$r["parent_id"]] = $amount;
  251. if ($r["parent_id"] > 0)
  252. $this->updateParent("OUT", $r["parent_id"], $amount, $filter);
  253. }
  254. }
  255. }
  256. }
  257. public function updateParentYear($type, $causal_id, $amount, $filter, &$records_in, &$records_out)
  258. {
  259. if ($type == "IN")
  260. {
  261. foreach($this->rows_in as $r)
  262. {
  263. if ($r["id"] == $causal_id)
  264. {
  265. if (isset($records_in[$filter][$r["parent_id"]]))
  266. $records_in[$filter][$r["parent_id"]] += $amount;
  267. else
  268. $records_in[$filter][$r["parent_id"]] = $amount;
  269. if ($r["parent_id"] > 0)
  270. $this->updateParentYear("IN", $r["parent_id"], $amount, $filter, $records_in, $records_out);
  271. }
  272. }
  273. }
  274. if ($type == "OUT")
  275. {
  276. foreach($this->rows_out as $r)
  277. {
  278. if ($r["id"] == $causal_id)
  279. {
  280. if (isset($records_out[$filter][$r["parent_id"]]))
  281. $records_out[$filter][$r["parent_id"]] += $amount;
  282. else
  283. $records_out[$filter][$r["parent_id"]] = $amount;
  284. if ($r["parent_id"] > 0)
  285. $this->updateParentYear("OUT", $r["parent_id"], $amount, $filter, $records_in, $records_out);
  286. }
  287. }
  288. }
  289. }
  290. public function getCausal($causal)
  291. {
  292. $ret = '';
  293. if ($causal > 0)
  294. {
  295. $ret = \App\Models\Causal::findOrFail($causal)->getTree();
  296. }
  297. return $ret;
  298. }
  299. public function getMonth($str)
  300. {
  301. $ret = '';
  302. list($m, $y) = explode("-", $str);
  303. switch ($m) {
  304. case 'x':
  305. $ret = '';
  306. break;
  307. case '01':
  308. $ret = 'Gennaio ';
  309. break;
  310. case '02':
  311. $ret = 'Febbraio ';
  312. break;
  313. case '03':
  314. $ret = 'Marzo ';
  315. break;
  316. case '04':
  317. $ret = 'Aprile ';
  318. break;
  319. case '05':
  320. $ret = 'Maggio ';
  321. break;
  322. case '06':
  323. $ret = 'Giugno ';
  324. break;
  325. case '07':
  326. $ret = 'Luglio ';
  327. break;
  328. case '08':
  329. $ret = 'Agosto ';
  330. break;
  331. case '09':
  332. $ret = 'Settembre ';
  333. break;
  334. case '10':
  335. $ret = 'Ottobre ';
  336. break;
  337. case '11':
  338. $ret = 'Novembre ';
  339. break;
  340. case '12':
  341. $ret = 'Dicembre ';
  342. break;
  343. default:
  344. $ret = '';
  345. break;
  346. }
  347. $ret .= $y;
  348. return $ret;
  349. }
  350. public function clear()
  351. {
  352. $this->columns = [];
  353. $this->datas = [];
  354. $this->records_out = [];
  355. $this->records_in = [];
  356. $this->emit('load-select');
  357. $this->emit('reset-collapse');
  358. //$this->showData = false;
  359. }
  360. public function remove($idx)
  361. {
  362. if (sizeof($this->datas) > 1)
  363. array_splice($this->datas, $idx, 1);
  364. //unset($this->datas[$idx]);
  365. else
  366. $this->datas = array();
  367. $this->show('', '');
  368. }
  369. public function export()
  370. {
  371. $rows_in = array();
  372. if ($this->filterCausalsIn != null && sizeof($this->filterCausalsIn) > 0)
  373. {
  374. foreach($this->rows_in as $r)
  375. {
  376. if (in_array($r["id"], $this->filterCausalsIn) || in_array($r["parent_id"], $this->filterCausalsIn) || in_array($r["first_parent_id"], $this->filterCausalsIn))
  377. {
  378. $rows_in[] = $r;
  379. }
  380. }
  381. }
  382. else
  383. {
  384. $rows_in = $this->rows_in;
  385. }
  386. $path = $this->generateExcel($this->columns, $rows_in, $this->records_in, $this->rows_out, $this->records_out,false);
  387. return response()->download($path)->deleteFileAfterSend();
  388. }
  389. public function exportYear($year)
  390. {
  391. $records_in = [];
  392. $records_out = [];
  393. $datas = [];
  394. if (env('FISCAL_YEAR_MONTH_FROM', 1) > 1)
  395. {
  396. for($m=env('FISCAL_YEAR_MONTH_FROM', 1);$m<=12;$m++)
  397. {
  398. $datas[] = $m . "-" . $year;
  399. }
  400. for($m=1;$m<=env('FISCAL_YEAR_MONTH_TO', 12);$m++)
  401. {
  402. $datas[] = $m . "-" . ($year + 1);
  403. }
  404. }
  405. else
  406. {
  407. for($m=1;$m<=12;$m++)
  408. {
  409. $datas[] = $m . "-" . $year;
  410. }
  411. }
  412. $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
  413. foreach($datas as $filter)
  414. {
  415. $columns[] = $filter;
  416. $records = \App\Models\Record::where('type', 'IN')
  417. ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
  418. ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
  419. ->where(function ($query) {
  420. $query->where('deleted', false)->orWhere('deleted', null);
  421. })
  422. ->where(function ($query) {
  423. $query->where('financial_movement', false)->orWhere('financial_movement', null);
  424. })
  425. ->whereNotIn('member_id', $exclude_from_records)
  426. ->where('records_rows.when', 'like', '%"' . $filter . '"%')->get();
  427. //$records = $records->orderBy('date', 'DESC')->get();
  428. foreach($records as $record)
  429. {
  430. $amount = $record->amount;
  431. $amount += getVatValue($amount, $record->vat_id);
  432. $when = sizeof(json_decode($record->when));
  433. if ($when > 1)
  434. {
  435. $amount = $amount / $when;
  436. $record->amount = $amount;
  437. }
  438. // Aggiungo/aggiorno i dati
  439. if (isset($records_in[$filter][$record->causal_id]))
  440. $records_in[$filter][$record->causal_id] += $amount;
  441. else
  442. $records_in[$filter][$record->causal_id] = $amount;
  443. // Aggiorno i dati del padre
  444. $this->updateParentYear("IN", $record->causal_id, $amount, $filter, $records_in, $records_out);
  445. }
  446. $records = \App\Models\Record::where('type', 'OUT')
  447. ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
  448. ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
  449. ->where(function ($query) {
  450. $query->where('deleted', false)->orWhere('deleted', null);
  451. })
  452. ->where(function ($query) {
  453. $query->where('financial_movement', false)->orWhere('financial_movement', null);
  454. })
  455. ->whereNotIn('member_id', $exclude_from_records)
  456. ->where('records_rows.when', 'like', '%"' . $filter . '"%')->get();
  457. //$records = $records->orderBy('date', 'DESC')->get();
  458. foreach($records as $record)
  459. {
  460. $amount = $record->amount;
  461. $when = sizeof(json_decode($record->when));
  462. if ($when > 1)
  463. {
  464. $amount = $amount / $when;
  465. $record->amount = $amount;
  466. }
  467. // Aggiungo/aggiorno i dati
  468. if (isset($records_out[$filter][$record->causal_id]))
  469. $records_out[$filter][$record->causal_id] += $amount;
  470. else
  471. $records_out[$filter][$record->causal_id] = $amount;
  472. $this->updateParentYear("OUT", $record->causal_id, $amount, $filter, $records_in, $records_out);
  473. }
  474. }
  475. $path = $this->generateExcel($columns, $this->rows_in, $records_in, $this->rows_out, $records_out, true);
  476. return response()->download($path)->deleteFileAfterSend();
  477. }
  478. public function generateExcel($columns, $rows_in, $records_in, $rows_out, $records_out, $isYearExport)
  479. {
  480. $letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N');
  481. $spreadsheet = new Spreadsheet();
  482. $activeWorksheet = $spreadsheet->getActiveSheet();
  483. $activeWorksheet->setCellValue('A1', 'Entrate');
  484. foreach($columns as $idx => $column)
  485. {
  486. $activeWorksheet->setCellValue($letters[$idx + 1] . '1', $this->getMonth($column));
  487. }
  488. $activeWorksheet->getStyle('A1:N1')->getFont()->setBold(true);
  489. $activeWorksheet->getStyle('A1:N1')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('C6E0B4'); // Lighter green
  490. $count = 2;
  491. $totals = [];
  492. foreach($rows_in as $in)
  493. {
  494. $activeWorksheet->setCellValue('A' . $count, str_repeat(" ", $in["level"]) . $in["name"]);
  495. foreach($columns as $idx => $column)
  496. {
  497. if(isset($records_in[$column][$in["id"]]))
  498. {
  499. $activeWorksheet->setCellValue($letters[$idx + 1] . $count, formatPrice($records_in[$column][$in["id"]]));
  500. if ($in["level"] == 0)
  501. {
  502. if (isset($totals[$idx]))
  503. $totals[$idx] += $records_in[$column][$in["id"]];
  504. else
  505. $totals[$idx] = $records_in[$column][$in["id"]];
  506. }
  507. }
  508. }
  509. if ($in["level"] == 0)
  510. {
  511. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFont()->setBold(true);
  512. //$activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('b1ed5c');
  513. }
  514. $count += 1;
  515. }
  516. $activeWorksheet->setCellValue('A' . $count, 'Totale');
  517. foreach($totals as $idx => $total)
  518. {
  519. $activeWorksheet->setCellValue($letters[$idx + 1] . $count, formatPrice($total));
  520. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFont()->setBold(true);
  521. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('C6E0B4'); // Lighter green
  522. }
  523. $count += 2;
  524. $activeWorksheet->setCellValue('A' . $count, "Uscite");
  525. foreach($columns as $idx => $column)
  526. {
  527. $activeWorksheet->setCellValue($letters[$idx + 1] . $count, $this->getMonth($column));
  528. }
  529. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFont()->setBold(true);
  530. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('F8CBAD'); // Lighter red
  531. $count += 1;
  532. $totals = [];
  533. foreach($rows_out as $out)
  534. {
  535. $activeWorksheet->setCellValue('A' . $count, str_repeat(" ", $out["level"]) . $out["name"]);
  536. foreach($columns as $idx => $column)
  537. {
  538. if(isset($records_out[$column][$out["id"]]))
  539. {
  540. $activeWorksheet->setCellValue($letters[$idx + 1] . $count, formatPrice($records_out[$column][$out["id"]]));
  541. if ($out["level"] == 0)
  542. {
  543. if (isset($totals[$idx]))
  544. $totals[$idx] += $records_out[$column][$out["id"]];
  545. else
  546. $totals[$idx] = $records_out[$column][$out["id"]];
  547. }
  548. }
  549. }
  550. if ($out["level"] == 0)
  551. {
  552. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFont()->setBold(true);
  553. //$activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('ed6d61');
  554. }
  555. $count += 1;
  556. }
  557. $activeWorksheet->setCellValue('A' . $count, 'Totale');
  558. foreach($totals as $idx => $total)
  559. {
  560. $activeWorksheet->setCellValue($letters[$idx + 1] . $count, formatPrice($total));
  561. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFont()->setBold(true);
  562. $activeWorksheet->getStyle('A' . $count . ':N' . $count)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('F8CBAD'); // Lighter red
  563. }
  564. $activeWorksheet->getColumnDimension('A')->setWidth(35);
  565. for($i = 1; $i < count($letters); $i++) {
  566. $activeWorksheet->getColumnDimension($letters[$i])->setWidth(20);
  567. }
  568. $fileSuffix = $isYearExport ? 'AnnoFiscale' : 'Selezione';
  569. $writer = new Xlsx($spreadsheet);
  570. $writer->save($path = storage_path(date("Ymd") .'_Gestionale_' . $fileSuffix . '.xlsx'));
  571. return $path;
  572. }
  573. }