refactor road observation
This commit is contained in:
@@ -1,54 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables;
|
||||
namespace App\Services\Cartables\RoadObservation;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadObservationTableService
|
||||
class OperatorService
|
||||
{
|
||||
use ApiResponse;
|
||||
public function supervisorCartableIndex(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'StartTime_DateTime',
|
||||
'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'rms_start_latlng',
|
||||
'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', 'edarate_shahri_id',
|
||||
'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa',
|
||||
'status', 'status_fa', 'supervisor_description', 'supervising_time', 'image_after', 'image_before'
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('show-fast-react')) {
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->whereNotNull('road_observeds.status')
|
||||
->select($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-province'))
|
||||
{
|
||||
if (is_null($user->province_id))
|
||||
{
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('road_observeds.province_id', $user->province_id)
|
||||
->whereNotNull('road_observeds.status')
|
||||
->select($fields);
|
||||
}
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*']);
|
||||
}
|
||||
|
||||
public function operatorCartableIndex(Request $request)
|
||||
public function cartableIndex(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
@@ -60,13 +20,13 @@ class RoadObservationTableService
|
||||
'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time'
|
||||
];
|
||||
|
||||
$query = RoadObserved::query()
|
||||
->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->whereNotNull('status')
|
||||
->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id')
|
||||
->where('edarate_shahri_id', $user->edarate_shahri_id)
|
||||
->select($fields);
|
||||
$query = RoadObserved::query()
|
||||
->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->whereNotNull('status')
|
||||
->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id')
|
||||
->where('edarate_shahri_id', $user->edarate_shahri_id)
|
||||
->select($fields);
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
53
app/Services/Cartables/RoadObservation/ReportService.php
Normal file
53
app/Services/Cartables/RoadObservation/ReportService.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\RoadObservation;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ReportService
|
||||
{
|
||||
public function index(Request $request): array
|
||||
{
|
||||
$fromDate = $request->from_date . ' 00:00:00';
|
||||
$toDate = $request->date_to . ' 23:59:59';
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage',
|
||||
'road_observeds.id',
|
||||
'Title',
|
||||
'road_observeds.created_at',
|
||||
'lat',
|
||||
'lng',
|
||||
'FeatureTypeTitle',
|
||||
'Description',
|
||||
'MobileForSendEventSms',
|
||||
'road_observeds.province_id',
|
||||
'province_fa',
|
||||
'city_fa',
|
||||
'edarate_shahri.name_fa',
|
||||
'rms_last_activity_fa',
|
||||
'rms_description'
|
||||
];
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', "<>", 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->whereBetween('road_observeds.created_at', [$fromDate, $toDate])
|
||||
->select($fields);
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*']
|
||||
);
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Services/Cartables/RoadObservation/SupervisorService.php
Normal file
47
app/Services/Cartables/RoadObservation/SupervisorService.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\RoadObservation;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SupervisorService
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'StartTime_DateTime',
|
||||
'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'rms_start_latlng',
|
||||
'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', 'edarate_shahri_id',
|
||||
'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa',
|
||||
'status', 'status_fa', 'supervisor_description', 'supervising_time', 'image_after', 'image_before'
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('show-fast-react')) {
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->whereNotNull('road_observeds.status')
|
||||
->select($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-province'))
|
||||
{
|
||||
if (is_null($user->province_id))
|
||||
{
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('road_observeds.province_id', $user->province_id)
|
||||
->whereNotNull('road_observeds.status')
|
||||
->select($fields);
|
||||
}
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user