RecordINOUT.php 24 KB

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