create new category for Road patrole service
This commit is contained in:
35
app/Services/Cartables/RoadPatrol/OperatorService.php
Normal file
35
app/Services/Cartables/RoadPatrol/OperatorService.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\RoadPatrol;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\RoadPatrol;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OperatorService
|
||||
{
|
||||
|
||||
|
||||
public function operatorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$query = RoadPatrol::query()
|
||||
->select([
|
||||
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description',
|
||||
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
|
||||
])
|
||||
->where('operator_id', '=', auth()->user()->id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables;
|
||||
namespace App\Services\Cartables\RoadPatrol;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\RoadPatrol;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadPatrolTableService
|
||||
class ReportService
|
||||
{
|
||||
public function supervisorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) {
|
||||
$query = RoadPatrol::query()
|
||||
->select([
|
||||
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description',
|
||||
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
|
||||
])
|
||||
->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')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query = RoadPatrol::query()
|
||||
->select([
|
||||
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description',
|
||||
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
|
||||
])
|
||||
->where('province_id', '=', $user->province_id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$query = RoadPatrol::query()
|
||||
->select([
|
||||
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description',
|
||||
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
|
||||
])
|
||||
->where('operator_id', '=', auth()->user()->id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function countryActivity(Request $request): array
|
||||
{
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
49
app/Services/Cartables/RoadPatrol/SupervisiorService.php
Normal file
49
app/Services/Cartables/RoadPatrol/SupervisiorService.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\RoadPatrol;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\RoadPatrol;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SupervisiorService
|
||||
{
|
||||
public function supervisorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) {
|
||||
$query = RoadPatrol::query()
|
||||
->select([
|
||||
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description',
|
||||
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
|
||||
])
|
||||
->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')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query = RoadPatrol::query()
|
||||
->select([
|
||||
'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description',
|
||||
'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points'
|
||||
])
|
||||
->where('province_id', '=', $user->province_id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user