diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 5d38af9bf..a6e25469c 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -32,8 +32,6 @@ abstract class Report public $filters = []; - public $category = 'income-expense'; - public $icon = 'fa fa-chart-pie'; public $indents = [ @@ -80,14 +78,14 @@ abstract class Report abstract public function getTotals(); - public function getName() + public function getDefaultName() { return Str::title(str_replace('_', ' ', Str::snake((new \ReflectionClass($this))->getShortName()))); } public function getCategory() { - return $this->category; + return trans('reports.income_expense'); } public function getIcon() diff --git a/app/Http/Controllers/Common/Reports.php b/app/Http/Controllers/Common/Reports.php index 106e7e715..ccca5412a 100644 --- a/app/Http/Controllers/Common/Reports.php +++ b/app/Http/Controllers/Common/Reports.php @@ -19,24 +19,23 @@ class Reports extends Controller */ public function index() { - $classes = []; - $reports = ['income-expense' => [], 'accounting' => []]; + $classes = $categories = []; - $items = Report::collect(); + $reports = Report::collect(); - foreach ($items as $item) { - $class = Utility::getClassInstance($item); + foreach ($reports as $report) { + $class = Utility::getClassInstance($report); if (!$class->canRead()) { continue; } - $reports[$class->getCategory()][] = $item; + $classes[$report->id] = $class; - $classes[$item->id] = $class; + $categories[$class->getCategory()][] = $report; } - return view('common.reports.index', compact('reports', 'classes')); + return view('common.reports.index', compact('categories', 'classes')); } /** diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index b73b12200..c5d08fa0f 100644 --- a/app/Reports/ExpenseSummary.php +++ b/app/Reports/ExpenseSummary.php @@ -9,8 +9,6 @@ use App\Utilities\Recurring; class ExpenseSummary extends Report { - public $category = 'income-expense'; - public $icon = 'fa fa-shopping-cart'; public $chart = [ @@ -28,11 +26,16 @@ class ExpenseSummary extends Report ], ]; - public function getName() + public function getDefaultName() { return trans('reports.summary.expense'); } + public function getCategory() + { + return trans('reports.income_expense'); + } + public function getTotals() { $payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 0ef2f458a..92daa28c6 100644 --- a/app/Reports/IncomeExpenseSummary.php +++ b/app/Reports/IncomeExpenseSummary.php @@ -10,15 +10,18 @@ use App\Utilities\Recurring; class IncomeExpenseSummary extends Report { - public $category = 'income-expense'; - public $icon = 'fa fa-chart-pie'; - public function getName() + public function getDefaultName() { return trans('reports.summary.income_expense'); } + public function getCategory() + { + return trans('reports.income_expense'); + } + public function getTotals() { $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index 1b023a844..3d34a0e8e 100644 --- a/app/Reports/IncomeSummary.php +++ b/app/Reports/IncomeSummary.php @@ -9,8 +9,6 @@ use App\Utilities\Recurring; class IncomeSummary extends Report { - public $category = 'income-expense'; - public $icon = 'fa fa-money-bill'; public $chart = [ @@ -28,11 +26,16 @@ class IncomeSummary extends Report ], ]; - public function getName() + public function getDefaultName() { return trans('reports.summary.income'); } + public function getCategory() + { + return trans('reports.income_expense'); + } + public function getTotals() { $transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index 27e1ab790..9732f5eaf 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -11,17 +11,20 @@ use App\Utilities\Recurring; class ProfitLoss extends Report { - public $category = 'accounting'; - public $icon = 'fa fa-heart'; public $chart = false; - public function getName() + public function getDefaultName() { return trans('reports.profit_loss'); } + public function getCategory() + { + return trans('general.accounting'); + } + public function setViews() { parent::setViews(); diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index 6275b0198..77a811455 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -15,17 +15,20 @@ class TaxSummary extends Report { use Currencies; - public $category = 'accounting'; - public $icon = 'fa fa-percent'; public $chart = false; - public function getName() + public function getDefaultName() { return trans('reports.summary.tax'); } + public function getCategory() + { + return trans('general.accounting'); + } + public function setViews() { parent::setViews(); diff --git a/app/Utilities/Reports.php b/app/Utilities/Reports.php index f4c5fc7ac..f170f0aea 100644 --- a/app/Utilities/Reports.php +++ b/app/Utilities/Reports.php @@ -2,6 +2,7 @@ namespace App\Utilities; +use App\Models\Common\Report; use App\Models\Module\Module; class Reports @@ -10,7 +11,7 @@ class Reports { $classes = []; - $core_classes = [ + $list = [ 'App\Reports\IncomeSummary', 'App\Reports\ExpenseSummary', 'App\Reports\IncomeExpenseSummary', @@ -18,35 +19,25 @@ class Reports 'App\Reports\ProfitLoss', ]; - static::parseClasses($classes, $core_classes); - - $modules = Module::enabled()->get(); - - foreach ($modules as $module) { + Module::enabled()->each(function ($module) use (&$list) { $m = module($module->alias); - // Check if the module exists and has reports if (!$m || empty($m->get('reports'))) { - continue; + return; } - static::parseClasses($classes, $m->get('reports')); - } + $list = array_merge($list, (array) $m->get('reports')); + }); - return $classes; - } - - protected static function parseClasses(&$classes, $list) - { foreach ($list as $class) { if (!class_exists($class)) { continue; } - $name = (new $class())->getName(); - - $classes[$class] = $name; + $classes[$class] = (new $class())->getDefaultName(); } + + return $classes; } public static function getGroups() @@ -81,8 +72,18 @@ class Reports ]; } - public static function getClassInstance($report, $get_totals = true) + public static function getClassInstance($model, $get_totals = true) { - return (new $report->class($report, $get_totals)); + if (is_string($model)) { + $model = Report::where('class', $model)->first(); + } + + if ((!$model instanceof Report) || !class_exists($model->class)) { + return false; + } + + $class = $model->class; + + return new $class($model, $get_totals); } } diff --git a/app/Utilities/Widgets.php b/app/Utilities/Widgets.php index c95c9ecba..7efd216b9 100644 --- a/app/Utilities/Widgets.php +++ b/app/Utilities/Widgets.php @@ -38,15 +38,13 @@ class Widgets continue; } - $name = (new $class())->getDefaultName(); - - $classes[$class] = $name; + $classes[$class] = (new $class())->getDefaultName(); } return $classes; } - public static function getInstance($model) + public static function getClassInstance($model) { if (is_string($model)) { $model = Widget::where('class', $model)->first(); @@ -63,7 +61,7 @@ class Widgets public static function show($model, ...$arguments) { - if (!$class = static::getInstance($model)) { + if (!$class = static::getClassInstance($model)) { return ''; } diff --git a/resources/views/common/reports/index.blade.php b/resources/views/common/reports/index.blade.php index c1bfff254..e47a46393 100644 --- a/resources/views/common/reports/index.blade.php +++ b/resources/views/common/reports/index.blade.php @@ -12,107 +12,58 @@ @section('content')
+ @foreach($categories as $name => $reports) +
+

{{ $name }}

+
-
-

{{ trans('reports.income_expense') }}

-
- - @foreach($reports['income-expense'] as $report) -
-
- - - - -
-
-
- -
{{ $report->name }}
- {{ $classes[$report->id]->getTotal() }} + @foreach($reports as $report) +
+
+ + - -

- - {{ $report->description }} - -

-
+ @endforeach + @endforeach - -
-

{{ trans('general.accounting') }}

-
- - @foreach($reports['accounting'] as $report) -
-
- - - - - -
-
- @endforeach -
@endsection diff --git a/resources/views/partials/reports/filter.blade.php b/resources/views/partials/reports/filter.blade.php index 72633eb3a..1f1933dca 100644 --- a/resources/views/partials/reports/filter.blade.php +++ b/resources/views/partials/reports/filter.blade.php @@ -1,6 +1,6 @@
{!! Form::open([ - 'url' => 'common/reports/' . $class->report->id . '/display', + 'url' => 'common/reports/' . $class->report->id, 'role' => 'form', 'method' => 'GET', ]) !!}