akaunting 3.0 (the last dance)

This commit is contained in:
Burak Civan
2022-06-01 10:15:55 +03:00
parent cead09f6d4
commit d9c0764572
3812 changed files with 126831 additions and 102949 deletions

View File

@ -9,7 +9,6 @@ use App\Jobs\Common\DeleteReport;
use App\Jobs\Common\UpdateReport;
use App\Models\Common\Report;
use App\Utilities\Reports as Utility;
use Illuminate\Support\Facades\Cache;
class Reports extends Controller
{
@ -37,7 +36,7 @@ class Reports extends Controller
$reports = Report::orderBy('name')->get();
foreach ($reports as $report) {
if (!Utility::canShow($report->class)) {
if (Utility::cannotShow($report->class)) {
continue;
}
@ -47,17 +46,20 @@ class Reports extends Controller
continue;
}
$ttl = 3600 * 6; // 6 hours
$totals[$report->id] = Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
return $class->getGrandTotal();
});
$icons[$report->id] = $class->getIcon();
$categories[$class->getCategory()][] = $report;
if (empty($categories[$class->getCategory()])) {
$categories[$class->getCategory()] = [
'name' => $class->getCategory(),
'description' => $class->getCategoryDescription(),
'reports' => [$report],
];
} else {
$categories[$class->getCategory()]['reports'][] = $report;
}
}
return $this->response('common.reports.index', compact('categories', 'totals', 'icons'));
return $this->response('common.reports.index', compact('categories', 'icons'));
}
/**
@ -68,15 +70,12 @@ class Reports extends Controller
*/
public function show(Report $report)
{
if (!Utility::canShow($report->class)) {
if (Utility::cannotShow($report->class)) {
abort(403);
}
$class = Utility::getClassInstance($report);
// Update cache
Cache::put('reports.totals.' . $report->id, $class->getGrandTotal());
return $class->show();
}
@ -215,7 +214,7 @@ class Reports extends Controller
*/
public function print(Report $report)
{
if (!Utility::canShow($report->class)) {
if (Utility::cannotShow($report->class)) {
abort(403);
}
@ -230,7 +229,7 @@ class Reports extends Controller
*/
public function export(Report $report)
{
if (!Utility::canShow($report->class)) {
if (Utility::cannotShow($report->class)) {
abort(403);
}
@ -257,7 +256,7 @@ class Reports extends Controller
$fields = (new $class())->getFields();
$html = view('partials.reports.fields', compact('fields'))->render();
$html = view('components.reports.fields', compact('fields'))->render();
return response()->json([
'success' => true,
@ -266,23 +265,4 @@ class Reports extends Controller
'html' => $html,
]);
}
/**
* Clear the cache of the resource.
*
* @return Response
*/
public function clear(Report $report)
{
$data = Utility::getClassInstance($report)->getGrandTotal();
Cache::put('reports.totals.' . $report->id, $data);
return response()->json([
'success' => true,
'error' => false,
'data' => $data,
'message' => '',
]);
}
}