From d47b11e4959821bd33079056fca7b0509ba83c5b Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 3 Jan 2020 15:08:41 +0300 Subject: [PATCH 1/7] migrations --- ...2019_11_14_000000_create_reports_table.php | 1 - ...0000_drop_enabled_column_reports_table.php | 32 ------------------- 2 files changed, 33 deletions(-) delete mode 100644 database/migrations/2019_11_19_000000_drop_enabled_column_reports_table.php diff --git a/database/migrations/2019_11_14_000000_create_reports_table.php b/database/migrations/2019_11_14_000000_create_reports_table.php index aef5d6d66..95390049a 100644 --- a/database/migrations/2019_11_14_000000_create_reports_table.php +++ b/database/migrations/2019_11_14_000000_create_reports_table.php @@ -23,7 +23,6 @@ class CreateReportsTable extends Migration $table->string('period'); $table->string('basis'); $table->string('chart'); - $table->boolean('enabled'); $table->timestamps(); $table->softDeletes(); diff --git a/database/migrations/2019_11_19_000000_drop_enabled_column_reports_table.php b/database/migrations/2019_11_19_000000_drop_enabled_column_reports_table.php deleted file mode 100644 index e57b59725..000000000 --- a/database/migrations/2019_11_19_000000_drop_enabled_column_reports_table.php +++ /dev/null @@ -1,32 +0,0 @@ -dropColumn('enabled'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('reports', function (Blueprint $table) { - $table->boolean('enabled')->default(1); - }); - } -} From e50453a76cfbef38f6087f5d163fedf8e8c0369b Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 3 Jan 2020 16:13:54 +0300 Subject: [PATCH 2/7] improved install command --- .../akaunting/module/Commands/InstallCommand.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/overrides/akaunting/module/Commands/InstallCommand.php b/overrides/akaunting/module/Commands/InstallCommand.php index d003e8a3f..68405475d 100644 --- a/overrides/akaunting/module/Commands/InstallCommand.php +++ b/overrides/akaunting/module/Commands/InstallCommand.php @@ -36,8 +36,10 @@ class InstallCommand extends Command $old_company_id = session('company_id'); - // Set company id session(['company_id' => $company_id]); + setting()->setExtraColumns(['company_id' => $company_id]); + setting()->forgetAll(); + setting()->load(true); $module = module($alias); @@ -47,7 +49,6 @@ class InstallCommand extends Command 'enabled' => '1', ]); - // Add history ModuleHistory::create([ 'company_id' => $company_id, 'module_id' => $model->id, @@ -56,21 +57,21 @@ class InstallCommand extends Command 'description' => trans('modules.installed', ['module' => $alias]), ]); - // Clear cache $this->call('cache:clear'); // Update database $this->call('migrate', ['--force' => true]); - // Trigger event event(new \App\Events\Module\Installed($alias, $company_id)); - // Unset company id session()->forget('company_id'); + setting()->forgetAll(); - // Set company id if (!empty($old_company_id)) { session(['company_id' => $old_company_id]); + + setting()->setExtraColumns(['company_id' => $old_company_id]); + setting()->load(true); } $this->info('Module installed!'); From 47f9f478d0dd247fb2760b319fd13f74cc39852b Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 3 Jan 2020 18:38:53 +0300 Subject: [PATCH 3/7] changed widget ids --- resources/views/widgets/account_balance.blade.php | 2 +- resources/views/widgets/cash_flow.blade.php | 2 +- resources/views/widgets/expenses_by_category.blade.php | 2 +- resources/views/widgets/income_by_category.blade.php | 2 +- resources/views/widgets/latest_expenses.blade.php | 2 +- resources/views/widgets/latest_income.blade.php | 2 +- resources/views/widgets/total_expenses.blade.php | 2 +- resources/views/widgets/total_income.blade.php | 2 +- resources/views/widgets/total_profit.blade.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/resources/views/widgets/account_balance.blade.php b/resources/views/widgets/account_balance.blade.php index 95e668281..b61bd54d9 100644 --- a/resources/views/widgets/account_balance.blade.php +++ b/resources/views/widgets/account_balance.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.standard_header', ['header_class' => 'border-bottom-0']) diff --git a/resources/views/widgets/cash_flow.blade.php b/resources/views/widgets/cash_flow.blade.php index 13e8fd0b3..22bfc2845 100644 --- a/resources/views/widgets/cash_flow.blade.php +++ b/resources/views/widgets/cash_flow.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.standard_header') diff --git a/resources/views/widgets/expenses_by_category.blade.php b/resources/views/widgets/expenses_by_category.blade.php index 83747bab2..7c2f1959d 100644 --- a/resources/views/widgets/expenses_by_category.blade.php +++ b/resources/views/widgets/expenses_by_category.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.standard_header') diff --git a/resources/views/widgets/income_by_category.blade.php b/resources/views/widgets/income_by_category.blade.php index a84e6c5f0..1c23a440c 100644 --- a/resources/views/widgets/income_by_category.blade.php +++ b/resources/views/widgets/income_by_category.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.standard_header') diff --git a/resources/views/widgets/latest_expenses.blade.php b/resources/views/widgets/latest_expenses.blade.php index b25a4b4d7..246d6b6ff 100644 --- a/resources/views/widgets/latest_expenses.blade.php +++ b/resources/views/widgets/latest_expenses.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.standard_header', ['header_class' => 'border-bottom-0']) diff --git a/resources/views/widgets/latest_income.blade.php b/resources/views/widgets/latest_income.blade.php index bf7d4324b..246d6b6ff 100644 --- a/resources/views/widgets/latest_income.blade.php +++ b/resources/views/widgets/latest_income.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.standard_header', ['header_class' => 'border-bottom-0']) diff --git a/resources/views/widgets/total_expenses.blade.php b/resources/views/widgets/total_expenses.blade.php index 130f58b8a..5ae815424 100644 --- a/resources/views/widgets/total_expenses.blade.php +++ b/resources/views/widgets/total_expenses.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.stats_header', ['header_class' => 'border-bottom-0']) diff --git a/resources/views/widgets/total_income.blade.php b/resources/views/widgets/total_income.blade.php index 9826e956d..4f2dc128c 100644 --- a/resources/views/widgets/total_income.blade.php +++ b/resources/views/widgets/total_income.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.stats_header', ['header_class' => 'border-bottom-0']) diff --git a/resources/views/widgets/total_profit.blade.php b/resources/views/widgets/total_profit.blade.php index a428a6ce8..f7b24eed1 100644 --- a/resources/views/widgets/total_profit.blade.php +++ b/resources/views/widgets/total_profit.blade.php @@ -1,4 +1,4 @@ -
+
@include('partials.widgets.stats_header', ['header_class' => 'border-bottom-0']) From f6e0c4dfc2a162c15161f841eb0d602cef4d615f Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 3 Jan 2020 19:00:38 +0300 Subject: [PATCH 4/7] refactored widget charts --- app/Widgets/CashFlow.php | 2 +- app/Widgets/ExpensesByCategory.php | 2 +- app/Widgets/IncomeByCategory.php | 2 +- public/css/custom.css | 6 ++--- ...tegory.blade.php => donut_chart.blade.php} | 8 +++---- .../widgets/income_by_category.blade.php | 23 ------------------- ...sh_flow.blade.php => line_chart.blade.php} | 6 ++--- .../views/widgets/total_expenses.blade.php | 2 +- .../views/widgets/total_income.blade.php | 22 +++++++++--------- 9 files changed, 25 insertions(+), 48 deletions(-) rename resources/views/widgets/{expenses_by_category.blade.php => donut_chart.blade.php} (64%) delete mode 100644 resources/views/widgets/income_by_category.blade.php rename resources/views/widgets/{cash_flow.blade.php => line_chart.blade.php} (70%) diff --git a/app/Widgets/CashFlow.php b/app/Widgets/CashFlow.php index 9c557b7c1..4604e6198 100644 --- a/app/Widgets/CashFlow.php +++ b/app/Widgets/CashFlow.php @@ -92,7 +92,7 @@ class CashFlow extends Widget ]) ->fill(false); - return $this->view('widgets.cash_flow', [ + return $this->view('widgets.line_chart', [ 'chart' => $chart, ]); } diff --git a/app/Widgets/ExpensesByCategory.php b/app/Widgets/ExpensesByCategory.php index 37f5a9601..b138f7d00 100644 --- a/app/Widgets/ExpensesByCategory.php +++ b/app/Widgets/ExpensesByCategory.php @@ -23,7 +23,7 @@ class ExpensesByCategory extends Widget $chart = $this->getDonutChart(trans_choice('general.expenses', 2), 0, 160, 6); - return $this->view('widgets.expenses_by_category', [ + return $this->view('widgets.donut_chart', [ 'chart' => $chart, ]); } diff --git a/app/Widgets/IncomeByCategory.php b/app/Widgets/IncomeByCategory.php index b23bf08ef..fc9f536ac 100644 --- a/app/Widgets/IncomeByCategory.php +++ b/app/Widgets/IncomeByCategory.php @@ -23,7 +23,7 @@ class IncomeByCategory extends Widget $chart = $this->getDonutChart(trans_choice('general.incomes', 1), 0, 160, 6); - return $this->view('widgets.income_by_category', [ + return $this->view('widgets.donut_chart', [ 'chart' => $chart, ]); } diff --git a/public/css/custom.css b/public/css/custom.css index 19c71f49a..0e5273bdb 100644 --- a/public/css/custom.css +++ b/public/css/custom.css @@ -39,13 +39,13 @@ button:focus /*--------Forgot Text Finish--------*/ -/*--------Dashboard Categories--------*/ -.dashboard-categories +/*--------Chart Donut Height--------*/ +.chart-donut { position:relative !important; height:23vh !important; } -/*--------Dashboard Categories Finish--------*/ +/*--------Chart Donut Height Finish--------*/ /*--------Cursor Pointer--------*/ diff --git a/resources/views/widgets/expenses_by_category.blade.php b/resources/views/widgets/donut_chart.blade.php similarity index 64% rename from resources/views/widgets/expenses_by_category.blade.php rename to resources/views/widgets/donut_chart.blade.php index 7c2f1959d..5441b2709 100644 --- a/resources/views/widgets/expenses_by_category.blade.php +++ b/resources/views/widgets/donut_chart.blade.php @@ -2,8 +2,8 @@
@include('partials.widgets.standard_header') -
-
+
+
{!! $chart->container() !!}
@@ -12,8 +12,8 @@ @push('charts') @endpush diff --git a/resources/views/widgets/income_by_category.blade.php b/resources/views/widgets/income_by_category.blade.php deleted file mode 100644 index 1c23a440c..000000000 --- a/resources/views/widgets/income_by_category.blade.php +++ /dev/null @@ -1,23 +0,0 @@ -
-
- @include('partials.widgets.standard_header') - -
-
- {!! $chart->container() !!} -
-
-
-
- -@push('charts') - -@endpush - -@push('body_scripts') - {!! $chart->script() !!} -@endpush diff --git a/resources/views/widgets/cash_flow.blade.php b/resources/views/widgets/line_chart.blade.php similarity index 70% rename from resources/views/widgets/cash_flow.blade.php rename to resources/views/widgets/line_chart.blade.php index 22bfc2845..2f3d8efad 100644 --- a/resources/views/widgets/cash_flow.blade.php +++ b/resources/views/widgets/line_chart.blade.php @@ -2,7 +2,7 @@
@include('partials.widgets.standard_header') -
+
{!! $chart->container() !!}
@@ -12,8 +12,8 @@ @push('charts') @endpush diff --git a/resources/views/widgets/total_expenses.blade.php b/resources/views/widgets/total_expenses.blade.php index 5ae815424..904d23682 100644 --- a/resources/views/widgets/total_expenses.blade.php +++ b/resources/views/widgets/total_expenses.blade.php @@ -10,7 +10,7 @@
-
+
diff --git a/resources/views/widgets/total_income.blade.php b/resources/views/widgets/total_income.blade.php index 4f2dc128c..87bd52f3f 100644 --- a/resources/views/widgets/total_income.blade.php +++ b/resources/views/widgets/total_income.blade.php @@ -16,17 +16,17 @@
-

- {{ trans('widgets.receivables') }} - - {{ $totals['open'] }} / {{ $totals['overdue'] }} - -

+

+ {{ trans('widgets.receivables') }} + + {{ $totals['open'] }} / {{ $totals['overdue'] }} + +

From 906b7045fa80b5081576f1e1e60ef1b097322466 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 3 Jan 2020 23:54:21 +0300 Subject: [PATCH 5/7] changed company id set in forms --- app/Abstracts/Http/FormRequest.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/app/Abstracts/Http/FormRequest.php b/app/Abstracts/Http/FormRequest.php index 090ee1653..1628789b1 100644 --- a/app/Abstracts/Http/FormRequest.php +++ b/app/Abstracts/Http/FormRequest.php @@ -8,22 +8,15 @@ use Illuminate\Support\Arr; abstract class FormRequest extends BaseFormRequest { /** - * Set the company id to the request. + * Prepare the data for validation. * - * @return \Illuminate\Contracts\Validation\Validator + * @return void */ - protected function getValidatorInstance() + protected function prepareForValidation() { - // Get request data - $data = $this->all(); - - // Add active company id - $data['company_id'] = session('company_id'); - - // Reset the request data - $this->getInputSource()->replace($data); - - return parent::getValidatorInstance(); + $this->merge([ + 'company_id' => session('company_id'), + ]); } /** From bc46b1f8f62f28744e11f4e8f05809231a088119 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sat, 4 Jan 2020 11:49:59 +0300 Subject: [PATCH 6/7] updated widget utility --- app/Utilities/Widgets.php | 39 ++++++++++++++++++++++----------------- app/Utilities/helpers.php | 10 +++++++--- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/Utilities/Widgets.php b/app/Utilities/Widgets.php index 1d4487bc5..c95c9ecba 100644 --- a/app/Utilities/Widgets.php +++ b/app/Utilities/Widgets.php @@ -2,6 +2,7 @@ namespace App\Utilities; +use App\Models\Common\Widget; use App\Models\Module\Module; class Widgets @@ -10,7 +11,7 @@ class Widgets { $classes = []; - $core_classes = [ + $list = [ 'App\Widgets\TotalIncome', 'App\Widgets\TotalExpenses', 'App\Widgets\TotalProfit', @@ -22,26 +23,16 @@ class Widgets 'App\Widgets\LatestExpenses', ]; - 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 widgets if (!$m || empty($m->get('widgets'))) { - continue; + return; } - static::parseClasses($classes, $m->get('widgets')); - } + $list = array_merge($list, (array) $m->get('widgets')); + }); - return $classes; - } - - protected static function parseClasses(&$classes, $list) - { foreach ($list as $class) { if (!class_exists($class)) { continue; @@ -51,17 +42,31 @@ class Widgets $classes[$class] = $name; } + + return $classes; } public static function getInstance($model) { + if (is_string($model)) { + $model = Widget::where('class', $model)->first(); + } + + if ((!$model instanceof Widget) || !class_exists($model->class)) { + return false; + } + $class = $model->class; return new $class($model); } - public static function show($model) + public static function show($model, ...$arguments) { - return static::getInstance($model)->show(); + if (!$class = static::getInstance($model)) { + return ''; + } + + return $class->show(...$arguments); } } diff --git a/app/Utilities/helpers.php b/app/Utilities/helpers.php index 4dcc4b004..5c0c3f641 100644 --- a/app/Utilities/helpers.php +++ b/app/Utilities/helpers.php @@ -41,12 +41,16 @@ if (!function_exists('company_date')) { if (!function_exists('show_widget')) { /** - * Format the given date based on company settings. + * Show a widget. * * @return string */ - function show_widget($model) + function show_widget() { - return Widgets::show($model); + $arguments = func_get_args(); + + $model = array_shift($arguments); + + return Widgets::show($model, ...$arguments); } } From dca5a64122479ed4e8487e327480ad9e53ea71a0 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sat, 4 Jan 2020 13:42:58 +0300 Subject: [PATCH 7/7] updated category structure of reports --- app/Abstracts/Report.php | 6 +- app/Http/Controllers/Common/Reports.php | 15 +- app/Reports/ExpenseSummary.php | 9 +- app/Reports/IncomeExpenseSummary.php | 9 +- app/Reports/IncomeSummary.php | 9 +- app/Reports/ProfitLoss.php | 9 +- app/Reports/TaxSummary.php | 9 +- app/Utilities/Reports.php | 41 +++--- app/Utilities/Widgets.php | 8 +- .../views/common/reports/index.blade.php | 135 ++++++------------ .../views/partials/reports/filter.blade.php | 2 +- 11 files changed, 107 insertions(+), 145 deletions(-) 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', ]) !!}