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 1/2] 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 +
From 6cc2d9682b62f5d512fe3e89c096873587bce9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 2 Jul 2020 10:09:23 +0300 Subject: [PATCH 2/2] refactored suggestions --- app/Http/ViewComposers/Suggestions.php | 53 ++++++++++--------- app/Traits/Modules.php | 6 +-- .../views/partials/admin/header.blade.php | 38 ++++++------- .../partials/admin/suggestions.blade.php | 6 +++ 4 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 resources/views/partials/admin/suggestions.blade.php diff --git a/app/Http/ViewComposers/Suggestions.php b/app/Http/ViewComposers/Suggestions.php index 011c3c843..d97523097 100644 --- a/app/Http/ViewComposers/Suggestions.php +++ b/app/Http/ViewComposers/Suggestions.php @@ -3,13 +3,12 @@ namespace App\Http\ViewComposers; use Illuminate\View\View; -use App\Traits\Modules as RemoteModules; +use App\Traits\Modules; use Route; -use App\Models\Module\Module; class Suggestions { - use RemoteModules; + use Modules; /** * Bind data to the view. @@ -24,30 +23,32 @@ class Suggestions return; } - $modules = false; - - if (user()) { - $path = Route::current()->uri(); - - if ($path) { - $suggestions = $this->getSuggestions($path); - - if ($suggestions) { - $suggestion_modules = $suggestions->modules; - - foreach ($suggestion_modules as $key => $module) { - $installed = Module::where('company_id', session('company_id'))->where('alias', $module->alias)->first(); - - if ($installed) { - continue; - } - - $modules[] = $module; - } - } - } + if ((!$user = user()) || $user->cannot('read-modules-home')) { + return; } - $view->with(['suggestion_modules' => $modules]); + if (!$path = Route::current()->uri()) { + return; + } + + if (!$suggestions = $this->getSuggestions($path)) { + return; + } + + $modules = []; + + foreach ($suggestions->modules as $s_module) { + if ($this->moduleIsEnabled($s_module->alias)) { + continue; + } + + $modules[] = $s_module; + } + + if (empty($modules)) { + return; + } + + $view->getFactory()->startPush('header_button_end', view('partials.admin.suggestions', compact('modules'))); } } diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 5a81573fd..cfe5d58b7 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -558,7 +558,7 @@ trait Modules return true; } - public function moduleEnabled($alias) + public function moduleIsEnabled($alias) { if (!$this->moduleExists($alias)) { return false; @@ -674,10 +674,10 @@ trait Modules if (isset($data['query'])){ foreach($data['query'] as $key => $value) { - $result .= '.' . $key . '.' . $value; + $result .= '.' . $key . '.' . $value; } } return $result; - } + } } diff --git a/resources/views/partials/admin/header.blade.php b/resources/views/partials/admin/header.blade.php index 0381c8d74..ad0e8e486 100644 --- a/resources/views/partials/admin/header.blade.php +++ b/resources/views/partials/admin/header.blade.php @@ -1,32 +1,26 @@ @stack('header_start') -