change the bundle and fix the bugs
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Reports;
|
||||
|
||||
use App\Exports\V3\RoadPatrols\CountryActivity;
|
||||
use App\Exports\V3\RoadPatrols\ProvinceActivity;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\Province;
|
||||
use App\Models\RoadPatrol;
|
||||
use App\Services\Cartables\RoadPatrol\ReportService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadPatrolReportController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
public function countryPatrolActivity(Request $request, ReportService $roadPatrolTableService): JsonResponse
|
||||
{
|
||||
$activities = $roadPatrolTableService->countryActivity($request);
|
||||
|
||||
$provinces = Province::all(['id', 'name_fa']);
|
||||
|
||||
return $this->successResponse([
|
||||
'activities' => $activities['data'],
|
||||
'provinces' => $provinces
|
||||
]);
|
||||
}
|
||||
|
||||
public function provincePatrolActivity(Request $request, ReportService $roadPatrolTableService): JsonResponse
|
||||
{
|
||||
$request->validate(["province_id" => "required",]);
|
||||
|
||||
$activities = $roadPatrolTableService->provinceActivity($request);
|
||||
|
||||
$edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']);
|
||||
|
||||
return $this->successResponse([
|
||||
'activities' => $activities['data'],
|
||||
'edarateShahri' => $edarateShahri,
|
||||
]);
|
||||
}
|
||||
|
||||
public function countryActivityExcel(Request $request, ReportService $roadPatrolTableService): BinaryFileResponse
|
||||
{
|
||||
$activities = $roadPatrolTableService->countryActivity($request);
|
||||
$provinces = Province::all(['id', 'name_fa']);
|
||||
|
||||
$name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
|
||||
return Excel::download(new CountryActivity([
|
||||
'activities' => $activities,
|
||||
'provinces' => $provinces,
|
||||
]), $name);
|
||||
}
|
||||
|
||||
public function provinceActivityExcel(Request $request, ReportService $roadPatrolTableService): BinaryFileResponse
|
||||
{
|
||||
$activities = $roadPatrolTableService->provinceActivity($request);
|
||||
$edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']);
|
||||
|
||||
$name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
|
||||
return Excel::download(new ProvinceActivity([
|
||||
'activities' => $activities,
|
||||
'edarateShahri' => $edarateShahri,
|
||||
]), $name);
|
||||
}
|
||||
|
||||
public function activitiesOnMap(Request $request): JsonResponse
|
||||
{
|
||||
$date_from = $request->from_date ? $request->from_date .' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$date_to = $request->date_to ? $request->date_to.' 23:59:59' : now()->addDay()->startOfDay()->toDateTimeString();
|
||||
$provinceId = $request->province_id;
|
||||
$edareId = $request->edare_id;
|
||||
|
||||
$data = RoadPatrol::query()
|
||||
->when($provinceId, fn($query, $provinceId) => $query->where('province_id', '=', $provinceId))
|
||||
->when($edareId, fn($query, $edareId) => $query->where('edare_id', '=', $edareId))
|
||||
->whereBetween('created_at', [$date_from, $date_to])
|
||||
->select('id', 'start_lat', 'start_lon')
|
||||
->get();
|
||||
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function showOnMap(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol->load(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\RoadPatrole;
|
||||
namespace App\Http\Controllers\V3\Dashboard\RoadPatrol;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
@@ -56,14 +56,14 @@ class DetailController extends Controller
|
||||
{
|
||||
return $this->successResponse($roadPatrol);
|
||||
}
|
||||
public function roadPatrolMachine(RoadPatrol $roadPatrol): JsonResponse
|
||||
|
||||
public function machines(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol->cmmsMachines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number']));
|
||||
}
|
||||
|
||||
public function roadPatrolRahdar(RoadPatrol $roadPatrol): JsonResponse
|
||||
public function rahdaran(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol->rahdaran()->get(['rahdaran.id', 'rahdaran.name', 'rahdaran.code']));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\RoadPatrole;
|
||||
namespace App\Http\Controllers\V3\Dashboard\RoadPatrol;
|
||||
|
||||
|
||||
use App\Enums\MissionStates;
|
||||
@@ -30,63 +30,23 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
class OperatorController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
public function index(Request $request, OperatorService $roadPatrolTableService): JsonResponse
|
||||
|
||||
public function index(Request $request, OperatorService $operatorService): JsonResponse
|
||||
{
|
||||
$data = $roadPatrolTableService->operatorCartableReport($request);
|
||||
$data = $operatorService->dataTable($request);
|
||||
return response()->json($data);
|
||||
}
|
||||
public function operatorCartableReport(Request $request, OperatorService $roadPatrolTableService): BinaryFileResponse
|
||||
public function excel(Request $request, OperatorService $operatorService): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل عملیات گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
$data = $roadPatrolTableService->operatorCartableReport($request, true);
|
||||
$data = $operatorService->dataTable($request, true);
|
||||
return Excel::download(new OperatorCartableReport($data['data']), $name);
|
||||
}
|
||||
public function delete(DeleteRequest $request, RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
if ($request->type == 1) {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
$roadPatrol->observedItems()->delete();
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
} else {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
if ($roadPatrol->observedItems) {
|
||||
foreach ($roadPatrol->observedItems as $index => $observed_item) {
|
||||
if ($observed_item->roadItemProject) {
|
||||
$road_item = $observed_item->roadItemProject;
|
||||
|
||||
if ($road_item->files()->exists()) {
|
||||
Storage::delete('public/' . $road_item->files[0]->path);
|
||||
Storage::delete('public/' . $road_item->files[1]->path);
|
||||
$road_item->files()->delete();
|
||||
}
|
||||
|
||||
$road_item->delete();
|
||||
}
|
||||
|
||||
$observed_item->delete();
|
||||
}
|
||||
}
|
||||
auth()->user()->addActivityComplete(1144);
|
||||
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
}
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->edarate_ostani_id || is_null($user->city_id)) {
|
||||
return $this->errorResponse('امکان ثبت فعالیت برای ادارات استانی وجود ندارد!');
|
||||
}
|
||||
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$edare_id = $user->edarate_shahri_id ?? $user->edarate_ostani_id;
|
||||
$edare_name = $user->edarate_shahri_id ? $user->edarate_shahri_name : $user->edarate_ostani_name;
|
||||
|
||||
@@ -94,7 +54,7 @@ class OperatorController extends Controller
|
||||
$request, $edare_id,
|
||||
$edare_name, $nominatimService, $user
|
||||
) {
|
||||
$mission = Mission::findOrFail($request->mission_id);
|
||||
$mission = Mission::query()->findOrFail($request->mission_id);
|
||||
|
||||
if ($mission->status !== MissionStates::START_MISSION->value) {
|
||||
throw ValidationException::withMessages([
|
||||
@@ -239,4 +199,38 @@ class OperatorController extends Controller
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function delete(DeleteRequest $request, RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
if ($request->type == 1) {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
$roadPatrol->observedItems()->delete();
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
} else {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
if ($roadPatrol->observedItems) {
|
||||
foreach ($roadPatrol->observedItems as $index => $observed_item) {
|
||||
if ($observed_item->roadItemProject) {
|
||||
$road_item = $observed_item->roadItemProject;
|
||||
|
||||
if ($road_item->files()->exists()) {
|
||||
Storage::delete('public/' . $road_item->files[0]->path);
|
||||
Storage::delete('public/' . $road_item->files[1]->path);
|
||||
$road_item->files()->delete();
|
||||
}
|
||||
|
||||
$road_item->delete();
|
||||
}
|
||||
|
||||
$observed_item->delete();
|
||||
}
|
||||
}
|
||||
auth()->user()->addActivityComplete(1144);
|
||||
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
}
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\RoadPatrole;
|
||||
namespace App\Http\Controllers\V3\Dashboard\RoadPatrol;
|
||||
|
||||
use App\Exports\V3\RoadPatrols\CountryActivity;
|
||||
use App\Exports\V3\RoadPatrols\ProvinceActivity;
|
||||
@@ -70,9 +70,9 @@ class ReportController extends Controller
|
||||
$data['observed_items'] = $observed_items;
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
public function countryPatrolActivity(Request $request, ReportService $roadPatrolTableService): JsonResponse
|
||||
public function countryPatrolActivity(Request $request, ReportService $reportService): JsonResponse
|
||||
{
|
||||
$activities = $roadPatrolTableService->countryActivity($request);
|
||||
$activities = $reportService->countryActivity($request);
|
||||
|
||||
$provinces = Province::all(['id', 'name_fa']);
|
||||
|
||||
@@ -82,11 +82,11 @@ class ReportController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function provincePatrolActivity(Request $request, ReportService $roadPatrolTableService): JsonResponse
|
||||
public function provincePatrolActivity(Request $request, ReportService $reportService): JsonResponse
|
||||
{
|
||||
$request->validate(["province_id" => "required",]);
|
||||
|
||||
$activities = $roadPatrolTableService->provinceActivity($request);
|
||||
$activities = $reportService->provinceActivity($request);
|
||||
|
||||
$edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']);
|
||||
|
||||
@@ -96,9 +96,9 @@ class ReportController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function countryActivityExcel(Request $request, ReportService $roadPatrolTableService): BinaryFileResponse
|
||||
public function countryActivityExcel(Request $request, ReportService $reportService): BinaryFileResponse
|
||||
{
|
||||
$activities = $roadPatrolTableService->countryActivity($request);
|
||||
$activities = $reportService->countryActivity($request);
|
||||
$provinces = Province::all(['id', 'name_fa']);
|
||||
|
||||
$name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
@@ -109,9 +109,9 @@ class ReportController extends Controller
|
||||
]), $name);
|
||||
}
|
||||
|
||||
public function provinceActivityExcel(Request $request, ReportService $roadPatrolTableService): BinaryFileResponse
|
||||
public function provinceActivityExcel(Request $request, ReportService $reportService): BinaryFileResponse
|
||||
{
|
||||
$activities = $roadPatrolTableService->provinceActivity($request);
|
||||
$activities = $reportService->provinceActivity($request);
|
||||
$edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']);
|
||||
|
||||
$name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
@@ -1,23 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\RoadPatrole;
|
||||
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\SupervisiorService;
|
||||
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;
|
||||
public function index(Request $request, SupervisiorService $roadPatrolTableService): JsonResponse
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(Request $request, SupervisorService $supervisorService): JsonResponse
|
||||
{
|
||||
$data = $roadPatrolTableService->supervisorCartableReport($request);
|
||||
$data = $supervisorService->dataTable($request);
|
||||
|
||||
foreach ($data['data'] as $road_patrol) {
|
||||
if (Gate::allows('gate-supervise-road-item', $road_patrol)) {
|
||||
@@ -29,13 +34,14 @@ class SupervisorController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
public function supervisorCartableReport(Request $request, SupervisiorService $roadPatrolTableService): BinaryFileResponse
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function excel(Request $request, SupervisorService $supervisorService): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
$data = $roadPatrolTableService->supervisorCartableReport($request, true);
|
||||
$data = $supervisorService->dataTable($request, true);
|
||||
return Excel::download(new SupervisorCartableReport($data['data']), $name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,350 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Enums\MissionStates;
|
||||
use App\Exports\V3\RoadPatrols\OperatorCartableReport;
|
||||
use App\Exports\V3\RoadPatrols\SupervisorCartableReport;
|
||||
use App\Facades\Sms\Sms;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\RoadPatrol\DeleteRequest;
|
||||
use App\Http\Requests\V3\RoadPatrol\StoreRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\Mission;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\RoadPatrol;
|
||||
use App\Services\Cartables\RoadPatrol\ReportService;
|
||||
use App\Services\NominatimService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadPatrolProjectController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function supervisorIndex(Request $request, ReportService $roadPatrolTableService): JsonResponse
|
||||
{
|
||||
$data = $roadPatrolTableService->supervisorCartableReport($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);
|
||||
}
|
||||
|
||||
public function delete(DeleteRequest $request, RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
if ($request->type == 1) {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
$roadPatrol->observedItems()->delete();
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
} else {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
if ($roadPatrol->observedItems) {
|
||||
foreach ($roadPatrol->observedItems as $index => $observed_item) {
|
||||
if ($observed_item->roadItemProject) {
|
||||
$road_item = $observed_item->roadItemProject;
|
||||
|
||||
if ($road_item->files()->exists()) {
|
||||
Storage::delete('public/'. $road_item->files[0]->path);
|
||||
Storage::delete('public/'. $road_item->files[1]->path);
|
||||
$road_item->files()->delete();
|
||||
}
|
||||
|
||||
$road_item->delete();
|
||||
}
|
||||
|
||||
$observed_item->delete();
|
||||
}
|
||||
}
|
||||
auth()->user()->addActivityComplete(1144);
|
||||
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
}
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function supervisorCartableReport(Request $request, ReportService $roadPatrolTableService): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
$data = $roadPatrolTableService->supervisorCartableReport($request, true);
|
||||
return Excel::download(new SupervisorCartableReport($data['data']), $name);
|
||||
}
|
||||
|
||||
public function operatorIndex(Request $request, ReportService $roadPatrolTableService): JsonResponse
|
||||
{
|
||||
$data = $roadPatrolTableService->operatorCartableReport($request);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->edarate_ostani_id || is_null($user->city_id)) {
|
||||
return $this->errorResponse('امکان ثبت فعالیت برای ادارات استانی وجود ندارد!');
|
||||
}
|
||||
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$edare_id = $user->edarate_shahri_id ?? $user->edarate_ostani_id;
|
||||
$edare_name = $user->edarate_shahri_id ? $user->edarate_shahri_name : $user->edarate_ostani_name;
|
||||
|
||||
$road_patrol = DB::transaction(function () use ($request, $edare_id,
|
||||
$edare_name, $nominatimService, $user) {
|
||||
$mission = Mission::findOrFail($request->mission_id);
|
||||
|
||||
if ($mission->status !== MissionStates::START_MISSION->value) {
|
||||
throw ValidationException::withMessages([
|
||||
'mission_id' => 'ماموریت انتخاب شده هنوز شروع نشده است.',
|
||||
]);
|
||||
}
|
||||
|
||||
$road_patrol = RoadPatrol::query()->create([
|
||||
'operator_id' => $user->id,
|
||||
'operator_name' => $user->name,
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'edare_id' => $edare_id,
|
||||
'edare_name' => $edare_name,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'distance' => $request->distance,
|
||||
'start_time' => $request->start_time,
|
||||
'end_time' => $request->end_time,
|
||||
'description' => $request->description ?? null,
|
||||
'fuel_consumption' => $request->fuel_consumption,
|
||||
'vehicle_runtime' => $request->vehicle_runtime,
|
||||
'stop_points' => json_encode($request->stop_points),
|
||||
]);
|
||||
|
||||
$road_patrol->rahdaran()->attach($request->road_patrol_rahdaran_id);
|
||||
$road_patrol->cmmsMachines()->attach($request->road_patrol_machines_id);
|
||||
|
||||
if ($request->observed_items) {
|
||||
foreach ($request->observed_items as $index => $item) {
|
||||
$info_item = InfoItem::where('item', $item['item_id'])
|
||||
->where('sub_item', $item['sub_item_id'])
|
||||
->firstOrFail();
|
||||
|
||||
$item_start_coordinates = explode(',', $item['start_point']);
|
||||
|
||||
$observed_item = $road_patrol->observedItems()->create([
|
||||
'item_id' => $info_item->item,
|
||||
'item_name' => $info_item->item_str,
|
||||
'sub_item_id' => $info_item->sub_item,
|
||||
'sub_item_name' => $info_item->sub_item_str,
|
||||
'local_name' => $item['local_name'],
|
||||
'description' => $item['description'] ?? null,
|
||||
'start_lat' => $item_start_coordinates[0],
|
||||
'start_lon' => $item_start_coordinates[1],
|
||||
]);
|
||||
|
||||
$item_end_coordinates = null;
|
||||
if ($item['instant_action'] == 0) {
|
||||
$priority = [
|
||||
1 => 'عادی',
|
||||
2 => 'فوری',
|
||||
3 => 'آنی',
|
||||
];
|
||||
$observed_item->priority = $item['priority'];
|
||||
$observed_item->priority_fa = $priority[$item['priority']];
|
||||
$observed_item->save();
|
||||
} elseif ($item['instant_action'] == 1) {
|
||||
if ($info_item->needs_end_point) {
|
||||
if (!isset($item['end_point'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.end_point" => __('validation.required', ['attribute' => 'end_point']),
|
||||
]);
|
||||
}
|
||||
|
||||
$item_end_coordinates = explode(',', $item['end_point']);
|
||||
}
|
||||
|
||||
$before_image = null;
|
||||
$after_image = null;
|
||||
if ($info_item->needs_image) {
|
||||
if (!isset($item['before_image'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.before_image" => __('validation.required', ['attribute' => 'before_image']),
|
||||
]);
|
||||
}
|
||||
if (!isset($item['after_image'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.after_image" => __('validation.required', ['attribute' => 'after_image']),
|
||||
]);
|
||||
}
|
||||
|
||||
$before_image = $item['before_image'];
|
||||
$after_image = $item['after_image'];
|
||||
}
|
||||
|
||||
$start_time = Carbon::createFromFormat('Y-m-d H:i', $request->start_time);
|
||||
$end_time = Carbon::createFromFormat('Y-m-d H:i', $request->end_time);
|
||||
$activity_date = $start_time->average($end_time);
|
||||
|
||||
$attributes = [
|
||||
'start_lat' => $item_start_coordinates[0],
|
||||
'start_lng' => $item_start_coordinates[1],
|
||||
'end_lat' => $item_end_coordinates ? $item_end_coordinates[0] : null,
|
||||
'end_lng' => $item_end_coordinates ? $item_end_coordinates[1] : null,
|
||||
'item' => $info_item->item,
|
||||
'item_fa' => $info_item->item_str,
|
||||
'sub_item' => $info_item->sub_item,
|
||||
'sub_item_fa' => $info_item->sub_item_str,
|
||||
'sub_item_data' => $item['amount'],
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'user_name' => $user->name,
|
||||
'start_way_id' => $nominatimService->get_way_id_from_nominatim($item_start_coordinates[0], $item_start_coordinates[1]),
|
||||
'end_way_id' => $item_end_coordinates ? $nominatimService->get_way_id_from_nominatim($item_end_coordinates[0], $item_end_coordinates[1]) : null,
|
||||
'unit_fa' => $info_item->sub_item_unit,
|
||||
'created_at_fa' => verta(Carbon::now())->format('Y-m-d H:i:s'),
|
||||
'info_id' => $info_item->id,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => $user->edarate_shahri_name,
|
||||
'activity_date' => $activity_date->format('Y-m-d'),
|
||||
'activity_time' => $activity_date->format('H:i:s'),
|
||||
];
|
||||
|
||||
$road_item = RoadItemsProject::store($user, $attributes, $before_image, $after_image, $observed_item->id);
|
||||
|
||||
if ($road_item === -1) {
|
||||
return $this->errorResponse('اقدام مربوطه قبلا رسیدگی شده است.');
|
||||
}
|
||||
|
||||
$road_item->rahdaran()->attach($item['road_item_rahdaran_id']);
|
||||
$road_item->cmmsMachines()->attach($item['road_item_machines_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1147);
|
||||
|
||||
Sms::sendSms($request->officer_phone_number,
|
||||
"گشت راهداری با کد یکتای $road_patrol->id در تاریخ ".verta(\Carbon\Carbon::now())->format('Y-m-d H:i:s')." با شماره شما در سامانه RMS ثبت شد. \n لینک دریافت گزارش : \n https://rms.rmto.ir/v2/road_patrols/operator/report/$road_patrol->id"
|
||||
);
|
||||
return $road_patrol;
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function getReport(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
$data = [
|
||||
'serial_no' => $roadPatrol->id,
|
||||
'province_fa' => $roadPatrol->province_fa,
|
||||
'edare_name' => $roadPatrol->edare_name,
|
||||
'start_time' => $roadPatrol->start_time,
|
||||
'end_time' => $roadPatrol->end_time,
|
||||
'officer_name' => $roadPatrol->officer_name,
|
||||
'officer_plaque' => $roadPatrol->officer_plaque,
|
||||
'officer_phone_number' => $roadPatrol->officer_phone_number,
|
||||
'created_at' => $roadPatrol->created_at
|
||||
];
|
||||
|
||||
$observed_items = array();
|
||||
if($roadPatrol->observedItems) {
|
||||
foreach ($roadPatrol->observedItems as $index => $observed_item) {
|
||||
$observed_items[] = [
|
||||
'item' => $observed_item->item_name,
|
||||
'sub_item' => $observed_item->sub_item_name,
|
||||
'local_name' => $observed_item->local_name,
|
||||
'description' => $observed_item->description,
|
||||
'priority_fa' => $observed_item->priority_fa,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['observed_items'] = $observed_items;
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function map(Request $request): JsonResponse
|
||||
{
|
||||
$province = $request->province_id;
|
||||
$edare_shahri = $request->edare_shahri_id;
|
||||
$status = $request->status;
|
||||
$rms_status = $request->rms_status;
|
||||
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$date_from = $request->from_date.' 00:00:00';
|
||||
$date_to = $request->date_to.' 23:59:59';
|
||||
} else {
|
||||
$date_from = Date('Y-m-d');
|
||||
$date_to = new \DateTime('tomorrow');
|
||||
$date_to = $date_to->format('Y-m-d');
|
||||
}
|
||||
|
||||
$projects = RoadObserved::query()->select(['id', 'lng', 'lat','status'])
|
||||
->whereBetween('created_at', [$date_from, $date_to])
|
||||
->when($province, function ($query) use ($province) {
|
||||
return $query->where('province_id', '=', $province);
|
||||
})
|
||||
->when($rms_status, function ($query) use ($rms_status) {
|
||||
if ($rms_status == 2) {
|
||||
return $query->where('rms_status', '<>', 0);
|
||||
} else {
|
||||
return $query->where('rms_status', '=', 0);
|
||||
}
|
||||
})
|
||||
->when($edare_shahri, function ($query) use ($edare_shahri) {
|
||||
return $query->where('edarate_shahri_id', '=', $edare_shahri);
|
||||
})
|
||||
->when($status, function ($query) use ($status) {
|
||||
return $query->where('status', '=', $status);
|
||||
})
|
||||
->get();
|
||||
return $this->successResponse($projects);
|
||||
}
|
||||
|
||||
public function show(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol);
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request, ReportService $roadPatrolTableService): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل عملیات گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
$data = $roadPatrolTableService->operatorCartableReport($request, true);
|
||||
return Excel::download(new OperatorCartableReport($data['data']), $name);
|
||||
}
|
||||
|
||||
public function roadPatrolMachine(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol->cmmsMachines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number']));
|
||||
}
|
||||
|
||||
public function roadPatrolRahdar(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol->rahdaran()->get(['rahdaran.id', 'rahdaran.name', 'rahdaran.code']));
|
||||
}
|
||||
}
|
||||
@@ -9,27 +9,22 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OperatorService
|
||||
{
|
||||
|
||||
|
||||
public function operatorCartableReport(Request $request, $loadRelations = false)
|
||||
public function dataTable(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(
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
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'
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
47
app/Services/Cartables/RoadPatrol/SupervisorService.php
Normal file
47
app/Services/Cartables/RoadPatrol/SupervisorService.php
Normal 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'
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ use App\Http\Controllers\V3\Dashboard\ObservedItemController;
|
||||
use App\Http\Controllers\V3\Dashboard\OtpManagementController;
|
||||
use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController;
|
||||
use App\Http\Controllers\V3\Dashboard\RoadMaintenanceStationController;
|
||||
use App\Http\Controllers\V3\Dashboard\RoadPatrolProjectController;
|
||||
use App\Http\Controllers\V3\Dashboard\RoadPatrol\ReportController;
|
||||
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\OperatorController;
|
||||
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\OperatorReportController;
|
||||
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\SupervisorController;
|
||||
@@ -28,7 +28,6 @@ use App\Http\Controllers\V3\NotificationController;
|
||||
use App\Http\Controllers\V3\PermissionManagementController;
|
||||
use App\Http\Controllers\V3\ProfileController;
|
||||
use App\Http\Controllers\V3\RahdaranController;
|
||||
use App\Http\Controllers\V3\RoadPatrole\ReportController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('admin/permissions', function () {
|
||||
@@ -200,28 +199,24 @@ Route::prefix('road_patrol')
|
||||
->group(function () {
|
||||
Route::prefix('details')
|
||||
->name('details.')
|
||||
->controller(\App\Http\Controllers\V3\RoadPatrole\DetailController::class)
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\RoadPatrol\DetailController::class)
|
||||
->group(function () {
|
||||
Route::get('/{roadPatrol}', 'show')
|
||||
->name('show');
|
||||
Route::get('/{roadPatrol}', 'show')->name('show');
|
||||
Route::get('/machines/{roadPatrol}', 'roadPatrolMachine')->name('roadPatrolMachine');
|
||||
Route::get('/rahdaran/{roadPatrol}', 'roadPatrolRahdar')->name('roadPatrolRahdar');
|
||||
});
|
||||
|
||||
Route::prefix('operator')
|
||||
->name('operator.')
|
||||
->controller(App\Http\Controllers\V3\RoadPatrole\OperatorController::class)
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')
|
||||
->middleware('permission:add-road-patrol')
|
||||
->name('index');
|
||||
|
||||
Route::get('/report', 'operatorCartableReport')
|
||||
->name('cartableReport');
|
||||
Route::get('/', 'index')->middleware('permission:add-road-patrol')->name('index');
|
||||
Route::get('/excel', 'excel')->name('excel');
|
||||
Route::post('/delete/{roadPatrol}', 'delete')
|
||||
->middleware('permission:partial-delete-road-patrol|complete-delete-road-patrol')
|
||||
->name('delete');
|
||||
Route::post('/store', 'store')
|
||||
->middleware('permission:add-road-patrol')
|
||||
->middleware(['permission:add-road-patrol', 'validate-store-access'])
|
||||
->name('store');
|
||||
});
|
||||
|
||||
@@ -235,19 +230,17 @@ Route::prefix('road_patrol')
|
||||
Route::get('/province_activity_excel', 'provinceActivityExcel')->name('provinceActivityExcel');
|
||||
Route::get('/activities_on_map', 'activitiesOnMap')->name('activitiesOnMap');
|
||||
Route::get('/show_on_map/{roadPatrol}', 'showOnMap')->name('showOnMap');
|
||||
Route::get('/{roadPatrol}', 'getReport')
|
||||
->name('getReport');
|
||||
Route::get('/{roadPatrol}', 'getReport')->name('getReport');
|
||||
});
|
||||
|
||||
Route::prefix('supervisor')
|
||||
->name('supervisor.')
|
||||
->controller(App\Http\Controllers\V3\RoadPatrole\SupervisorController::class)
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\RoadPatrol\SupervisorController::class)
|
||||
->group(function () {
|
||||
Route::get('/','index')
|
||||
->middleware(['permission:show-road-patrol-supervise-cartable|show-road-patrol-supervise-cartable-province'])
|
||||
->name('index');
|
||||
Route::get('/report', 'supervisorCartableReport')
|
||||
->name('cartableReport');
|
||||
|
||||
Route::get('/excel', 'excel')->name('excel');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user