From 893970ffaed288485b9681948653b7bc3106c1ec Mon Sep 17 00:00:00 2001 From: denisdulici Date: Thu, 16 Jan 2020 15:39:37 +0300 Subject: [PATCH] report fields --- app/Abstracts/Report.php | 140 +++++++++++++++--- .../Stubs/Modules/scaffold/provider.stub | 2 +- app/Http/Controllers/Common/Reports.php | 36 ++--- app/Listeners/Update/V20/Version200.php | 50 ++----- app/Models/Common/Report.php | 12 +- app/Reports/ExpenseSummary.php | 14 +- app/Reports/IncomeExpenseSummary.php | 14 +- app/Reports/IncomeSummary.php | 14 +- app/Reports/ProfitLoss.php | 16 +- app/Reports/TaxSummary.php | 16 +- app/Utilities/Reports.php | 32 ---- .../2020_01_08_000000_core_v200.php | 7 +- database/seeds/Reports.php | 45 ++---- resources/lang/en-GB/demo.php | 2 +- .../views/common/reports/create.blade.php | 10 +- resources/views/common/reports/edit.blade.php | 22 ++- .../views/partials/reports/fields.blade.php | 15 ++ .../views/partials/reports/filter.blade.php | 2 +- .../views/partials/reports/header.blade.php | 2 +- .../views/partials/reports/print.blade.php | 4 +- .../views/partials/reports/show.blade.php | 2 +- .../partials/reports/table/header.blade.php | 4 +- routes/admin.php | 2 +- 23 files changed, 233 insertions(+), 230 deletions(-) create mode 100644 resources/views/partials/reports/fields.blade.php diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 8f5ae5851..885680b23 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -2,6 +2,10 @@ namespace App\Abstracts; +use App\Events\Common\ReportFilterShowing; +use App\Events\Common\ReportFilterApplying; +use App\Events\Common\ReportGroupApplying; +use App\Events\Common\ReportGroupShowing; use App\Exports\Common\Reports as Export; use App\Models\Common\Report as Model; use App\Traits\Charts; @@ -14,7 +18,13 @@ abstract class Report { use Charts, DateTime; - public $report; + public $model; + + public $default_name = ''; + + public $category = 'reports.income_expense'; + + public $icon = 'fa fa-chart-pie'; public $year; @@ -28,12 +38,8 @@ abstract class Report public $totals = []; - public $groups = []; - public $filters = []; - public $icon = 'fa fa-chart-pie'; - public $indents = [ 'table_header' => '0px', 'table_rows' => '0px', @@ -54,15 +60,15 @@ abstract class Report 'datasets' => [], ]; - public function __construct(Model $report = null, $get_totals = true) + public function __construct(Model $model = null, $get_totals = true) { $this->setGroups(); - if (!$report) { + if (!$model) { return; } - $this->report = $report; + $this->model = $model; $this->setYear(); $this->setViews(); @@ -80,12 +86,16 @@ abstract class Report public function getDefaultName() { + if (!empty($this->default_name)) { + return trans($this->default_name); + } + return Str::title(str_replace('_', ' ', Str::snake((new \ReflectionClass($this))->getShortName()))); } public function getCategory() { - return trans('reports.income_expense'); + return trans($this->category); } public function getIcon() @@ -108,7 +118,7 @@ abstract class Report public function getTableRowList() { - $group_prl = Str::plural($this->report->group); + $group_prl = Str::plural($this->model->settings->group); if ($group_filter = request($group_prl)) { $rows = collect($this->filters[$group_prl])->filter(function ($value, $key) use ($group_filter) { @@ -125,13 +135,13 @@ abstract class Report { $chart = new Chartjs(); - $config = $this->chart[$this->report->chart]; + $config = $this->chart[$this->model->settings->chart]; $default_options = $this->getLineChartOptions(); $options = array_merge($default_options, (array) $config['options']); - $chart->type($this->report->chart) + $chart->type($this->model->settings->chart) ->width((int) $config['width']) ->height((int) $config['height']) ->options($options) @@ -147,7 +157,7 @@ abstract class Report } } else { foreach ($this->totals as $total) { - $chart->dataset($this->report->name, 'line', array_values($total)) + $chart->dataset($this->model->name, 'line', array_values($total)) ->backgroundColor(isset($config['backgroundColor']) ? $config['backgroundColor'] : '#6da252') ->color(isset($config['color']) ? $config['color'] : '#6da252') ->options([ @@ -173,7 +183,7 @@ abstract class Report public function export() { - return \Excel::download(new Export($this->views['content'], $this), $this->report->name . '.xlsx'); + return \Excel::download(new Export($this->views['content'], $this), $this->model->name . '.xlsx'); } public function setYear() @@ -208,12 +218,12 @@ abstract class Report public function setDates() { - $function = 'sub' . ucfirst(str_replace('ly', '', $this->report->period)); + $function = 'sub' . ucfirst(str_replace('ly', '', $this->model->settings->period)); $start = $this->getFinancialStart()->copy()->$function(); for ($j = 1; $j <= 12; $j++) { - switch ($this->report->period) { + switch ($this->model->settings->period) { case 'yearly': $start->addYear(); @@ -260,12 +270,14 @@ abstract class Report public function setFilters() { - event(new \App\Events\Common\ReportFilterShowing($this)); + event(new ReportFilterShowing($this)); } public function setGroups() { - event(new \App\Events\Common\ReportGroupShowing($this)); + $this->groups = []; + + event(new ReportGroupShowing($this)); } public function setRows() @@ -289,7 +301,7 @@ abstract class Report $date = $this->getFormattedDate(Date::parse($item->$date_field)); - $id_field = $this->report->group . '_id'; + $id_field = $this->model->settings->group . '_id'; if (!isset($this->rows[$table][$item->$id_field]) || !isset($this->rows[$table][$item->$id_field][$date]) || @@ -322,21 +334,21 @@ abstract class Report public function applyFilters($model, $args = []) { - event(new \App\Events\Common\ReportFilterApplying($this, $model, $args)); + event(new ReportFilterApplying($this, $model, $args)); return $model; } public function applyGroups($model, $args = []) { - event(new \App\Events\Common\ReportGroupApplying($this, $model, $args)); + event(new ReportGroupApplying($this, $model, $args)); return $model; } public function getFormattedDate($date) { - switch ($this->report->period) { + switch ($this->model->settings->period) { case 'yearly': $i = $date->copy()->format($this->getYearlyDateFormat()); break; @@ -356,7 +368,7 @@ abstract class Report public function getUrl($action = 'print') { - $print_url = 'common/reports/' . $this->report->id . '/' . $action . '?year='. $this->year; + $print_url = 'common/reports/' . $this->model->id . '/' . $action . '?year='. $this->year; collect(request('accounts'))->each(function($item) use(&$print_url) { $print_url .= '&accounts[]=' . $item; @@ -372,4 +384,86 @@ abstract class Report return $print_url; } + + public function getFields() + { + return [ + $this->getGroupField(), + $this->getPeriodField(), + $this->getBasisField(), + $this->getChartField(), + ]; + } + + public function getGroupField() + { + $this->setGroups(); + + return [ + 'type' => 'selectGroup', + 'name' => 'group', + 'title' => trans('general.group_by'), + 'icon' => 'folder', + 'values' => $this->groups, + 'selected' => 'category', + 'attributes' => [ + 'required' => 'required', + ], + ]; + } + + public function getPeriodField() + { + return [ + 'type' => 'selectGroup', + 'name' => 'period', + 'title' => trans('general.period'), + 'icon' => 'calendar', + 'values' => [ + 'monthly' => trans('general.monthly'), + 'quarterly' => trans('general.quarterly'), + 'yearly' => trans('general.yearly'), + ], + 'selected' => 'quarterly', + 'attributes' => [ + 'required' => 'required', + ], + ]; + } + + public function getBasisField() + { + return [ + 'type' => 'selectGroup', + 'name' => 'basis', + 'title' => trans('general.basis'), + 'icon' => 'file', + 'values' => [ + 'accrual' => trans('general.accrual'), + 'cash' => trans('general.cash'), + ], + 'selected' => 'accrual', + 'attributes' => [ + 'required' => 'required', + ], + ]; + } + + public function getChartField() + { + return [ + 'type' => 'selectGroup', + 'name' => 'chart', + 'title' => trans_choice('general.charts', 1), + 'icon' => 'chart-pie', + 'values' => [ + '0' => trans('general.disabled'), + 'line' => trans('reports.charts.line'), + ], + 'selected' => '0', + 'attributes' => [ + 'required' => 'required', + ], + ]; + } } diff --git a/app/Console/Stubs/Modules/scaffold/provider.stub b/app/Console/Stubs/Modules/scaffold/provider.stub index 3c0c2511b..4fe695849 100644 --- a/app/Console/Stubs/Modules/scaffold/provider.stub +++ b/app/Console/Stubs/Modules/scaffold/provider.stub @@ -13,8 +13,8 @@ class $NAME$ extends Provider */ public function boot() { - $this->loadTranslations(); $this->loadViews(); + $this->loadTranslations(); $this->loadMigrations(); } diff --git a/app/Http/Controllers/Common/Reports.php b/app/Http/Controllers/Common/Reports.php index be5575a3e..e85805e51 100644 --- a/app/Http/Controllers/Common/Reports.php +++ b/app/Http/Controllers/Common/Reports.php @@ -21,7 +21,7 @@ class Reports extends Controller { $classes = $categories = []; - $reports = Report::collect(); + $reports = Report::all(); foreach ($reports as $report) { if (!Utility::canRead($report->class)) { @@ -62,15 +62,7 @@ class Reports extends Controller { $classes = Utility::getClasses(); - $groups = Utility::getGroups(); - - $periods = Utility::getPeriods(); - - $basises = Utility::getBasises(); - - $charts = Utility::getCharts(); - - return view('common.reports.create', compact('classes', 'groups', 'periods', 'basises', 'charts')); + return view('common.reports.create', compact('classes')); } /** @@ -111,15 +103,9 @@ class Reports extends Controller { $classes = Utility::getClasses(); - $groups = Utility::getGroups(); + $class = Utility::getClassInstance($report); - $periods = Utility::getPeriods(); - - $basises = Utility::getBasises(); - - $charts = Utility::getCharts(); - - return view('common.reports.edit', compact('report', 'classes', 'groups', 'periods', 'basises', 'charts')); + return view('common.reports.edit', compact('report', 'classes', 'class')); } /** @@ -207,11 +193,11 @@ class Reports extends Controller } /** - * Get groups of the specified resource. + * Get fields of the specified resource. * * @return Response */ - public function groups() + public function fields() { $class = request('class'); @@ -219,16 +205,20 @@ class Reports extends Controller return response()->json([ 'success' => false, 'error' => true, - 'data' => false, - 'message' => "Class doesn't exist", + 'message' => 'Class does not exist', + 'html' => '', ]); } + $fields = (new $class())->getFields(); + + $html = view('partials.reports.fields', compact('fields'))->render(); + return response()->json([ 'success' => true, 'error' => false, - 'data' => (new $class())->groups, 'message' => '', + 'html' => $html, ]); } } diff --git a/app/Listeners/Update/V20/Version200.php b/app/Listeners/Update/V20/Version200.php index 5dfcaabdc..ac4ac2275 100644 --- a/app/Listeners/Update/V20/Version200.php +++ b/app/Listeners/Update/V20/Version200.php @@ -259,58 +259,38 @@ class Version200 extends Listener $rows = [ [ 'company_id' => $company->id, + 'class' => 'App\Reports\IncomeSummary', 'name' => trans('reports.summary.income'), 'description' => trans('demo.reports.income'), - 'class' => 'App\Reports\IncomeSummary', - 'group' => 'category', - 'period' => 'monthly', - 'basis' => 'accrual', - 'chart' => 'line', - 'enabled' => 1, + 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'], ], [ 'company_id' => $company->id, + 'class' => 'App\Reports\ExpenseSummary', 'name' => trans('reports.summary.expense'), 'description' => trans('demo.reports.expense'), - 'class' => 'App\Reports\ExpenseSummary', - 'group' => 'category', - 'period' => 'monthly', - 'basis' => 'accrual', - 'chart' => 'line', - 'enabled' => 1, + 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'], ], [ 'company_id' => $company->id, + 'class' => 'App\Reports\IncomeExpenseSummary', 'name' => trans('reports.summary.income_expense'), 'description' => trans('demo.reports.income_expense'), - 'class' => 'App\Reports\IncomeExpenseSummary', - 'group' => 'category', - 'period' => 'monthly', - 'basis' => 'accrual', - 'chart' => 'line', - 'enabled' => 1, + 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'], ], [ 'company_id' => $company->id, + 'class' => 'App\Reports\ProfitLoss', + 'name' => trans('reports.profit_loss'), + 'description' => trans('demo.reports.profit_loss'), + 'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'], + ], + [ + 'company_id' => $company->id, + 'class' => 'App\Reports\TaxSummary', 'name' => trans('reports.summary.tax'), 'description' => trans('demo.reports.tax'), - 'class' => 'App\Reports\TaxSummary', - 'group' => 'category', - 'period' => 'quarterly', - 'basis' => 'accrual', - 'chart' => '0', - 'enabled' => 1, - ], - [ - 'company_id' => $company->id, - 'name' => trans('reports.profit_loss'), - 'description' => trans('demo.reports.pl'), - 'class' => 'App\Reports\ProfitLoss', - 'group' => 'category', - 'period' => 'quarterly', - 'basis' => 'accrual', - 'chart' => '0', - 'enabled' => 1, + 'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'], ], ]; diff --git a/app/Models/Common/Report.php b/app/Models/Common/Report.php index cf09fa477..ff3a7dead 100644 --- a/app/Models/Common/Report.php +++ b/app/Models/Common/Report.php @@ -6,7 +6,6 @@ use App\Abstracts\Model; class Report extends Model { - protected $table = 'reports'; /** @@ -14,5 +13,14 @@ class Report extends Model * * @var array */ - protected $fillable = ['company_id', 'name', 'description', 'class', 'group', 'period', 'basis', 'chart']; + protected $fillable = ['company_id', 'class', 'name', 'description', 'settings']; + + /** + * The attributes that should be casted to native types. + * + * @var array + */ + protected $casts = [ + 'settings' => 'object', + ]; } diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index c5d08fa0f..ab3343cd8 100644 --- a/app/Reports/ExpenseSummary.php +++ b/app/Reports/ExpenseSummary.php @@ -9,6 +9,8 @@ use App\Utilities\Recurring; class ExpenseSummary extends Report { + public $default_name = 'reports.summary.expense'; + public $icon = 'fa fa-shopping-cart'; public $chart = [ @@ -26,21 +28,11 @@ class ExpenseSummary extends Report ], ]; - 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(); - switch ($this->report->basis) { + switch ($this->model->settings->basis) { case 'cash': // Payments $this->setTotals($payments, 'paid_at'); diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 92daa28c6..1996ce070 100644 --- a/app/Reports/IncomeExpenseSummary.php +++ b/app/Reports/IncomeExpenseSummary.php @@ -10,24 +10,16 @@ use App\Utilities\Recurring; class IncomeExpenseSummary extends Report { + public $default_name = 'reports.summary.income_expense'; + public $icon = 'fa fa-chart-pie'; - 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(); $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); - switch ($this->report->basis) { + switch ($this->model->settings->basis) { case 'cash': // Income Transactions $this->setTotals($income_transactions, 'paid_at', true); diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index 3d34a0e8e..8c0c60e1e 100644 --- a/app/Reports/IncomeSummary.php +++ b/app/Reports/IncomeSummary.php @@ -9,6 +9,8 @@ use App\Utilities\Recurring; class IncomeSummary extends Report { + public $default_name = 'reports.summary.income'; + public $icon = 'fa fa-money-bill'; public $chart = [ @@ -26,21 +28,11 @@ class IncomeSummary extends Report ], ]; - 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(); - switch ($this->report->basis) { + switch ($this->model->settings->basis) { case 'cash': // Transactions $this->setTotals($transactions, 'paid_at'); diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index 9732f5eaf..fc5767893 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -11,20 +11,14 @@ use App\Utilities\Recurring; class ProfitLoss extends Report { + public $default_name = 'reports.profit_loss'; + + public $category = 'general.accounting'; + public $icon = 'fa fa-heart'; public $chart = false; - public function getDefaultName() - { - return trans('reports.profit_loss'); - } - - public function getCategory() - { - return trans('general.accounting'); - } - public function setViews() { parent::setViews(); @@ -73,7 +67,7 @@ class ProfitLoss extends Report $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); - switch ($this->report->basis) { + switch ($this->model->settings->basis) { case 'cash': // Income Transactions $this->setTotals($income_transactions, 'paid_at', true, $this->tables['income']); diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index 77a811455..8fdf3b0d3 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -15,20 +15,14 @@ class TaxSummary extends Report { use Currencies; + public $default_name = 'reports.summary.tax'; + + public $category = 'general.accounting'; + public $icon = 'fa fa-percent'; public $chart = false; - public function getDefaultName() - { - return trans('reports.summary.tax'); - } - - public function getCategory() - { - return trans('general.accounting'); - } - public function setViews() { parent::setViews(); @@ -54,7 +48,7 @@ class TaxSummary extends Report public function getTotals() { - switch ($this->report->basis) { + switch ($this->model->settings->basis) { case 'cash': // Invoice Payments $invoices = $this->applyFilters(Transaction::type('income')->isDocument()->with(['invoice', 'invoice.totals'])->isNotTransfer(), ['date_field' => 'paid_at'])->get(); diff --git a/app/Utilities/Reports.php b/app/Utilities/Reports.php index 7f2eaf355..21906f9ad 100644 --- a/app/Utilities/Reports.php +++ b/app/Utilities/Reports.php @@ -41,38 +41,6 @@ class Reports return $classes; } - public static function getGroups() - { - return [ - 'category' => trans_choice('general.categories', 1), - ]; - } - - public static function getPeriods() - { - return [ - 'monthly' => trans('general.monthly'), - 'quarterly' => trans('general.quarterly'), - 'yearly' => trans('general.yearly'), - ]; - } - - public static function getBasises() - { - return [ - 'accrual' => trans('general.accrual'), - 'cash' => trans('general.cash'), - ]; - } - - public static function getCharts() - { - return [ - '0' => trans('general.disabled'), - 'line' => trans('reports.charts.line'), - ]; - } - public static function getClassInstance($model, $get_totals = true) { if (is_string($model)) { diff --git a/database/migrations/2020_01_08_000000_core_v200.php b/database/migrations/2020_01_08_000000_core_v200.php index bea4074bb..a9e7e1daf 100644 --- a/database/migrations/2020_01_08_000000_core_v200.php +++ b/database/migrations/2020_01_08_000000_core_v200.php @@ -110,8 +110,8 @@ class CoreV200 extends Migration $table->integer('dashboard_id'); $table->string('class'); $table->string('name'); - $table->text('settings')->nullable(); $table->integer('sort')->default(0); + $table->text('settings')->nullable(); $table->timestamps(); $table->softDeletes(); @@ -170,10 +170,7 @@ class CoreV200 extends Migration $table->string('class'); $table->string('name'); $table->text('description'); - $table->string('group'); - $table->string('period'); - $table->string('basis'); - $table->string('chart'); + $table->text('settings')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/seeds/Reports.php b/database/seeds/Reports.php index 9402f6f1a..53e7dc7c5 100644 --- a/database/seeds/Reports.php +++ b/database/seeds/Reports.php @@ -29,53 +29,38 @@ class Reports extends Seeder $rows = [ [ 'company_id' => $company_id, + 'class' => 'App\Reports\IncomeSummary', 'name' => trans('reports.summary.income'), 'description' => trans('demo.reports.income'), - 'class' => 'App\Reports\IncomeSummary', - 'group' => 'category', - 'period' => 'monthly', - 'basis' => 'accrual', - 'chart' => 'line', + 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'], ], [ 'company_id' => $company_id, + 'class' => 'App\Reports\ExpenseSummary', 'name' => trans('reports.summary.expense'), 'description' => trans('demo.reports.expense'), - 'class' => 'App\Reports\ExpenseSummary', - 'group' => 'category', - 'period' => 'monthly', - 'basis' => 'accrual', - 'chart' => 'line', + 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'], ], [ 'company_id' => $company_id, + 'class' => 'App\Reports\IncomeExpenseSummary', 'name' => trans('reports.summary.income_expense'), 'description' => trans('demo.reports.income_expense'), - 'class' => 'App\Reports\IncomeExpenseSummary', - 'group' => 'category', - 'period' => 'monthly', - 'basis' => 'accrual', - 'chart' => 'line', + 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'], ], [ 'company_id' => $company_id, + 'class' => 'App\Reports\ProfitLoss', + 'name' => trans('reports.profit_loss'), + 'description' => trans('demo.reports.profit_loss'), + 'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'], + ], + [ + 'company_id' => $company_id, + 'class' => 'App\Reports\TaxSummary', 'name' => trans('reports.summary.tax'), 'description' => trans('demo.reports.tax'), - 'class' => 'App\Reports\TaxSummary', - 'group' => 'category', - 'period' => 'quarterly', - 'basis' => 'accrual', - 'chart' => '0', - ], - [ - 'company_id' => $company_id, - 'name' => trans('reports.profit_loss'), - 'description' => trans('demo.reports.pl'), - 'class' => 'App\Reports\ProfitLoss', - 'group' => 'category', - 'period' => 'quarterly', - 'basis' => 'accrual', - 'chart' => '0', + 'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'], ], ]; diff --git a/resources/lang/en-GB/demo.php b/resources/lang/en-GB/demo.php index ad8b67591..abeb2357f 100644 --- a/resources/lang/en-GB/demo.php +++ b/resources/lang/en-GB/demo.php @@ -28,7 +28,7 @@ return [ 'expense' => 'Monthly expense summary by category.', 'income_expense' => 'Monthly income vs expense by category.', 'tax' => 'Quarterly tax summary by category.', - 'pl' => 'Quarterly profit & loss by category.', + 'profit_loss' => 'Quarterly profit & loss by category.', ], ]; diff --git a/resources/views/common/reports/create.blade.php b/resources/views/common/reports/create.blade.php index 6c22578b8..8187819f7 100644 --- a/resources/views/common/reports/create.blade.php +++ b/resources/views/common/reports/create.blade.php @@ -11,7 +11,7 @@ '@keydown' => 'form.errors.clear($event.target.name)', 'role' => 'form', 'class' => 'form-loading-button', - 'novalidate' => true + 'novalidate' => true, ]) !!}
@@ -22,13 +22,7 @@ {{ Form::textareaGroup('description', trans('general.description'), null, null, ['rows' => '3', 'required' => 'required']) }} - {{ Form::selectGroup('group', trans('general.group_by'), 'folder', $groups, 'category') }} - - {{ Form::selectGroup('period', trans('general.period'), 'calendar', $periods, 'yearly') }} - - {{ Form::selectGroup('basis', trans('general.basis'), 'file', $basises, 'accrual') }} - - {{ Form::selectGroup('chart', trans_choice('general.charts', 1), 'chart-pie', $charts, 'line') }} +
diff --git a/resources/views/common/reports/edit.blade.php b/resources/views/common/reports/edit.blade.php index f71355d4f..5ef6ea18f 100644 --- a/resources/views/common/reports/edit.blade.php +++ b/resources/views/common/reports/edit.blade.php @@ -12,7 +12,7 @@ '@keydown' => 'form.errors.clear($event.target.name)', 'role' => 'form', 'class' => 'form-loading-button', - 'novalidate' => true + 'novalidate' => true, ]) !!}
@@ -23,13 +23,21 @@ {{ Form::textareaGroup('description', trans('general.description'), null, null, ['rows' => '3', 'required' => 'required']) }} - {{ Form::selectGroup('group', trans('general.group_by'), 'folder', $groups, $report->group) }} + @foreach($class->getFields() as $field) + @php $type = $field['type']; @endphp - {{ Form::selectGroup('period', trans('general.period'), 'calendar', $periods, $report->period) }} - - {{ Form::selectGroup('basis', trans('general.basis'), 'file', $basises, $report->basis) }} - - {{ Form::selectGroup('chart', trans_choice('general.charts', 1), 'chart-pie', $charts, $report->chart) }} + @if (($type == 'textGroup') || ($type == 'emailGroup') || ($type == 'passwordGroup')) + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['icon'], $field['attributes']) }} + @elseif ($type == 'textareaGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title']) }} + @elseif ($type == 'selectGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['icon'], $field['values'], $report->settings->{$field['name']}, $field['attributes']) }} + @elseif ($type == 'radioGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], isset($report->settings->{$field['name']}) ? $report->settings->{$field['name']} : 1, $field['enable'], $field['disable'], $field['attributes']) }} + @elseif ($type == 'checkboxGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['items'], $report->settings->{$field['name']}, $field['id'], $field['attributes']) }} + @endif + @endforeach
diff --git a/resources/views/partials/reports/fields.blade.php b/resources/views/partials/reports/fields.blade.php new file mode 100644 index 000000000..c4ff87da4 --- /dev/null +++ b/resources/views/partials/reports/fields.blade.php @@ -0,0 +1,15 @@ +@foreach($fields as $field) + @php $type = $field['type']; @endphp + + @if (($type == 'textGroup') || ($type == 'emailGroup') || ($type == 'passwordGroup')) + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['icon'], $field['attributes']) }} + @elseif ($type == 'textareaGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title']) }} + @elseif ($type == 'selectGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['icon'], $field['values'], $field['selected'], $field['attributes']) }} + @elseif ($type == 'radioGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], 1, $field['enable'], $field['disable'], $field['attributes']) }} + @elseif ($type == 'checkboxGroup') + {{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['items'], $field['value'], $field['id'], $field['attributes']) }} + @endif +@endforeach diff --git a/resources/views/partials/reports/filter.blade.php b/resources/views/partials/reports/filter.blade.php index 56d037601..2c76b3e08 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, + 'url' => 'common/reports/' . $class->model->id, 'role' => 'form', 'method' => 'GET', ]) !!} diff --git a/resources/views/partials/reports/header.blade.php b/resources/views/partials/reports/header.blade.php index 8fabf97ac..89bc4053d 100644 --- a/resources/views/partials/reports/header.blade.php +++ b/resources/views/partials/reports/header.blade.php @@ -1,4 +1,4 @@ -@section('title', $class->report->name) +@section('title', $class->model->name) @section('new_button') diff --git a/resources/views/partials/reports/print.blade.php b/resources/views/partials/reports/print.blade.php index 3c3fa65f2..d41ca2ec9 100644 --- a/resources/views/partials/reports/print.blade.php +++ b/resources/views/partials/reports/print.blade.php @@ -1,9 +1,9 @@ @extends('layouts.print') -@section('title', $class->report->name) +@section('title', $class->model->name) @section('content') - @if($class->report->chart) + @if($class->model->settings->chart) @include($class->views['chart']) @endif diff --git a/resources/views/partials/reports/show.blade.php b/resources/views/partials/reports/show.blade.php index e5f72eea0..e5d9de068 100644 --- a/resources/views/partials/reports/show.blade.php +++ b/resources/views/partials/reports/show.blade.php @@ -6,7 +6,7 @@
@include($class->views['filter']) - @if($class->report->chart) + @if(!empty($class->model->settings->chart)) @include($class->views['chart']) @endif diff --git a/resources/views/partials/reports/table/header.blade.php b/resources/views/partials/reports/table/header.blade.php index 265f7aa44..e56d91cae 100644 --- a/resources/views/partials/reports/table/header.blade.php +++ b/resources/views/partials/reports/table/header.blade.php @@ -1,7 +1,7 @@ - @if ($table == 'default') - {{ $class->groups[$class->report->group] }} + @if (($table == 'default') && !empty($class->groups)) + {{ $class->groups[$class->model->settings->group] }} @else {{ $table }} @endif diff --git a/routes/admin.php b/routes/admin.php index 059874a6b..9ab83ef6b 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -37,7 +37,7 @@ Route::group(['prefix' => 'common'], function () { Route::get('reports/{report}/print', 'Common\Reports@print')->name('reports.print'); Route::get('reports/{report}/export', 'Common\Reports@export')->name('reports.export'); - Route::get('reports/groups', 'Common\Reports@groups')->name('reports.groups'); + Route::get('reports/fields', 'Common\Reports@fields')->name('reports.fields'); Route::resource('reports', 'Common\Reports'); });