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\Services\Cartables\RoadPatrol;
use App\Exceptions\ProhibitedAction;
use App\Facades\DataTable\DataTableFacade;
use App\Models\RoadPatrol;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Throwable;
class SupervisorService
{
/**
* @throws Throwable
*/
public function dataTable(Request $request, $loadRelations = false)
{
$user = auth()->user();
$query = null;
if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) {
$query = RoadPatrol::query()
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
}
elseif ($user->hasPermissionTo('show-road-patrol-supervise-cartable-province'))
{
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
$query = RoadPatrol::query()
->where('province_id', '=', $user->province_id)
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
}
return DataTableFacade::run(
$query,
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: [
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name',
'start_time', 'end_time', 'created_at', 'description',
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
]
);
}
}