report fields

This commit is contained in:
denisdulici 2020-01-16 15:39:37 +03:00
parent 7d3c7619d1
commit 893970ffae
23 changed files with 233 additions and 230 deletions

View File

@ -2,6 +2,10 @@
namespace App\Abstracts; 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\Exports\Common\Reports as Export;
use App\Models\Common\Report as Model; use App\Models\Common\Report as Model;
use App\Traits\Charts; use App\Traits\Charts;
@ -14,7 +18,13 @@ abstract class Report
{ {
use Charts, DateTime; use Charts, DateTime;
public $report; public $model;
public $default_name = '';
public $category = 'reports.income_expense';
public $icon = 'fa fa-chart-pie';
public $year; public $year;
@ -28,12 +38,8 @@ abstract class Report
public $totals = []; public $totals = [];
public $groups = [];
public $filters = []; public $filters = [];
public $icon = 'fa fa-chart-pie';
public $indents = [ public $indents = [
'table_header' => '0px', 'table_header' => '0px',
'table_rows' => '0px', 'table_rows' => '0px',
@ -54,15 +60,15 @@ abstract class Report
'datasets' => [], 'datasets' => [],
]; ];
public function __construct(Model $report = null, $get_totals = true) public function __construct(Model $model = null, $get_totals = true)
{ {
$this->setGroups(); $this->setGroups();
if (!$report) { if (!$model) {
return; return;
} }
$this->report = $report; $this->model = $model;
$this->setYear(); $this->setYear();
$this->setViews(); $this->setViews();
@ -80,12 +86,16 @@ abstract class Report
public function getDefaultName() public function getDefaultName()
{ {
if (!empty($this->default_name)) {
return trans($this->default_name);
}
return Str::title(str_replace('_', ' ', Str::snake((new \ReflectionClass($this))->getShortName()))); return Str::title(str_replace('_', ' ', Str::snake((new \ReflectionClass($this))->getShortName())));
} }
public function getCategory() public function getCategory()
{ {
return trans('reports.income_expense'); return trans($this->category);
} }
public function getIcon() public function getIcon()
@ -108,7 +118,7 @@ abstract class Report
public function getTableRowList() public function getTableRowList()
{ {
$group_prl = Str::plural($this->report->group); $group_prl = Str::plural($this->model->settings->group);
if ($group_filter = request($group_prl)) { if ($group_filter = request($group_prl)) {
$rows = collect($this->filters[$group_prl])->filter(function ($value, $key) use ($group_filter) { $rows = collect($this->filters[$group_prl])->filter(function ($value, $key) use ($group_filter) {
@ -125,13 +135,13 @@ abstract class Report
{ {
$chart = new Chartjs(); $chart = new Chartjs();
$config = $this->chart[$this->report->chart]; $config = $this->chart[$this->model->settings->chart];
$default_options = $this->getLineChartOptions(); $default_options = $this->getLineChartOptions();
$options = array_merge($default_options, (array) $config['options']); $options = array_merge($default_options, (array) $config['options']);
$chart->type($this->report->chart) $chart->type($this->model->settings->chart)
->width((int) $config['width']) ->width((int) $config['width'])
->height((int) $config['height']) ->height((int) $config['height'])
->options($options) ->options($options)
@ -147,7 +157,7 @@ abstract class Report
} }
} else { } else {
foreach ($this->totals as $total) { 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') ->backgroundColor(isset($config['backgroundColor']) ? $config['backgroundColor'] : '#6da252')
->color(isset($config['color']) ? $config['color'] : '#6da252') ->color(isset($config['color']) ? $config['color'] : '#6da252')
->options([ ->options([
@ -173,7 +183,7 @@ abstract class Report
public function export() 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() public function setYear()
@ -208,12 +218,12 @@ abstract class Report
public function setDates() 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(); $start = $this->getFinancialStart()->copy()->$function();
for ($j = 1; $j <= 12; $j++) { for ($j = 1; $j <= 12; $j++) {
switch ($this->report->period) { switch ($this->model->settings->period) {
case 'yearly': case 'yearly':
$start->addYear(); $start->addYear();
@ -260,12 +270,14 @@ abstract class Report
public function setFilters() public function setFilters()
{ {
event(new \App\Events\Common\ReportFilterShowing($this)); event(new ReportFilterShowing($this));
} }
public function setGroups() public function setGroups()
{ {
event(new \App\Events\Common\ReportGroupShowing($this)); $this->groups = [];
event(new ReportGroupShowing($this));
} }
public function setRows() public function setRows()
@ -289,7 +301,7 @@ abstract class Report
$date = $this->getFormattedDate(Date::parse($item->$date_field)); $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]) || if (!isset($this->rows[$table][$item->$id_field]) ||
!isset($this->rows[$table][$item->$id_field][$date]) || !isset($this->rows[$table][$item->$id_field][$date]) ||
@ -322,21 +334,21 @@ abstract class Report
public function applyFilters($model, $args = []) public function applyFilters($model, $args = [])
{ {
event(new \App\Events\Common\ReportFilterApplying($this, $model, $args)); event(new ReportFilterApplying($this, $model, $args));
return $model; return $model;
} }
public function applyGroups($model, $args = []) public function applyGroups($model, $args = [])
{ {
event(new \App\Events\Common\ReportGroupApplying($this, $model, $args)); event(new ReportGroupApplying($this, $model, $args));
return $model; return $model;
} }
public function getFormattedDate($date) public function getFormattedDate($date)
{ {
switch ($this->report->period) { switch ($this->model->settings->period) {
case 'yearly': case 'yearly':
$i = $date->copy()->format($this->getYearlyDateFormat()); $i = $date->copy()->format($this->getYearlyDateFormat());
break; break;
@ -356,7 +368,7 @@ abstract class Report
public function getUrl($action = 'print') 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) { collect(request('accounts'))->each(function($item) use(&$print_url) {
$print_url .= '&accounts[]=' . $item; $print_url .= '&accounts[]=' . $item;
@ -372,4 +384,86 @@ abstract class Report
return $print_url; 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',
],
];
}
} }

View File

@ -13,8 +13,8 @@ class $NAME$ extends Provider
*/ */
public function boot() public function boot()
{ {
$this->loadTranslations();
$this->loadViews(); $this->loadViews();
$this->loadTranslations();
$this->loadMigrations(); $this->loadMigrations();
} }

View File

@ -21,7 +21,7 @@ class Reports extends Controller
{ {
$classes = $categories = []; $classes = $categories = [];
$reports = Report::collect(); $reports = Report::all();
foreach ($reports as $report) { foreach ($reports as $report) {
if (!Utility::canRead($report->class)) { if (!Utility::canRead($report->class)) {
@ -62,15 +62,7 @@ class Reports extends Controller
{ {
$classes = Utility::getClasses(); $classes = Utility::getClasses();
$groups = Utility::getGroups(); return view('common.reports.create', compact('classes'));
$periods = Utility::getPeriods();
$basises = Utility::getBasises();
$charts = Utility::getCharts();
return view('common.reports.create', compact('classes', 'groups', 'periods', 'basises', 'charts'));
} }
/** /**
@ -111,15 +103,9 @@ class Reports extends Controller
{ {
$classes = Utility::getClasses(); $classes = Utility::getClasses();
$groups = Utility::getGroups(); $class = Utility::getClassInstance($report);
$periods = Utility::getPeriods(); return view('common.reports.edit', compact('report', 'classes', 'class'));
$basises = Utility::getBasises();
$charts = Utility::getCharts();
return view('common.reports.edit', compact('report', 'classes', 'groups', 'periods', 'basises', 'charts'));
} }
/** /**
@ -207,11 +193,11 @@ class Reports extends Controller
} }
/** /**
* Get groups of the specified resource. * Get fields of the specified resource.
* *
* @return Response * @return Response
*/ */
public function groups() public function fields()
{ {
$class = request('class'); $class = request('class');
@ -219,16 +205,20 @@ class Reports extends Controller
return response()->json([ return response()->json([
'success' => false, 'success' => false,
'error' => true, 'error' => true,
'data' => false, 'message' => 'Class does not exist',
'message' => "Class doesn't exist", 'html' => '',
]); ]);
} }
$fields = (new $class())->getFields();
$html = view('partials.reports.fields', compact('fields'))->render();
return response()->json([ return response()->json([
'success' => true, 'success' => true,
'error' => false, 'error' => false,
'data' => (new $class())->groups,
'message' => '', 'message' => '',
'html' => $html,
]); ]);
} }
} }

View File

@ -259,58 +259,38 @@ class Version200 extends Listener
$rows = [ $rows = [
[ [
'company_id' => $company->id, 'company_id' => $company->id,
'class' => 'App\Reports\IncomeSummary',
'name' => trans('reports.summary.income'), 'name' => trans('reports.summary.income'),
'description' => trans('demo.reports.income'), 'description' => trans('demo.reports.income'),
'class' => 'App\Reports\IncomeSummary', 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
'group' => 'category',
'period' => 'monthly',
'basis' => 'accrual',
'chart' => 'line',
'enabled' => 1,
], ],
[ [
'company_id' => $company->id, 'company_id' => $company->id,
'class' => 'App\Reports\ExpenseSummary',
'name' => trans('reports.summary.expense'), 'name' => trans('reports.summary.expense'),
'description' => trans('demo.reports.expense'), 'description' => trans('demo.reports.expense'),
'class' => 'App\Reports\ExpenseSummary', 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
'group' => 'category',
'period' => 'monthly',
'basis' => 'accrual',
'chart' => 'line',
'enabled' => 1,
], ],
[ [
'company_id' => $company->id, 'company_id' => $company->id,
'class' => 'App\Reports\IncomeExpenseSummary',
'name' => trans('reports.summary.income_expense'), 'name' => trans('reports.summary.income_expense'),
'description' => trans('demo.reports.income_expense'), 'description' => trans('demo.reports.income_expense'),
'class' => 'App\Reports\IncomeExpenseSummary', 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
'group' => 'category',
'period' => 'monthly',
'basis' => 'accrual',
'chart' => 'line',
'enabled' => 1,
], ],
[ [
'company_id' => $company->id, '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'), 'name' => trans('reports.summary.tax'),
'description' => trans('demo.reports.tax'), 'description' => trans('demo.reports.tax'),
'class' => 'App\Reports\TaxSummary', 'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'],
'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,
], ],
]; ];

View File

@ -6,7 +6,6 @@ use App\Abstracts\Model;
class Report extends Model class Report extends Model
{ {
protected $table = 'reports'; protected $table = 'reports';
/** /**
@ -14,5 +13,14 @@ class Report extends Model
* *
* @var array * @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',
];
} }

View File

@ -9,6 +9,8 @@ use App\Utilities\Recurring;
class ExpenseSummary extends Report class ExpenseSummary extends Report
{ {
public $default_name = 'reports.summary.expense';
public $icon = 'fa fa-shopping-cart'; public $icon = 'fa fa-shopping-cart';
public $chart = [ 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() public function getTotals()
{ {
$payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) { switch ($this->model->settings->basis) {
case 'cash': case 'cash':
// Payments // Payments
$this->setTotals($payments, 'paid_at'); $this->setTotals($payments, 'paid_at');

View File

@ -10,24 +10,16 @@ use App\Utilities\Recurring;
class IncomeExpenseSummary extends Report class IncomeExpenseSummary extends Report
{ {
public $default_name = 'reports.summary.income_expense';
public $icon = 'fa fa-chart-pie'; 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() public function getTotals()
{ {
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $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(); $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) { switch ($this->model->settings->basis) {
case 'cash': case 'cash':
// Income Transactions // Income Transactions
$this->setTotals($income_transactions, 'paid_at', true); $this->setTotals($income_transactions, 'paid_at', true);

View File

@ -9,6 +9,8 @@ use App\Utilities\Recurring;
class IncomeSummary extends Report class IncomeSummary extends Report
{ {
public $default_name = 'reports.summary.income';
public $icon = 'fa fa-money-bill'; public $icon = 'fa fa-money-bill';
public $chart = [ 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() public function getTotals()
{ {
$transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) { switch ($this->model->settings->basis) {
case 'cash': case 'cash':
// Transactions // Transactions
$this->setTotals($transactions, 'paid_at'); $this->setTotals($transactions, 'paid_at');

View File

@ -11,20 +11,14 @@ use App\Utilities\Recurring;
class ProfitLoss extends Report class ProfitLoss extends Report
{ {
public $default_name = 'reports.profit_loss';
public $category = 'general.accounting';
public $icon = 'fa fa-heart'; public $icon = 'fa fa-heart';
public $chart = false; public $chart = false;
public function getDefaultName()
{
return trans('reports.profit_loss');
}
public function getCategory()
{
return trans('general.accounting');
}
public function setViews() public function setViews()
{ {
parent::setViews(); parent::setViews();
@ -73,7 +67,7 @@ class ProfitLoss extends Report
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $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(); $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) { switch ($this->model->settings->basis) {
case 'cash': case 'cash':
// Income Transactions // Income Transactions
$this->setTotals($income_transactions, 'paid_at', true, $this->tables['income']); $this->setTotals($income_transactions, 'paid_at', true, $this->tables['income']);

View File

@ -15,20 +15,14 @@ class TaxSummary extends Report
{ {
use Currencies; use Currencies;
public $default_name = 'reports.summary.tax';
public $category = 'general.accounting';
public $icon = 'fa fa-percent'; public $icon = 'fa fa-percent';
public $chart = false; public $chart = false;
public function getDefaultName()
{
return trans('reports.summary.tax');
}
public function getCategory()
{
return trans('general.accounting');
}
public function setViews() public function setViews()
{ {
parent::setViews(); parent::setViews();
@ -54,7 +48,7 @@ class TaxSummary extends Report
public function getTotals() public function getTotals()
{ {
switch ($this->report->basis) { switch ($this->model->settings->basis) {
case 'cash': case 'cash':
// Invoice Payments // Invoice Payments
$invoices = $this->applyFilters(Transaction::type('income')->isDocument()->with(['invoice', 'invoice.totals'])->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $invoices = $this->applyFilters(Transaction::type('income')->isDocument()->with(['invoice', 'invoice.totals'])->isNotTransfer(), ['date_field' => 'paid_at'])->get();

View File

@ -41,38 +41,6 @@ class Reports
return $classes; 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) public static function getClassInstance($model, $get_totals = true)
{ {
if (is_string($model)) { if (is_string($model)) {

View File

@ -110,8 +110,8 @@ class CoreV200 extends Migration
$table->integer('dashboard_id'); $table->integer('dashboard_id');
$table->string('class'); $table->string('class');
$table->string('name'); $table->string('name');
$table->text('settings')->nullable();
$table->integer('sort')->default(0); $table->integer('sort')->default(0);
$table->text('settings')->nullable();
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
@ -170,10 +170,7 @@ class CoreV200 extends Migration
$table->string('class'); $table->string('class');
$table->string('name'); $table->string('name');
$table->text('description'); $table->text('description');
$table->string('group'); $table->text('settings')->nullable();
$table->string('period');
$table->string('basis');
$table->string('chart');
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();

View File

@ -29,53 +29,38 @@ class Reports extends Seeder
$rows = [ $rows = [
[ [
'company_id' => $company_id, 'company_id' => $company_id,
'class' => 'App\Reports\IncomeSummary',
'name' => trans('reports.summary.income'), 'name' => trans('reports.summary.income'),
'description' => trans('demo.reports.income'), 'description' => trans('demo.reports.income'),
'class' => 'App\Reports\IncomeSummary', 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
'group' => 'category',
'period' => 'monthly',
'basis' => 'accrual',
'chart' => 'line',
], ],
[ [
'company_id' => $company_id, 'company_id' => $company_id,
'class' => 'App\Reports\ExpenseSummary',
'name' => trans('reports.summary.expense'), 'name' => trans('reports.summary.expense'),
'description' => trans('demo.reports.expense'), 'description' => trans('demo.reports.expense'),
'class' => 'App\Reports\ExpenseSummary', 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
'group' => 'category',
'period' => 'monthly',
'basis' => 'accrual',
'chart' => 'line',
], ],
[ [
'company_id' => $company_id, 'company_id' => $company_id,
'class' => 'App\Reports\IncomeExpenseSummary',
'name' => trans('reports.summary.income_expense'), 'name' => trans('reports.summary.income_expense'),
'description' => trans('demo.reports.income_expense'), 'description' => trans('demo.reports.income_expense'),
'class' => 'App\Reports\IncomeExpenseSummary', 'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
'group' => 'category',
'period' => 'monthly',
'basis' => 'accrual',
'chart' => 'line',
], ],
[ [
'company_id' => $company_id, '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'), 'name' => trans('reports.summary.tax'),
'description' => trans('demo.reports.tax'), 'description' => trans('demo.reports.tax'),
'class' => 'App\Reports\TaxSummary', 'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'],
'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',
], ],
]; ];

View File

@ -28,7 +28,7 @@ return [
'expense' => 'Monthly expense summary by category.', 'expense' => 'Monthly expense summary by category.',
'income_expense' => 'Monthly income vs expense by category.', 'income_expense' => 'Monthly income vs expense by category.',
'tax' => 'Quarterly tax summary by category.', 'tax' => 'Quarterly tax summary by category.',
'pl' => 'Quarterly profit & loss by category.', 'profit_loss' => 'Quarterly profit & loss by category.',
], ],
]; ];

View File

@ -11,7 +11,7 @@
'@keydown' => 'form.errors.clear($event.target.name)', '@keydown' => 'form.errors.clear($event.target.name)',
'role' => 'form', 'role' => 'form',
'class' => 'form-loading-button', 'class' => 'form-loading-button',
'novalidate' => true 'novalidate' => true,
]) !!} ]) !!}
<div class="card-body"> <div class="card-body">
@ -22,13 +22,7 @@
{{ Form::textareaGroup('description', trans('general.description'), null, null, ['rows' => '3', 'required' => 'required']) }} {{ Form::textareaGroup('description', trans('general.description'), null, null, ['rows' => '3', 'required' => 'required']) }}
{{ Form::selectGroup('group', trans('general.group_by'), 'folder', $groups, 'category') }} <component v-bind:is="report_fields"></component>
{{ 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') }}
</div> </div>
</div> </div>

View File

@ -12,7 +12,7 @@
'@keydown' => 'form.errors.clear($event.target.name)', '@keydown' => 'form.errors.clear($event.target.name)',
'role' => 'form', 'role' => 'form',
'class' => 'form-loading-button', 'class' => 'form-loading-button',
'novalidate' => true 'novalidate' => true,
]) !!} ]) !!}
<div class="card-body"> <div class="card-body">
@ -23,13 +23,21 @@
{{ Form::textareaGroup('description', trans('general.description'), null, null, ['rows' => '3', 'required' => 'required']) }} {{ 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) }} @if (($type == 'textGroup') || ($type == 'emailGroup') || ($type == 'passwordGroup'))
{{ Form::$type('settings[' . $field['name'] . ']', $field['title'], $field['icon'], $field['attributes']) }}
{{ Form::selectGroup('basis', trans('general.basis'), 'file', $basises, $report->basis) }} @elseif ($type == 'textareaGroup')
{{ Form::$type('settings[' . $field['name'] . ']', $field['title']) }}
{{ Form::selectGroup('chart', trans_choice('general.charts', 1), 'chart-pie', $charts, $report->chart) }} @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
</div> </div>
</div> </div>

View File

@ -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

View File

@ -1,6 +1,6 @@
<div class="card-header"> <div class="card-header">
{!! Form::open([ {!! Form::open([
'url' => 'common/reports/' . $class->report->id, 'url' => 'common/reports/' . $class->model->id,
'role' => 'form', 'role' => 'form',
'method' => 'GET', 'method' => 'GET',
]) !!} ]) !!}

View File

@ -1,4 +1,4 @@
@section('title', $class->report->name) @section('title', $class->model->name)
@section('new_button') @section('new_button')
<span> <span>

View File

@ -1,9 +1,9 @@
@extends('layouts.print') @extends('layouts.print')
@section('title', $class->report->name) @section('title', $class->model->name)
@section('content') @section('content')
@if($class->report->chart) @if($class->model->settings->chart)
@include($class->views['chart']) @include($class->views['chart'])
@endif @endif

View File

@ -6,7 +6,7 @@
<div class="card"> <div class="card">
@include($class->views['filter']) @include($class->views['filter'])
@if($class->report->chart) @if(!empty($class->model->settings->chart))
@include($class->views['chart']) @include($class->views['chart'])
@endif @endif

View File

@ -1,7 +1,7 @@
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
@if ($table == 'default') @if (($table == 'default') && !empty($class->groups))
<th>{{ $class->groups[$class->report->group] }}</th> <th>{{ $class->groups[$class->model->settings->group] }}</th>
@else @else
<th>{{ $table }}</th> <th>{{ $table }}</th>
@endif @endif

View File

@ -37,7 +37,7 @@ Route::group(['prefix' => 'common'], function () {
Route::get('reports/{report}/print', 'Common\Reports@print')->name('reports.print'); 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/{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'); Route::resource('reports', 'Common\Reports');
}); });