From c754a2a7bae563f78c773e5c7de12eab5e01b708 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Apr 2025 10:11:50 +0330 Subject: [PATCH] change directory --- .../SafetyAndPrivacy/OperatorController.php | 230 ++++++++++++++++++ .../OperatorReportController.php | 52 ++++ .../SafetyAndPrivacy/SupervisorController.php | 56 +++++ .../SupervisorReportController.php | 56 +++++ routes/v3.php | 77 ++++-- 5 files changed, 444 insertions(+), 27 deletions(-) create mode 100644 app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php create mode 100644 app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReportController.php create mode 100644 app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php create mode 100644 app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorReportController.php diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php new file mode 100644 index 00000000..bce8f08e --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php @@ -0,0 +1,230 @@ +json($safetyAndPrivacyTableService->operatorDatatable($request)); + } + + /** + * @throws Throwable + */ + public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + { + $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + $data = $safetyAndPrivacyTableService->operatorDatatable($request); + return Excel::download(new OperatorCartableReport($data['data']), $name); + } + + public function firstStepStore(FirstStepStoreRequest $request, NominatimService $nominatimService): JsonResponse + { + $user = auth()->user(); + + $coordinates = explode(',', $request->point); + $item = InfoItem::query() + ->where('id', $request->info_id) + ->where('item', 17) + ->firstOrFail(); + + DB::transaction(function () use ($request, $coordinates, $item, $nominatimService, $user) + { + $step = SafetyAndPrivacySteps::SHENASAEI->value; + $safety_and_privacy = SafetyAndPrivacy::query()->create([ + 'lat' => $coordinates[0], + 'lon' => $coordinates[1], + 'operator_id' => $user->id, + 'operator_name' => $user->name, + 'province_id' => $user->province_id, + 'province_fa' => $user->province_fa, + 'info_id' => $item->id, + 'info_fa' => $item->sub_item_str, + 'city_id' => $user->city_id, + 'city_fa' => $user->city_fa, + 'activity_date_time' => $request->activity_date." ".$request->activity_time, + 'edare_shahri_id' => $user->edarate_shahri_id, + 'edare_shahri_name' => $user->edarate_shahri_name, + 'way_id' => $nominatimService->get_way_id_from_nominatim($coordinates[0], $coordinates[1]), + 'axis_type_id' => $request->axis_type_id, + 'axis_type_name' => AxisTypes::name($request->axis_type_id), + 'step' => $step, + 'step_fa' => SafetyAndPrivacySteps::name($step), + 'is_finished' => false, + ]); + + $safety_and_privacy->recognize_picture = $request->has('recognize_picture') ? + FileFacade::save($request->recognize_picture, "safety_and_privacy/{$safety_and_privacy->id}") : + null; + $safety_and_privacy->save(); + + $user->addActivityComplete(1134); + }); + + return $this->successResponse(); + } + + public function secondStepStore(SafetyAndPrivacy $safetyAndPrivacy, SecondStepStoreRequest $request): JsonResponse + { + $user = auth()->user(); + + DB::transaction(function () use ($request, $safetyAndPrivacy, $user) { + + $need_judiciary = $request->need_judiciary; + + $judiciary_document = []; + if ($need_judiciary) { + foreach ($request->judiciary_document as $index => $file) { + $judiciary_document[] = FileFacade::save( + $file, + "safety_and_privacy/{$safetyAndPrivacy->id}/judiciary_document" + ); + } + } + + $step = SafetyAndPrivacySteps::MOSTANADAT_GAZAEI->value; + $safetyAndPrivacy->update([ + 'step' => $step, + 'step_fa' => SafetyAndPrivacySteps::name($step), + 'judiciary_document' => $need_judiciary ? serialize($judiciary_document) : null, + 'judiciary_document_upload_date' => $need_judiciary ? now() : null, + 'need_judiciary' => $need_judiciary, + ]); + + $user->addActivityComplete(1135); + }); + + return $this->successResponse(); + } + + public function thirdStepStore(SafetyAndPrivacy $safetyAndPrivacy, ThirdStepStoreRequest $request): JsonResponse + { + $user = auth()->user(); + + DB::transaction(function () use ($request, $safetyAndPrivacy, $user) { + $step = SafetyAndPrivacySteps::BARKHORD->value; + $safetyAndPrivacy->update([ + 'step' => $step, + 'step_fa' => SafetyAndPrivacySteps::name($step), + 'action_picture' => FileFacade::save($request->action_picture, "safety_and_privacy/{$safetyAndPrivacy->id}/action_picture"), + 'action_picture_document_upload_date' => now(), + 'action_date' => $request->action_date, + 'is_finished' => true, + 'final_description' => 'پیام سیستمی : این عملیات پس از طی تمامی گام ها خاتمه یافت' + ]); + + $user->addActivityComplete(1136); + }); + + return $this->successResponse(); + } + + public function update(SafetyAndPrivacy $safetyAndPrivacy, UpdateRequest $request): JsonResponse + { + DB::transaction(function () use ($request, $safetyAndPrivacy) { + $safetyAndPrivacy->update([ + 'axis_type_id' => $request->axis_type_id, + 'axis_type_name' => AxisTypes::name($request->axis_type_id), + ]); + + auth()->user()->addActivityComplete(1168); + }); + + return $this->successResponse(); + } + + public function show(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + return $this->successResponse($safetyAndPrivacy); + } + + public function destroy(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + FileFacade::deleteDirectory("safety_and_privacy/{$safetyAndPrivacy->id}"); + + DB::transaction(function () use ($safetyAndPrivacy) + { + auth()->user()->addActivityComplete(1155); + $safetyAndPrivacy->delete(); + }); + + return $this->successResponse(); + } + + public function deserialize(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $judiciaries = $safetyAndPrivacy->judiciary_document ? unserialize($safetyAndPrivacy->judiciary_document) : []; + + $result = []; + + foreach ($judiciaries as $judiciary) { + $result[] = Storage::disk('public')->url($judiciary); + } + + return $this->successResponse($result); + } + + public function subItems(): JsonResponse + { + return $this->successResponse(InfoItem::query() + ->where('item', '=', 17) + ->select('id', 'item', 'item_str', 'sub_item_str as name', 'sub_item_unit as unit', 'needs_image', 'needs_end_point', 'sub_item') + ->get()); + } + + public function finish(FinishRequest $request, SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $status_id = SafetyAndPrivacyStatus::PENDING->value; + + $safetyAndPrivacy->update([ + 'is_finished' => 1, + 'final_description' => $request->final_description, + 'status' => $status_id, + 'status_fa' => SafetyAndPrivacyStatus::name($status_id), + ]); + + return $this->successResponse(); + } + + public function map(Request $request): JsonResponse + { + return response()->json(DataTableFacade::run( + SafetyAndPrivacy::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: ['id', 'lat', 'lon', 'step'] + )); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReportController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReportController.php new file mode 100644 index 00000000..31b41c52 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReportController.php @@ -0,0 +1,52 @@ +countryActivity($request); + return $this->successResponse([ + 'activities' => $data, + 'provinces' => Province::all(['id', 'name_fa']) + ]); + } + + public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + { + $data = $safetyAndPrivacyTableService->provinceActivity($request); + return $this->successResponse([ + 'activities' => $data, + 'edarateShahri' => EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']), + ]); + } + + public function countryExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + { + $data = $safetyAndPrivacyTableService->countryActivity($request); + $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new CountryActivityReport($data), $name); + } + + public function provinceExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + { + $data = $safetyAndPrivacyTableService->provinceActivity($request); + $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new ProvinceActivityReport($data, $request), $name); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php new file mode 100644 index 00000000..240a7219 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php @@ -0,0 +1,56 @@ +json($safetyAndPrivacyTableService->supervisorDataTable($request)); + } + + public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + { + $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + $data = $safetyAndPrivacyTableService->supervisorDataTable($request); + return Excel::download(new SupervisorCartableReport($data['data']), $name); + } + + public function confirm(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $status_id = SafetyAndPrivacyStatus::CONFIRM->value; + + $safetyAndPrivacy->update([ + 'status' => $status_id, + 'status_fa' => SafetyAndPrivacyStatus::name($status_id), + ]); + + return $this->successResponse(); + } + + public function reject(RejectRequest $request, SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $status_id = SafetyAndPrivacyStatus::REJECT->value; + + $safetyAndPrivacy->update([ + 'status' => $status_id, + 'status_fa' => SafetyAndPrivacyStatus::name($status_id), + 'supervisor_description' => $request->supervisor_description + ]); + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorReportController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorReportController.php new file mode 100644 index 00000000..60b3ab87 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorReportController.php @@ -0,0 +1,56 @@ +countryActivity($request); + return $this->successResponse([ + 'activities' => $data, + 'provinces' => Province::all(['id', 'name_fa']) + ]); + } + + public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + { + $data = $safetyAndPrivacyTableService->provinceActivity($request); + return $this->successResponse([ + 'activities' => $data, + 'edarateShahri' => EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']), + ]); + } + + public function countryExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + { + $data = $safetyAndPrivacyTableService->countryActivity($request); + $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new CountryActivityReport($data), $name); + } + + public function provinceExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + { + $data = $safetyAndPrivacyTableService->provinceActivity($request); + $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new ProvinceActivityReport($data, $request), $name); + } +} diff --git a/routes/v3.php b/routes/v3.php index 7d6b2e8f..98953436 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -18,7 +18,10 @@ use App\Http\Controllers\V3\Dashboard\Reports\SafetyAndPrivacyReportController; use App\Http\Controllers\V3\Dashboard\RoadItemsProjectController; use App\Http\Controllers\V3\Dashboard\RoadObservationController; use App\Http\Controllers\V3\Dashboard\RoadPatrolProjectController; -use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacyController; +use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\OperatorController; +use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\OperatorReportController; +use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\SupervisorController; +use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\SupervisorReportController; use App\Http\Controllers\V3\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; use App\Http\Controllers\V3\LogListManagementController; @@ -335,39 +338,59 @@ Route::prefix('log_list') Route::prefix('safety_and_privacy') ->name('SafetyAndPrivacy.') - ->controller(SafetyAndPrivacyController::class) ->group(function () { - Route::get('/operator_index', 'operatorIndex')->name('operatorIndex') - ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); - Route::get('/supervisor_index', 'supervisorIndex')->name('supervisorIndex') - ->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province'); - Route::get('/operator_excel_report', 'operatorExcelReport')->name('operatorExcelReport') - ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); - Route::get('/supervisor_excel_report', 'supervisorExcelReport')->name('supervisorExcelReport') - ->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province'); + Route::prefix('operator') + ->name('operator.') + ->controller(OperatorController::class) + ->group(function () { + Route::get('/', 'index')->name('index') + ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); + Route::get('/excel_report', 'excelReport')->name('excelReport') + ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); + Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware(['validate-store-access', 'permission:add-safety-and-privacy']); + Route::get('/sub_items', 'subItems')->name('subItems'); + Route::get('/map', 'map')->name('map'); + Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy']); + Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy']); + Route::post('/{safetyAndPrivacy}', 'update')->name('update')->middleware('permission:update-safety-and-privacy'); + Route::get('/{safetyAndPrivacy}', 'show')->name('show'); + Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); + Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize'); + Route::post('/finish/{safetyAndPrivacy}', 'finish')->name('finish'); + }); - Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware(['validate-store-access', 'permission:add-safety-and-privacy']); - Route::get('/sub_items', 'subItems')->name('subItems'); - Route::get('/map', 'map')->name('map'); - Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy']); - Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy']); - Route::post('/{safetyAndPrivacy}', 'update')->name('update')->middleware('permission:update-safety-and-privacy'); - Route::get('/{safetyAndPrivacy}', 'show')->name('show'); - Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); - Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize'); - Route::post('/confirm/{safetyAndPrivacy}', 'confirm')->name('confirm'); - Route::post('/reject/{safetyAndPrivacy}', 'reject')->name('reject'); - Route::post('/finish/{safetyAndPrivacy}', 'finish')->name('finish'); + Route::prefix('supervisor') + ->name('supervisor.') + ->controller(SupervisorController::class) + ->group(function () { + Route::get('/', 'index')->name('index') + ->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province'); + Route::get('/excel_report', 'excelReport')->name('excelReport') + ->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province'); + Route::post('/confirm/{safetyAndPrivacy}', 'confirm')->name('confirm'); + Route::post('/reject/{safetyAndPrivacy}', 'reject')->name('reject'); + }); }); Route::prefix('safety_and_privacy_report') ->name('SafetyAndPrivacyReport.') - ->controller(SafetyAndPrivacyReportController::class) ->group(function () { - Route::get('/country_activity', 'countryActivity')->name('countryActivity'); - Route::get('/province_activity', 'provinceActivity')->name('provinceActivity'); - Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity'); - Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity'); + Route::prefix('operator') + ->name('operator.') + ->controller(OperatorReportController::class) + ->group(function () { + Route::get('/country_activity', 'countryActivity')->name('countryActivity'); + Route::get('/province_activity', 'provinceActivity')->name('provinceActivity'); + Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity'); + Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity'); + }); + + Route::prefix('supervisor') + ->name('supervisor.') + ->controller(SupervisorReportController::class) + ->group(function () { + + }); }); Route::prefix('otp')