updated category structure of reports
This commit is contained in:
parent
bc46b1f8f6
commit
dca5a64122
@ -32,8 +32,6 @@ abstract class Report
|
|||||||
|
|
||||||
public $filters = [];
|
public $filters = [];
|
||||||
|
|
||||||
public $category = 'income-expense';
|
|
||||||
|
|
||||||
public $icon = 'fa fa-chart-pie';
|
public $icon = 'fa fa-chart-pie';
|
||||||
|
|
||||||
public $indents = [
|
public $indents = [
|
||||||
@ -80,14 +78,14 @@ abstract class Report
|
|||||||
|
|
||||||
abstract public function getTotals();
|
abstract public function getTotals();
|
||||||
|
|
||||||
public function getName()
|
public function getDefaultName()
|
||||||
{
|
{
|
||||||
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 $this->category;
|
return trans('reports.income_expense');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIcon()
|
public function getIcon()
|
||||||
|
@ -19,24 +19,23 @@ class Reports extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$classes = [];
|
$classes = $categories = [];
|
||||||
$reports = ['income-expense' => [], 'accounting' => []];
|
|
||||||
|
|
||||||
$items = Report::collect();
|
$reports = Report::collect();
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($reports as $report) {
|
||||||
$class = Utility::getClassInstance($item);
|
$class = Utility::getClassInstance($report);
|
||||||
|
|
||||||
if (!$class->canRead()) {
|
if (!$class->canRead()) {
|
||||||
continue;
|
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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,8 +9,6 @@ use App\Utilities\Recurring;
|
|||||||
|
|
||||||
class ExpenseSummary extends Report
|
class ExpenseSummary extends Report
|
||||||
{
|
{
|
||||||
public $category = 'income-expense';
|
|
||||||
|
|
||||||
public $icon = 'fa fa-shopping-cart';
|
public $icon = 'fa fa-shopping-cart';
|
||||||
|
|
||||||
public $chart = [
|
public $chart = [
|
||||||
@ -28,11 +26,16 @@ class ExpenseSummary extends Report
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getName()
|
public function getDefaultName()
|
||||||
{
|
{
|
||||||
return trans('reports.summary.expense');
|
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();
|
||||||
|
@ -10,15 +10,18 @@ use App\Utilities\Recurring;
|
|||||||
|
|
||||||
class IncomeExpenseSummary extends Report
|
class IncomeExpenseSummary extends Report
|
||||||
{
|
{
|
||||||
public $category = 'income-expense';
|
|
||||||
|
|
||||||
public $icon = 'fa fa-chart-pie';
|
public $icon = 'fa fa-chart-pie';
|
||||||
|
|
||||||
public function getName()
|
public function getDefaultName()
|
||||||
{
|
{
|
||||||
return trans('reports.summary.income_expense');
|
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();
|
||||||
|
@ -9,8 +9,6 @@ use App\Utilities\Recurring;
|
|||||||
|
|
||||||
class IncomeSummary extends Report
|
class IncomeSummary extends Report
|
||||||
{
|
{
|
||||||
public $category = 'income-expense';
|
|
||||||
|
|
||||||
public $icon = 'fa fa-money-bill';
|
public $icon = 'fa fa-money-bill';
|
||||||
|
|
||||||
public $chart = [
|
public $chart = [
|
||||||
@ -28,11 +26,16 @@ class IncomeSummary extends Report
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getName()
|
public function getDefaultName()
|
||||||
{
|
{
|
||||||
return trans('reports.summary.income');
|
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();
|
||||||
|
@ -11,17 +11,20 @@ use App\Utilities\Recurring;
|
|||||||
|
|
||||||
class ProfitLoss extends Report
|
class ProfitLoss extends Report
|
||||||
{
|
{
|
||||||
public $category = 'accounting';
|
|
||||||
|
|
||||||
public $icon = 'fa fa-heart';
|
public $icon = 'fa fa-heart';
|
||||||
|
|
||||||
public $chart = false;
|
public $chart = false;
|
||||||
|
|
||||||
public function getName()
|
public function getDefaultName()
|
||||||
{
|
{
|
||||||
return trans('reports.profit_loss');
|
return trans('reports.profit_loss');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCategory()
|
||||||
|
{
|
||||||
|
return trans('general.accounting');
|
||||||
|
}
|
||||||
|
|
||||||
public function setViews()
|
public function setViews()
|
||||||
{
|
{
|
||||||
parent::setViews();
|
parent::setViews();
|
||||||
|
@ -15,17 +15,20 @@ class TaxSummary extends Report
|
|||||||
{
|
{
|
||||||
use Currencies;
|
use Currencies;
|
||||||
|
|
||||||
public $category = 'accounting';
|
|
||||||
|
|
||||||
public $icon = 'fa fa-percent';
|
public $icon = 'fa fa-percent';
|
||||||
|
|
||||||
public $chart = false;
|
public $chart = false;
|
||||||
|
|
||||||
public function getName()
|
public function getDefaultName()
|
||||||
{
|
{
|
||||||
return trans('reports.summary.tax');
|
return trans('reports.summary.tax');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCategory()
|
||||||
|
{
|
||||||
|
return trans('general.accounting');
|
||||||
|
}
|
||||||
|
|
||||||
public function setViews()
|
public function setViews()
|
||||||
{
|
{
|
||||||
parent::setViews();
|
parent::setViews();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Utilities;
|
namespace App\Utilities;
|
||||||
|
|
||||||
|
use App\Models\Common\Report;
|
||||||
use App\Models\Module\Module;
|
use App\Models\Module\Module;
|
||||||
|
|
||||||
class Reports
|
class Reports
|
||||||
@ -10,7 +11,7 @@ class Reports
|
|||||||
{
|
{
|
||||||
$classes = [];
|
$classes = [];
|
||||||
|
|
||||||
$core_classes = [
|
$list = [
|
||||||
'App\Reports\IncomeSummary',
|
'App\Reports\IncomeSummary',
|
||||||
'App\Reports\ExpenseSummary',
|
'App\Reports\ExpenseSummary',
|
||||||
'App\Reports\IncomeExpenseSummary',
|
'App\Reports\IncomeExpenseSummary',
|
||||||
@ -18,35 +19,25 @@ class Reports
|
|||||||
'App\Reports\ProfitLoss',
|
'App\Reports\ProfitLoss',
|
||||||
];
|
];
|
||||||
|
|
||||||
static::parseClasses($classes, $core_classes);
|
Module::enabled()->each(function ($module) use (&$list) {
|
||||||
|
|
||||||
$modules = Module::enabled()->get();
|
|
||||||
|
|
||||||
foreach ($modules as $module) {
|
|
||||||
$m = module($module->alias);
|
$m = module($module->alias);
|
||||||
|
|
||||||
// Check if the module exists and has reports
|
|
||||||
if (!$m || empty($m->get('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) {
|
foreach ($list as $class) {
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = (new $class())->getName();
|
$classes[$class] = (new $class())->getDefaultName();
|
||||||
|
|
||||||
$classes[$class] = $name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getGroups()
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,13 @@ class Widgets
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = (new $class())->getDefaultName();
|
$classes[$class] = (new $class())->getDefaultName();
|
||||||
|
|
||||||
$classes[$class] = $name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $classes;
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getInstance($model)
|
public static function getClassInstance($model)
|
||||||
{
|
{
|
||||||
if (is_string($model)) {
|
if (is_string($model)) {
|
||||||
$model = Widget::where('class', $model)->first();
|
$model = Widget::where('class', $model)->first();
|
||||||
@ -63,7 +61,7 @@ class Widgets
|
|||||||
|
|
||||||
public static function show($model, ...$arguments)
|
public static function show($model, ...$arguments)
|
||||||
{
|
{
|
||||||
if (!$class = static::getInstance($model)) {
|
if (!$class = static::getClassInstance($model)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="row mb-4">
|
<div class="row mb-4">
|
||||||
|
@foreach($categories as $name => $reports)
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h3 id="stats">{{ trans('reports.income_expense') }}</h3>
|
<h3>{{ $name }}</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@foreach($reports['income-expense'] as $report)
|
@foreach($reports as $report)
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="card card-stats">
|
<div class="card card-stats">
|
||||||
<span>
|
<span>
|
||||||
@ -63,56 +63,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
<div class="col-md-12">
|
|
||||||
<h3 id="stats">{{ trans('general.accounting') }}</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@foreach($reports['accounting'] as $report)
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="card card-stats">
|
|
||||||
<span>
|
|
||||||
<div class="dropdown card-action-button">
|
|
||||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
<i class="fa fa-ellipsis-v text-primary"></i>
|
|
||||||
</a>
|
|
||||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
|
||||||
@permission('create-common-reports')
|
|
||||||
<a class="dropdown-item" href="{{ route('reports.edit', $report->id) }}">{{ trans('general.edit') }}</a>
|
|
||||||
<div class="dropdown-divider"></div>
|
|
||||||
@endpermission
|
|
||||||
@permission('delete-common-reports')
|
|
||||||
{!! Form::deleteLink($report, 'common/reports') !!}
|
|
||||||
@endpermission
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<a href="{{ route('reports.show', $report->id) }}">
|
|
||||||
<h5 class="card-title text-uppercase text-muted mb-0">{{ $report->name }}</h5>
|
|
||||||
<span class="h2 font-weight-bold mb-0">{{ $classes[$report->id]->getTotal() }}</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="{{ route('reports.show', $report->id) }}">
|
|
||||||
<div class="icon icon-shape bg-orange text-white rounded-circle shadow">
|
|
||||||
<i class="{{ $classes[$report->id]->getIcon() }}"></i>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p class="mt-3 mb-0 text-sm">
|
|
||||||
<a href="{{ route('reports.show', $report->id) }}">
|
|
||||||
<span class="text-nowrap">{{ $report->description }}</span>
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
{!! Form::open([
|
{!! Form::open([
|
||||||
'url' => 'common/reports/' . $class->report->id . '/display',
|
'url' => 'common/reports/' . $class->report->id,
|
||||||
'role' => 'form',
|
'role' => 'form',
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
]) !!}
|
]) !!}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user