change the bundle and fix the bugs

This commit is contained in:
2025-06-23 10:12:08 +03:30
parent 4e463de0d3
commit 47dd5afb47
10 changed files with 138 additions and 596 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\V3\Dashboard\RoadPatrol;
use App\Exports\V3\RoadPatrols\SupervisorCartableReport;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Services\Cartables\RoadPatrol\SupervisorService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Maatwebsite\Excel\Facades\Excel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Throwable;
class SupervisorController extends Controller
{
use ApiResponse;
/**
* @throws Throwable
*/
public function index(Request $request, SupervisorService $supervisorService): JsonResponse
{
$data = $supervisorService->dataTable($request);
foreach ($data['data'] as $road_patrol) {
if (Gate::allows('gate-supervise-road-item', $road_patrol)) {
$road_patrol['can_supervise'] = 1;
} else {
$road_patrol['can_supervise'] = 0;
}
}
return response()->json($data);
}
/**
* @throws Throwable
*/
public function excel(Request $request, SupervisorService $supervisorService): BinaryFileResponse
{
$name = 'گزارش از کارتابل ارزیابی گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
$data = $supervisorService->dataTable($request, true);
return Excel::download(new SupervisorCartableReport($data['data']), $name);
}
}