RecordINOUT.php 25 KB

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