From d22a3e20018c6d8b95e4cf60817505d16ccaca0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 2 Jul 2020 01:55:45 +0300 Subject: [PATCH] added events to manipulate report data --- app/Abstracts/Report.php | 13 ++++++++++- app/Events/Report/DataLoaded.php | 22 +++++++++++++++++++ app/Events/Report/DataLoading.php | 22 +++++++++++++++++++ app/Reports/ProfitLoss.php | 11 ---------- .../profit_loss/content/footer.blade.php | 12 ++++++++++ 5 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 app/Events/Report/DataLoaded.php create mode 100644 app/Events/Report/DataLoading.php diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index dce1ea98f..2c07ec8c2 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -2,6 +2,8 @@ namespace App\Abstracts; +use App\Events\Report\DataLoaded; +use App\Events\Report\DataLoading; use App\Events\Report\FilterApplying; use App\Events\Report\FilterShowing; use App\Events\Report\GroupApplying; @@ -92,12 +94,21 @@ abstract class Report $this->setDates(); $this->setFilters(); $this->setRows(); - $this->setData(); + $this->loadData(); $this->setColumnWidth(); $this->loaded = true; } + public function loadData() + { + event(new DataLoading($this)); + + $this->setData(); + + event(new DataLoaded($this)); + } + public function getDefaultName() { if (!empty($this->default_name)) { diff --git a/app/Events/Report/DataLoaded.php b/app/Events/Report/DataLoaded.php new file mode 100644 index 000000000..03be50915 --- /dev/null +++ b/app/Events/Report/DataLoaded.php @@ -0,0 +1,22 @@ +class = $class; + } +} diff --git a/app/Events/Report/DataLoading.php b/app/Events/Report/DataLoading.php new file mode 100644 index 000000000..4684541af --- /dev/null +++ b/app/Events/Report/DataLoading.php @@ -0,0 +1,22 @@ +class = $class; + } +} diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index d225abab2..c30ab5d34 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -72,17 +72,6 @@ class ProfitLoss extends Report break; } - - // TODO: move to views - foreach ($this->footer_totals as $table => $dates) { - foreach ($dates as $date => $total) { - if (!isset($this->net_profit[$date])) { - $this->net_profit[$date] = 0; - } - - $this->net_profit[$date] += $total; - } - } } public function getFields() diff --git a/resources/views/reports/profit_loss/content/footer.blade.php b/resources/views/reports/profit_loss/content/footer.blade.php index 2b4b4728a..b15ff7683 100644 --- a/resources/views/reports/profit_loss/content/footer.blade.php +++ b/resources/views/reports/profit_loss/content/footer.blade.php @@ -1,3 +1,15 @@ +@php +foreach ($class->footer_totals as $table => $dates) { + foreach ($dates as $date => $total) { + if (!isset($class->net_profit[$date])) { + $class->net_profit[$date] = 0; + } + + $class->net_profit[$date] += $total; + } +} +@endphp +