From c754a2a7bae563f78c773e5c7de12eab5e01b708 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Apr 2025 10:11:50 +0330 Subject: [PATCH 1/5] 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') From 65375bf399efa2d48ec2d5d428d718f3f1785382 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Apr 2025 10:51:11 +0330 Subject: [PATCH 2/5] add description section to second step --- .../SafetyAndPrivacy/OperatorController.php | 1 + .../SecondStepStoreRequest.php | 3 +- .../SafetyAndPrivacyTableService.php | 40 +++++++++---------- ...add_column_to_safety_and_privacy_table.php | 1 + 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php index bce8f08e..650a6a93 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php @@ -120,6 +120,7 @@ class OperatorController extends Controller 'judiciary_document' => $need_judiciary ? serialize($judiciary_document) : null, 'judiciary_document_upload_date' => $need_judiciary ? now() : null, 'need_judiciary' => $need_judiciary, + 'operator_description' => $request->operator_description, ]); $user->addActivityComplete(1135); diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php index 78e471ad..dc88a0b6 100644 --- a/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php +++ b/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php @@ -23,7 +23,8 @@ class SecondStepStoreRequest extends FormRequest { return [ 'need_judiciary' => 'required|boolean', - 'judiciary_document' => 'required|array', + 'operator_description' => 'required_if:need_judiciary,0|string', + 'judiciary_document' => 'required_if:need_judiciary,1|array', 'judiciary_document.*' => 'file', ]; } diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index 4e651ef4..f5d07ad4 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -28,42 +28,40 @@ class SafetyAndPrivacyTableService 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description' ]; - if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) { - $query = SafetyAndPrivacy::query()->select($fields); - } - elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) { - throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); - $query = SafetyAndPrivacy::query()->where('province_id', '=', $user->province_id)->select($fields); - } - elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) { - throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); - - $query = SafetyAndPrivacy::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id); - } + $query = SafetyAndPrivacy::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id); return DataTableFacade::run( $query, $request, allowedFilters: ['*'], - allowedSortings: ['*'] + allowedSortings: ['*'], + allowedSelects: $fields ); } + /** + * @throws Throwable + */ public function supervisorDataTable(Request $request) { $user = auth()->user(); - $fields = ['id','lat','lon','province_id','province_fa','city_id','city_fa','edare_shahri_id','edare_shahri_name', - 'recognize_picture','action_picture','operator_id','operator_name','way_id','created_at','updated_at','step', - 'info_id','info_fa','activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', - 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date' + $fields = [ + 'id','lat','lon', 'recognize_picture','action_picture','created_at','step', 'final_description', + 'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', + 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description' ]; - $query = SafetyAndPrivacy::query()->where([ - ['province_id', '=', $user->province_id], - ['is_finished', '=', 1] - ]); + $query = SafetyAndPrivacy::query()->where('is_finished', '=', 1); + + if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) + { + throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + + $query = $query->where('province_id', '=', $user->province_id); + } return DataTableFacade::run( $query, diff --git a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php index e78b6af7..d747836d 100644 --- a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php +++ b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php @@ -15,6 +15,7 @@ return new class extends Migration $table->boolean('is_finished')->nullable(); $table->integer('status')->nullable(); $table->string('status_fa')->nullable(); + $table->string('operator_description')->nullable(); $table->string('supervisor_description')->nullable(); $table->string('final_description')->nullable(); $table->boolean('need_judiciary')->nullable(); From 9a0f1522448b6ebf8982041e7eaec2a4e0008721 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Apr 2025 11:20:48 +0330 Subject: [PATCH 3/5] add prefix to routes --- .../SafetyAndPrivacyTableService.php | 4 ++-- ...add_column_to_safety_and_privacy_table.php | 2 +- routes/v3.php | 21 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index f5d07ad4..89e0ee0f 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -25,7 +25,7 @@ class SafetyAndPrivacyTableService $fields = [ 'id','lat','lon', 'recognize_picture','action_picture','created_at','step', 'final_description', 'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', - 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description' + 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description', 'operator_description' ]; throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); @@ -51,7 +51,7 @@ class SafetyAndPrivacyTableService $fields = [ 'id','lat','lon', 'recognize_picture','action_picture','created_at','step', 'final_description', 'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', - 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description' + 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description', 'operator_description' ]; $query = SafetyAndPrivacy::query()->where('is_finished', '=', 1); diff --git a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php index d747836d..63711b72 100644 --- a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php +++ b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php @@ -30,7 +30,7 @@ return new class extends Migration public function down(): void { Schema::table('safety_and_privacy', function (Blueprint $table) { - $table->dropColumn(['status', 'final_description', 'is_finished', 'supervisor_description', 'status_fa', 'need_judiciary']); + $table->dropColumn(['status', 'final_description', 'is_finished', 'supervisor_description', 'status_fa', 'need_judiciary', 'operator_description']); $table->text('judiciary_document')->change(); $table->dateTime('judiciary_document_upload_date')->change(); }); diff --git a/routes/v3.php b/routes/v3.php index 98953436..01f34693 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -339,24 +339,23 @@ Route::prefix('log_list') Route::prefix('safety_and_privacy') ->name('SafetyAndPrivacy.') ->group(function () { - Route::prefix('operator') - ->name('operator.') + Route::name('operator.') ->controller(OperatorController::class) ->group(function () { - Route::get('/', 'index')->name('index') + Route::get('operator', 'index')->name('index') ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); - Route::get('/excel_report', 'excelReport')->name('excelReport') + Route::get('operator/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::post('operator/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::post('operator/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy']); + Route::post('operator/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy']); + Route::post('operator/{safetyAndPrivacy}', 'update')->name('update')->middleware('permission:update-safety-and-privacy'); + Route::get('operator/{safetyAndPrivacy}', 'show')->name('show'); + Route::delete('operator/{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('operator/finish/{safetyAndPrivacy}', 'finish')->name('finish'); }); Route::prefix('supervisor') From d0b9803d8d928390c3ba8858548636687ef7b4a5 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Apr 2025 13:55:29 +0330 Subject: [PATCH 4/5] add notification count for supervise --- .../SafetyAndPrivacy/SupervisorController.php | 8 +++++ .../Controllers/V3/NotificationController.php | 33 ++++++++++++------- app/Models/SafetyAndPrivacy.php | 3 +- .../SafetyAndPrivacyTableService.php | 6 ++-- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php index 240a7219..f6ddb692 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php @@ -13,15 +13,23 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Throwable; class SupervisorController extends Controller { use ApiResponse; + + /** + * @throws Throwable + */ public function index(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse { return response()->json($safetyAndPrivacyTableService->supervisorDataTable($request)); } + /** + * @throws Throwable + */ public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse { $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index 833ba72c..b48536c5 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -91,23 +91,31 @@ class NotificationController extends Controller private function safetyAndPrivacyNotifications(): JsonResponse|array { $user = auth()->user(); - $safety_and_privacy = array(); + $safety_and_privacy = [ + 'supervise_cnt' => 0, + 'step_one' => 0, + 'step_two' => 0, + ]; if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) { - $activity = SafetyAndPrivacy::query() - ->selectRaw('count(*) as cnt, step') - ->groupby('step') - ->orderBy('step') + $supervise = SafetyAndPrivacy::query() + ->selectRaw('count(*) as cnt') + ->where([ + ['is_finished', '=', 1], + ['status', '=', 0], + ]) ->get(); } elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) { throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); - $activity = SafetyAndPrivacy::query() + $supervise = SafetyAndPrivacy::query() ->where('province_id', '=', $user->province_id) - ->selectRaw('count(*) as cnt, step') - ->groupby('step') - ->orderBy('step') + ->selectRaw('count(*) as cnt') + ->where([ + ['is_finished', '=', 1], + ['status', '=', 0], + ]) ->get(); } @@ -120,13 +128,14 @@ class NotificationController extends Controller ->groupby('step') ->orderBy('step') ->get(); - } - $step_one = $activity->where('step', '=', 1)->first(); - $step_two = $activity->where('step', '=', 2)->first(); + $step_one = $activity->where('step', '=', 1)->first(); + $step_two = $activity->where('step', '=', 2)->first(); + } $safety_and_privacy['step_one'] = $step_one->cnt ?? 0; $safety_and_privacy['step_two'] = $step_two->cnt ?? 0; + $safety_and_privacy['supervise_cnt'] = $supervise->cnt ?? 0; return $safety_and_privacy; } diff --git a/app/Models/SafetyAndPrivacy.php b/app/Models/SafetyAndPrivacy.php index 55e0a239..5fbc1126 100644 --- a/app/Models/SafetyAndPrivacy.php +++ b/app/Models/SafetyAndPrivacy.php @@ -42,7 +42,8 @@ class SafetyAndPrivacy extends Model 'is_finished', 'supervisor_description', 'status_fa', - 'need_judiciary' + 'need_judiciary', + 'operator_description' ]; public $table = "safety_and_privacy"; diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index 89e0ee0f..a9ec577e 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -49,12 +49,12 @@ class SafetyAndPrivacyTableService $user = auth()->user(); $fields = [ - 'id','lat','lon', 'recognize_picture','action_picture','created_at','step', 'final_description', - 'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', + 'id','lat','lon', 'recognize_picture','action_picture','created_at','step', 'final_description', 'province_fa', + 'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', 'edare_shahri_name', 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description', 'operator_description' ]; - $query = SafetyAndPrivacy::query()->where('is_finished', '=', 1); + $query = SafetyAndPrivacy::query(); if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) { From 933a5165e70af8d9da15f34c1447a23eaff10ccd Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Apr 2025 14:24:37 +0330 Subject: [PATCH 5/5] add new column to safety --- .../SafetyAndPrivacy/SupervisorController.php | 9 ++++- .../Controllers/V3/NotificationController.php | 39 +++++++------------ app/Models/SafetyAndPrivacy.php | 4 +- .../SafetyAndPrivacyTableService.php | 2 +- ...add_column_to_safety_and_privacy_table.php | 8 +++- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php index f6ddb692..fc026166 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php @@ -37,13 +37,16 @@ class SupervisorController extends Controller return Excel::download(new SupervisorCartableReport($data['data']), $name); } - public function confirm(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + public function confirm(SafetyAndPrivacy $safetyAndPrivacy, Request $request): JsonResponse { $status_id = SafetyAndPrivacyStatus::CONFIRM->value; $safetyAndPrivacy->update([ 'status' => $status_id, 'status_fa' => SafetyAndPrivacyStatus::name($status_id), + 'supervisor_description' => $request->supervisor_description, + 'supervisor_id' => auth()->user()->id, + 'supervisor_name' => auth()->user()->name, ]); return $this->successResponse(); @@ -56,7 +59,9 @@ class SupervisorController extends Controller $safetyAndPrivacy->update([ 'status' => $status_id, 'status_fa' => SafetyAndPrivacyStatus::name($status_id), - 'supervisor_description' => $request->supervisor_description + 'supervisor_description' => $request->supervisor_description, + 'supervisor_id' => auth()->user()->id, + 'supervisor_name' => auth()->user()->name, ]); return $this->successResponse(); diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index b48536c5..f5d3bb82 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -91,33 +91,22 @@ class NotificationController extends Controller private function safetyAndPrivacyNotifications(): JsonResponse|array { $user = auth()->user(); - $safety_and_privacy = [ - 'supervise_cnt' => 0, - 'step_one' => 0, - 'step_two' => 0, - ]; - if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) { - $supervise = SafetyAndPrivacy::query() - ->selectRaw('count(*) as cnt') - ->where([ - ['is_finished', '=', 1], - ['status', '=', 0], - ]) - ->get(); + $safety_and_privacy = array(); + if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) { + $safety_and_privacy['supervise_cnt'] = SafetyAndPrivacy::query() + ->where('is_finished', '=', 1) + ->where('status', '=', 0) + ->count(); } elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) { throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); - $supervise = SafetyAndPrivacy::query() + $safety_and_privacy['supervise_cnt'] = SafetyAndPrivacy::query() ->where('province_id', '=', $user->province_id) - ->selectRaw('count(*) as cnt') - ->where([ - ['is_finished', '=', 1], - ['status', '=', 0], - ]) - ->get(); - + ->where('is_finished', '=', 1) + ->where('status', '=', 0) + ->count(); } elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) { throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); @@ -125,17 +114,17 @@ class NotificationController extends Controller $activity = SafetyAndPrivacy::query() ->where('edare_shahri_id', '=', $user->edarate_shahri_id) ->selectRaw('count(*) as cnt, step') + ->where('is_finished', '=', 0) ->groupby('step') ->orderBy('step') ->get(); $step_one = $activity->where('step', '=', 1)->first(); $step_two = $activity->where('step', '=', 2)->first(); - } - $safety_and_privacy['step_one'] = $step_one->cnt ?? 0; - $safety_and_privacy['step_two'] = $step_two->cnt ?? 0; - $safety_and_privacy['supervise_cnt'] = $supervise->cnt ?? 0; + $safety_and_privacy['step_one'] = $step_one->cnt ?? 0; + $safety_and_privacy['step_two'] = $step_two->cnt ?? 0; + } return $safety_and_privacy; } diff --git a/app/Models/SafetyAndPrivacy.php b/app/Models/SafetyAndPrivacy.php index 5fbc1126..0ae5ac91 100644 --- a/app/Models/SafetyAndPrivacy.php +++ b/app/Models/SafetyAndPrivacy.php @@ -43,7 +43,9 @@ class SafetyAndPrivacy extends Model 'supervisor_description', 'status_fa', 'need_judiciary', - 'operator_description' + 'operator_description', + 'supervisor_name', + 'supervisor_id' ]; public $table = "safety_and_privacy"; diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index a9ec577e..b6331901 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -49,7 +49,7 @@ class SafetyAndPrivacyTableService $user = auth()->user(); $fields = [ - 'id','lat','lon', 'recognize_picture','action_picture','created_at','step', 'final_description', 'province_fa', + 'id','lat','lon', 'recognize_picture','action_picture','created_at','status', 'final_description', 'province_fa', 'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', 'edare_shahri_name', 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa', 'supervisor_description', 'operator_description' ]; diff --git a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php index 63711b72..ac7409c5 100644 --- a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php +++ b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php @@ -19,6 +19,8 @@ return new class extends Migration $table->string('supervisor_description')->nullable(); $table->string('final_description')->nullable(); $table->boolean('need_judiciary')->nullable(); + $table->integer('supervisor_id')->nullable(); + $table->string('supervisor_name')->nullable(); $table->text('judiciary_document')->nullable()->change(); $table->dateTime('judiciary_document_upload_date')->nullable()->change(); }); @@ -30,7 +32,11 @@ return new class extends Migration public function down(): void { Schema::table('safety_and_privacy', function (Blueprint $table) { - $table->dropColumn(['status', 'final_description', 'is_finished', 'supervisor_description', 'status_fa', 'need_judiciary', 'operator_description']); + $table->dropColumn([ + 'status', 'final_description', 'is_finished', + 'supervisor_description', 'status_fa', 'need_judiciary', + 'operator_description', 'supervisor_name', 'supervisor_id', + ]); $table->text('judiciary_document')->change(); $table->dateTime('judiciary_document_upload_date')->change(); });