diff --git a/app/Console/Commands/RoadObservationProblems.php b/app/Console/Commands/RoadObservationProblems.php index d56da6bb..3706103e 100755 --- a/app/Console/Commands/RoadObservationProblems.php +++ b/app/Console/Commands/RoadObservationProblems.php @@ -24,7 +24,7 @@ class RoadObservationProblems extends Command * * @var string */ - protected $signature = 'webservice:roadobserved'; + protected $signature = 'webservice:roadobserved {--daily-mode}'; /** * The console command description. @@ -63,7 +63,9 @@ class RoadObservationProblems extends Command // return 0; // } - $result = $nikarayanService->getRoadObservedProblemsByDate(); + $time = $this->option('daily-mode') ? verta()->subDay() : verta(); + + $result = $nikarayanService->getRoadObservedProblemsByDate($time); $result = serialize($result); $x = strpos($result, 'fk_FeatureType >= 1 && $value->fk_FeatureType <= 18) { + if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 24) { $mobile = null; if ($value->MobileForSendEventSms && (strlen($value->MobileForSendEventSms) == 11)) { @@ -89,7 +91,7 @@ class RoadObservationProblems extends Command } $city = findCityFromGeoJson($value->YGeo, $value->XGeo); - $cityModel = $city ? City::find($city['city_id']) : null; + $cityModel = $city ? City::query()->find($city['city_id']) : City::query()->find(NikarayanComplaints::mapCities((int) $value->fk_Town)); $rop = RoadObserved::query()->updateOrCreate( ['fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage], [ @@ -99,7 +101,7 @@ class RoadObservationProblems extends Command 'EndTime' => $value->EndTime ?? null, 'StartDate' => $value->StartDate ?? null, 'EndDate' => $value->EndDate ?? null, - 'StartTime_DateTime' => $value->StartTime_DateTime ?? null, + 'StartTime_DateTime' => $value->StartTime_DateTime ? Carbon::createFromFormat('m/d/Y h:i:s A', $value->StartTime_DateTime)->format('Y-m-d H:i:s') : null, 'StartTime_DateTime_fa' => Verta::instance($value->StartTime_DateTime) ?? null, 'EndTime_DateTime' => $value->EndTime_DateTime ?? null, 'AutoID' => $value->AutoID ?? null, @@ -130,7 +132,7 @@ class RoadObservationProblems extends Command 'province_id' => $city ? $city['province_id'] : null, 'city_id' => $city ? $city['city_id'] : null, // 'handler_type' => EdarateShahri::class, - 'edarate_shahri_id' => $cityModel ? ($cityModel->edarateShahri()->where('is_primary', 1)->exists() ? $cityModel->edarateShahri()->where('is_primary', 1)->first()->id : null) : null, + 'edarate_shahri_id' => $cityModel->edarateShahri()->first()->id, 'province_fa' => (isset($city['province_id']) ? Province::find($city['province_id'])->name_fa : null), 'city_fa' => $cityModel ? $cityModel->name_fa : null, ] diff --git a/app/Console/Commands/SendRoadObservationToNikarayanCommand.php b/app/Console/Commands/SendRoadObservationToNikarayanCommand.php index e04568bd..5202e148 100644 --- a/app/Console/Commands/SendRoadObservationToNikarayanCommand.php +++ b/app/Console/Commands/SendRoadObservationToNikarayanCommand.php @@ -33,16 +33,14 @@ class SendRoadObservationToNikarayanCommand extends Command $this->info("Dispatching jobs with a delay between each..."); DB::transaction(function () use (&$count) { - $delay = 0; RoadObserved::query() ->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-13 23:59:59']) - ->chunkById(50, function ($roads) use (&$delay, &$count) { + ->chunkById(50, function ($roads) use (&$count) { foreach ($roads as $road) { $road->update(['status' => 1]); - SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addSeconds($delay)); - Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with a {$delay} seconds delay."); - $this->info("Scheduled job for Road ID: {$road->id} {$delay}s"); - $delay += 3; + SendRoadObservationToNikarayan::dispatch($road); + Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled."); + $this->info("Scheduled job for Road ID: {$road->id}"); $count +=1; } }); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7a38c610..6a2033c1 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -26,7 +26,7 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $schedule->command('webservice:roadobserved') - ->everyFiveMinutes()->appendOutputTo(storage_path('logs/roadobser.log')); + ->everyFiveMinutes()->appendOutputTo(storage_path('logs/nikarayan.log')); $schedule->command('command:sendcontractsmsnotification') // ->everyMinute()->appendOutputTo(storage_path('logs/contractSms.log')); @@ -35,7 +35,8 @@ class Kernel extends ConsoleKernel $schedule->command('reports:rms-summary') ->dailyAt('00:00')->appendOutputTo(storage_path('logs/report_summary.log')); - + $schedule->command("webservice:roadobserved --daily-mode") + ->dailyAt('00:15')->appendOutputTo(storage_path('logs/nikarayan.log')); } /** diff --git a/app/Enums/NikarayanComplaints.php b/app/Enums/NikarayanComplaints.php index 9d2d5feb..d8bfecd5 100644 --- a/app/Enums/NikarayanComplaints.php +++ b/app/Enums/NikarayanComplaints.php @@ -2636,7 +2636,37 @@ enum NikarayanComplaints: int "CityName" => "خرمدره", "ProvinceID" => "67", "InvarID" => 150 - ] + ], + 432 => [ + "OnvarID" => 432, + "CityName" => "جرقویه علیا", + "ProvinceID" => "21", + "InvarID" => 497 + ], + 433 => [ + "OnvarID" => 433, + "CityName" => "كوهپایه", + "ProvinceID" => "21", + "InvarID" => 793 + ], + 434 => [ + "OnvarID" => 434, + "CityName" => "ورزنه", + "ProvinceID" => "21", + "InvarID" => 805 + ], + 435 => [ + "OnvarID" => 435, + "CityName" => "هرند", + "ProvinceID" => "21", + "InvarID" => 794 + ], + 436 => [ + "OnvarID" => 436, + "CityName" => "جرقویه سفلی", + "ProvinceID" => "21", + "InvarID" => 497 + ], ]; return $nikarayanToRmsCityId[$city_id]["InvarID"]; } diff --git a/app/Enums/RoadMaintenanceStationTypes.php b/app/Enums/RoadMaintenanceStationTypes.php new file mode 100644 index 00000000..4d557675 --- /dev/null +++ b/app/Enums/RoadMaintenanceStationTypes.php @@ -0,0 +1,21 @@ + "دائمی", + 2 => "موقت", + 3 => "فصلی", + ]; + + return $mapArray[$state]; + } +} \ No newline at end of file diff --git a/app/Enums/SafetyAndPrivacyStatus.php b/app/Enums/SafetyAndPrivacyStatus.php new file mode 100644 index 00000000..78168c2a --- /dev/null +++ b/app/Enums/SafetyAndPrivacyStatus.php @@ -0,0 +1,21 @@ + 'در حال بررسی', + 1 => 'تایید', + 2 => 'عدم تایید', + ]; + + return $mapArray[$state]; + } +} \ No newline at end of file diff --git a/app/Enums/SafetyAndPrivacySteps.php b/app/Enums/SafetyAndPrivacySteps.php new file mode 100644 index 00000000..b0e30776 --- /dev/null +++ b/app/Enums/SafetyAndPrivacySteps.php @@ -0,0 +1,21 @@ + 'گام اول (شناسایی)', + 2 => 'گام دوم (مستندات قضایی)', + 3 => 'گام سوم (برخورد)', + ]; + + return $mapArray[$step]; + } +} \ No newline at end of file diff --git a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php index b6e6ccb2..68e1b99a 100644 --- a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php @@ -19,13 +19,13 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit public function view(): View { $data = $this->data; - $existedProvinces = array_keys($data['activities']); + $existedProvinces = array_keys($data); foreach (\App\Models\Province::all() as $value) { $provinceId = $value->id; if (!array_key_exists($provinceId, $existedProvinces)) { - $data['activities'][] = (object) [ + $data[] = (object) [ 'province_id' => $provinceId, 'name_fa' => $value->name_fa, 'sum' => 0, @@ -37,9 +37,7 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit } return view('v3.Reports.SafetyAndPrivacy.CountryActivityReport', [ - 'data' => $data['activities'], - 'fromDate' => $data['fromDate'], - 'toDate' => $data['toDate'], + 'data' => $data, ]); } diff --git a/app/Exports/V3/SafetyAndPrivacy/CartableReport.php b/app/Exports/V3/SafetyAndPrivacy/OperatorCartableReport.php similarity index 91% rename from app/Exports/V3/SafetyAndPrivacy/CartableReport.php rename to app/Exports/V3/SafetyAndPrivacy/OperatorCartableReport.php index 6c066aa1..81137eea 100644 --- a/app/Exports/V3/SafetyAndPrivacy/CartableReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/OperatorCartableReport.php @@ -12,13 +12,13 @@ use Maatwebsite\Excel\Events\AfterSheet; use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -class CartableReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings +class OperatorCartableReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings { public function __construct(private ?Collection $data){} public function view(): View { - return view('v3.Reports.SafetyAndPrivacy.CartableReport', [ + return view('v3.Reports.SafetyAndPrivacy.OperatorCartableReport', [ 'data' => $this->data, ]); } diff --git a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php index 399b5bca..17b1e853 100644 --- a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php @@ -21,14 +21,14 @@ class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, Wi public function view(): View { $data = $this->data; - $existedCities = array_keys($data['activities']); + $existedCities = array_keys($data); $edarat = EdarateShahri::query()->where('province_id', '=', $this->request->province_id)->get(['id', 'name_fa']); foreach ($edarat as $value) { $edareId = $value->id; if (!array_key_exists($edareId, $existedCities)) { - $data['activities'][] = (object) [ + $data[] = (object) [ 'edare_shahri_id' => $edareId, 'name_fa' => $value->name_fa, 'sum' => 0, @@ -40,9 +40,7 @@ class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, Wi } return view('v3.Reports.SafetyAndPrivacy.ProvinceActivityReport', [ - 'data' => $data['activities'], - 'fromDate' => $data['fromDate'], - 'toDate' => $data['toDate'], + 'data' => $data, ]); } diff --git a/app/Exports/V3/SafetyAndPrivacy/SupervisorCartableReport.php b/app/Exports/V3/SafetyAndPrivacy/SupervisorCartableReport.php new file mode 100644 index 00000000..cf712aaf --- /dev/null +++ b/app/Exports/V3/SafetyAndPrivacy/SupervisorCartableReport.php @@ -0,0 +1,69 @@ + $this->data, + ]); + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + public function drawings(): array + { + $drawing = new Drawing(); + $drawing->setName('Logo'); + $drawing->setDescription('This is my logo'); + $drawing->setPath(public_path('/dist/logo.png')); + $drawing->setWidth(50); + $drawing->setHeight(50); + $drawing->setOffsetX(5); + $drawing->setOffsetY(5); + $drawing->setCoordinates('A1'); + + $drawing2 = new Drawing(); + $drawing2->setName('Logo'); + $drawing2->setDescription('This is my logo'); + $drawing2->setPath(public_path('/dist/141icon.png')); + $drawing2->setWidth(50); + $drawing2->setHeight(50); + $drawing2->setOffsetX(5); + $drawing2->setOffsetY(5); + $drawing2->setCoordinates('B1'); + return [$drawing, $drawing2]; + } + + public function styles(Worksheet $sheet): array + { + return [ + 'A:BA' => [ + 'font' => [ + 'name' => 'B Nazanin' + ] + ], + ]; + } +} \ No newline at end of file diff --git a/app/Facades/DataTable/DataTable.php b/app/Facades/DataTable/DataTable.php index ae637a86..63699505 100644 --- a/app/Facades/DataTable/DataTable.php +++ b/app/Facades/DataTable/DataTable.php @@ -28,7 +28,8 @@ class DataTable array $allowedFilters = [], array $allowedRelations = [], array $allowedSortings = [], - array $allowedSelects = [] + array $allowedSelects = [], + array $allowedGroupBy = [] ): array { @@ -43,7 +44,8 @@ class DataTable $sorting, $rels, $allowedFilters, - $allowedSortings + $allowedSortings, + $allowedGroupBy ); $query = $this->makeQueryFromModel($mixed); @@ -52,7 +54,8 @@ class DataTable ->setAllowedFilters($allowedFilters) ->setAllowedRelations($allowedRelations) ->setAllowedSortings($allowedSortings) - ->setAllowedSelects($allowedSelects); + ->setAllowedSelects($allowedSelects) + ->setAllowedGroupBy($allowedGroupBy); return $dataTableService->getData(); } diff --git a/app/Facades/File/File.php b/app/Facades/File/File.php index 79155a8e..418f7664 100644 --- a/app/Facades/File/File.php +++ b/app/Facades/File/File.php @@ -104,4 +104,9 @@ class File fclose($file); return trim($output); } + + public function deleteDirectory(string $path, string $disk = 'public'): void + { + Storage::disk($disk)->deleteDirectory($path); + } } diff --git a/app/Http/Controllers/Api/BiController.php b/app/Http/Controllers/Api/BiController.php index 91272974..ecb4de03 100644 --- a/app/Http/Controllers/Api/BiController.php +++ b/app/Http/Controllers/Api/BiController.php @@ -150,6 +150,7 @@ class BiController extends Controller public function getDiagram(Request $request) { + ini_set('memory_limit', '-1'); $subjectID = $request->subject_id; $provinceID = $request->province_id; $dateFrom = $request->from_date; @@ -1021,6 +1022,7 @@ class BiController extends Controller public function separationActivityTypeRahdariActivities(Request $request) { + ini_set('memory_limit', '-1'); $dateFrom = $request->from_date; $dateTo = $request->to_date; $provinceID = $request->province_id ?? null; @@ -1198,4 +1200,4 @@ class BiController extends Controller 'data' => round($camps, 2) ]); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 5368e931..3b314a2d 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -202,7 +202,7 @@ class AccidentReceiptController extends Controller public function destroy(Accident $accident): JsonResponse { - FileFacade::delete('storage/receipts_files/'.$accident->id); + FileFacade::deleteDirectory('receipts_files/'.$accident->id); DB::transaction(function () use ($accident) { @@ -240,9 +240,9 @@ class AccidentReceiptController extends Controller DB::transaction(function () use ($request, $accident) { $accident->update([ - 'deposit_insurance_image' => $request->deposit_insurance_image != null ? FileFacade::save($request->deposit_insurance_image, "receipts_files/{$accident->id}/deposit_insurance/") : null, + 'deposit_insurance_image' => $request->has('deposit_insurance_image') ? FileFacade::save($request->deposit_insurance_image, "receipts_files/{$accident->id}/deposit_insurance") : null, 'deposit_insurance_amount' => $request->deposit_insurance_amount ?? 0, - 'deposit_daghi_image' => $request->deposit_insurance_image != null ? FileFacade::save($request->deposit_daghi_image, "receipts_files/{$accident->id}/deposit_daghi/") : null, + 'deposit_daghi_image' => $request->has('deposit_daghi_image') ? FileFacade::save($request->deposit_daghi_image, "receipts_files/{$accident->id}/deposit_daghi") : null, 'deposit_daghi_amount' => $request->deposit_daghi_amount ?? 0, 'status' => AccidentStates::SABT_FISH->value, 'status_fa' => AccidentStates::name(AccidentStates::SABT_FISH->value), diff --git a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php index cc3d5673..3346cdb7 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php @@ -22,7 +22,7 @@ class SafetyAndPrivacyReportController extends Controller { $data = $safetyAndPrivacyTableService->countryActivity($request); return $this->successResponse([ - 'activities' => $data['activities'], + 'activities' => $data, 'provinces' => Province::all(['id', 'name_fa']) ]); } @@ -31,7 +31,7 @@ class SafetyAndPrivacyReportController extends Controller { $data = $safetyAndPrivacyTableService->provinceActivity($request); return $this->successResponse([ - 'activities' => $data['activities'], + 'activities' => $data, 'edarateShahri' => EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']), ]); } diff --git a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php new file mode 100644 index 00000000..dc14f995 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php @@ -0,0 +1,260 @@ +user(); + auth()->user()->addActivityComplete(1019); + + $allowedFilters = ['*']; + $allowedSortings = ['*']; + + $province = $request->province; + $status = $request->status; + $type = $request->type; + + $query = RahdariPoint::query() + ->when($status, fn ($query, $status) => $query->where('status', $status)) + ->when($type, fn ($query, $type) => $query->where('type', $type)) + ->when($province, fn($query, $province) => $query->where('province_id', $province)); + + if ($user->hasPermissionTo('show-tollhouse-province')) { + $query->where('province_id', $user->province_id); + } + + $data = DataTableFacade::run( + $query, + $request, + allowedFilters: $allowedFilters, + allowedSortings: $allowedSortings + ); + + + foreach ($data['data'] as &$stations) { + if ($user->hasPermissionTo('edit-tollhouse')) { + $stations['canEdit'] = 1; + } + elseif ($user->hasPermissionTo('edit-tollhouse-province') && $stations->province_id == $user->province_id) { + $stations['canEdit'] = 1; + } + else { + $stations['canEdit'] = 0; + } + + if ($user->hasPermissionTo('delete-tollhouse')) { + $stations['canDelete'] = 1; + } + elseif ($user->hasPermissionTo('delete-tollhouse-province') && $stations->province_id == $user->province_id) { + $stations['canDelete'] = 1; + } + else { + $stations['canDelete'] = 0; + } + } + + return response()->json($data); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + $province = Province::query()->find($request->province_id); + + $city = City::query()->find($request->city_id); + + $station = RahdariPoint::query()->create([ + 'province_id' => $province->id, + 'province_name' => $province->name_fa, + 'city_id' => $city->id, + 'city_name' => $city->name_fa, + 'name' => $request->name, + 'status' => $request->status, + 'type' => $request->type, + 'type_fa' =>RoadMaintenanceStationTypes::name($request->type), + 'team_num' => $request->team_num, + 'staff_num' => $request->staff_num, + 'phone' => $request->phone, + 'responsible_name' => $request->responsible_name, + 'responsible_mobile' => $request->responsible_mobile, + 'successor_name' => $request->successor_name, + 'successor_mobile' => $request->successor_mobile, + 'machines_light' => $request->machines_light, + 'machines_sheavy' => $request->machines_sheavy, + 'machines_heavy' => $request->machines_heavy, + 'code' => $request->code, + 'lat' => $request->lat, + 'lng' => $request->lng, + 'updated_at_fa' => verta()->now()->format('Y/m/d H:i:s'), + ]); + + $uploadPaths = [ + 'overview_files_1' => "road_stations/{$station->id}", + 'overview_files_2' => "road_stations/{$station->id}", + 'overview_files_3' => "road_stations/{$station->id}", + 'overview_files_4' => "road_stations/{$station->id}", + 'overview_files_5' => "road_stations/{$station->id}", + ]; + + foreach ($uploadPaths as $field => $path) { + if ($request->hasFile($field)) { + $station->files()->create([ + 'path' => FileFacade::save($request->$field, $path) + ]); + } + } + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(RahdariPoint $rahdariPoint): JsonResponse + { + return $this->successResponse($rahdariPoint->load('files')); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, RahdariPoint $rahdariPoint): JsonResponse + { + $province = Province::query()->find($request->province_id); + + $city = City::query()->find($request->city_id); + + RahdariPointHistory::query()->create([ + 'user_id' => $request->user()->id, + 'point_id' => $rahdariPoint->id, + 'previous_province_id' => $province->id, + 'previous_province_name' => $province->name_fa, + 'previous_city_id' => $city->id, + 'previous_city_name' => $city->name_fa, + 'previous_name' => $rahdariPoint->name, + 'previous_status' => $rahdariPoint->status, + 'previous_type' => $rahdariPoint->type, + 'previous_team_num' => $rahdariPoint->team_num, + 'previous_staff_num' => $rahdariPoint->staff_num, + 'previous_phone' => $rahdariPoint->phone, + 'previous_responsible_name' => $rahdariPoint->responsible_name, + 'previous_responsible_mobile' => $rahdariPoint->responsible_mobile, + 'previous_successor_name' => $rahdariPoint->successor_name, + 'previous_successor_mobile' => $rahdariPoint->successor_mobile, + 'previous_machines_light' => $rahdariPoint->machines_light, + 'previous_machines_sheavy' => $rahdariPoint->machines_sheavy, + 'previous_machines_heavy' => $rahdariPoint->machines_heavy, + 'previous_lat' => $rahdariPoint->lat, + 'previous_lng' => $rahdariPoint->lng, + 'new_files' => json_encode($rahdariPoint->files), + ]); + + $rahdariPoint->update([ + 'province_id' => $province->id, + 'province_name' => $province->name_fa, + 'city_id' => $city->id, + 'city_name' => $city->name_fa, + 'name' => $request->input('name'), + 'status' => $request->input('status'), + 'type' => $request->input('type',), + 'type_fa' => RoadMaintenanceStationTypes::name($request->type) ?? $rahdariPoint->type_fa, + 'team_num' => $request->input('team_num'), + 'staff_num' => $request->input('staff_num'), + 'phone' => $request->input('phone'), + 'responsible_name' => $request->input('responsible_name'), + 'responsible_mobile' => $request->input('responsible_mobile'), + 'successor_name' => $request->input('successor_name'), + 'successor_mobile' => $request->input('successor_mobile'), + 'machines_light' => $request->input('machines_light'), + 'machines_sheavy' => $request->input('machines_sheavy'), + 'machines_heavy' => $request->input('machines_heavy'), + 'lat' => $request->input('lat'), + 'lng' => $request->input('lng'), + 'lat_from' => $request->lat_from, + 'lng_from' => $request->lng_from, + 'geometry' => $request->geometry, + 'lat_to' => $request->lat_to, + 'lng_to' => $request->lng_to, + 'color' => $request->color, + 'updated_at_fa' => verta()->now()->format('Y/m/d H:i:s'), + ]); + + $uploadFields = [ + 'overview_files_1', + 'overview_files_2', + 'overview_files_3', + 'overview_files_4', + 'overview_files_5', + ]; + + foreach ($uploadFields as $index => $field) { + if ($request->hasFile($field)) { + $existingFile = $rahdariPoint->files->get($index); + $path = FileFacade::save($request->$field, "road_stations/{$rahdariPoint->id}"); + + if ($existingFile) { + FileFacade::delete($existingFile->path); + $existingFile->update(['path' => $path]); + } else { + $rahdariPoint->files()->create(['path' => $path]); + } + } + } + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(RahdariPoint $rahdariPoint): JsonResponse + { + foreach ($rahdariPoint->files as $file) { + FileFacade::delete($file->path); + } + $rahdariPoint->rahdariPointHistories()->delete(); + $rahdariPoint->files()->delete(); + $rahdariPoint->delete(); + + return $this->successResponse(); + } + + public function images(RahdariPoint $rahdariPoint): JsonResponse + { + return $this->successResponse($rahdariPoint->files()->orderBy('id')->get(['path'])); + } + + public function map(Request $request): JsonResponse + { + auth()->user()->addActivityComplete(1023); + + return response()->json(DataTableFacade::run( + RahdariPoint::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: ['id', 'lat', 'lng', 'status', 'type'], + )); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index a3b97c4c..8cdd32c7 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\V3\Dashboard; use App\Exports\V3\RoadObservation\ComplaintsReport; use App\Exports\V3\RoadObservation\OperatorCartableReport; use App\Exports\V3\RoadObservation\SupervisorCartableReport; +use App\Facades\DataTable\DataTableFacade; use App\Facades\File\FileFacade; use App\Facades\Sms\Sms; use App\Http\Controllers\Controller; @@ -24,6 +25,7 @@ use Hekmatinasser\Verta\Verta; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Services\Cartables\RoadObservationTableService; +use Illuminate\Support\Facades\DB; use Maatwebsite\Excel\Facades\Excel; use SoapFault; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -117,8 +119,8 @@ class RoadObservationController extends Controller $roadObserved->files()->where('path', 'like', '%_image_before%')->delete(); $roadObserved->files()->where('path', 'like', '%_image_after%')->delete(); - $image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}/"); - $image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}/"); + $image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}"); + $image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}"); $files_path[0]['path'] = $image_before; $files_path[1]['path'] = $image_after; @@ -135,20 +137,15 @@ class RoadObservationController extends Controller $roadObservedHistoryData['new_files'] = $files; } - $roadObserved->problemHistories()->create($roadObservedHistoryData); - $roadObserved->update($roadObservedData); + DB::transaction(function () use ($roadObserved, $roadObservedHistoryData, $roadObservedData, $request, $nikarayanService) { + $roadObserved->problemHistories()->create($roadObservedHistoryData); + $roadObserved->update($roadObservedData); - auth()->user()->addActivityComplete(1142); + auth()->user()->addActivityComplete(1142); - try { $nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, json_encode($roadObservedHistoryData['new_files'])); - } - catch (SoapFault $e) { - $msg = "error in send to nikarayan at" . date("Y-m-d H:i:s") . "\n"; - $msg .= $e->getMessage(); - Sms::sendSms(env('RMS_CTO_PHONE_NUMBER'), $msg); - } + }); return $this->successResponse(); } @@ -182,7 +179,7 @@ class RoadObservationController extends Controller if ($roadObserved->image_before) { FileFacade::delete($roadObserved->image_before, true); } - $image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}/"); + $image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}"); $roadObservedData['image_before'] = $image_before; $files_path[0]['path'] = $image_before; } @@ -191,7 +188,7 @@ class RoadObservationController extends Controller if ($roadObserved->image_after) { FileFacade::delete($roadObserved->image_after, true); } - $image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}/"); + $image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}"); $roadObservedData['image_after'] = $image_after; $files_path[1]['path'] = $image_after; } @@ -206,20 +203,14 @@ class RoadObservationController extends Controller $roadObservedHistoryData['new_files'] = $files; } - $roadObserved->problemHistories()->create($roadObservedHistoryData); - $roadObserved->update($roadObservedData); + DB::transaction(function () use ($roadObserved, $roadObservedHistoryData, $roadObservedData, $request, $nikarayanService) { + $roadObserved->problemHistories()->create($roadObservedHistoryData); + $roadObserved->update($roadObservedData); - auth()->user()->addActivityComplete(1142); + auth()->user()->addActivityComplete(1142); - try { $nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, json_encode($roadObservedHistoryData['new_files'])); - } - catch (SoapFault $e) { - - $msg = "error in send to nikarayan at" . date("Y-m-d H:i:s") . "\n"; - $msg .= $e->getMessage(); - Sms::sendSms(env('RMS_CTO_PHONE_NUMBER'), $msg); - } + }); return $this->successResponse(); } @@ -305,4 +296,15 @@ class RoadObservationController extends Controller return $this->successResponse(); } + + public function map(Request $request): JsonResponse + { + return response()->json(DataTableFacade::run( + RoadObserved::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: ['id', 'lat', 'lng', 'status'] + )); + } } 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..650a6a93 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorController.php @@ -0,0 +1,231 @@ +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, + 'operator_description' => $request->operator_description, + ]); + + $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..fc026166 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/SupervisorController.php @@ -0,0 +1,69 @@ +json($safetyAndPrivacyTableService->supervisorDataTable($request)); + } + + /** + * @throws Throwable + */ + 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, 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(); + } + + 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, + 'supervisor_id' => auth()->user()->id, + 'supervisor_name' => auth()->user()->name, + ]); + + 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/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index a36842d3..06b03021 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -3,12 +3,19 @@ namespace App\Http\Controllers\V3\Dashboard; use App\Enums\AxisTypes; -use App\Exports\V3\SafetyAndPrivacy\CartableReport; +use App\Enums\SafetyAndPrivacyStatus; +use App\Enums\SafetyAndPrivacySteps; +use App\Exports\V3\SafetyAndPrivacy\OperatorCartableReport; +use App\Exports\V3\SafetyAndPrivacy\SupervisorCartableReport; +use App\Facades\DataTable\DataTableFacade; use App\Facades\File\FileFacade; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\SafetyAndPrivacy\FinishRequest; +use App\Http\Requests\V3\SafetyAndPrivacy\RejectRequest; use App\Http\Requests\V3\SafetyAndPrivacy\FirstStepStoreRequest; use App\Http\Requests\V3\SafetyAndPrivacy\SecondStepStoreRequest; use App\Http\Requests\V3\SafetyAndPrivacy\ThirdStepStoreRequest; +use App\Http\Requests\V3\SafetyAndPrivacy\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\InfoItem; use App\Models\SafetyAndPrivacy; @@ -16,41 +23,38 @@ use App\Services\Cartables\SafetyAndPrivacyTableService; use App\Services\NominatimService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\Validator; use Maatwebsite\Excel\Facades\Excel; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Throwable; class SafetyAndPrivacyController extends Controller { use ApiResponse; - public function index(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + /** + * @throws Throwable + */ + public function operatorIndex(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse { - return response()->json($safetyAndPrivacyTableService->datatable($request)); + return response()->json($safetyAndPrivacyTableService->operatorDatatable($request)); } - public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse + /** + * @throws Throwable + */ + public function operatorExcelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse { $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - $data = $safetyAndPrivacyTableService->datatable($request); - return Excel::download(new CartableReport($data['data']), $name); + $data = $safetyAndPrivacyTableService->operatorDatatable($request); + return Excel::download(new OperatorCartableReport($data['data']), $name); } public function firstStepStore(FirstStepStoreRequest $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('اداره شهری برای شما در سامانه ثبت نشده است!'); - } - $coordinates = explode(',', $request->point); $item = InfoItem::query() ->where('id', $request->info_id) @@ -59,6 +63,7 @@ class SafetyAndPrivacyController extends Controller 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], @@ -76,8 +81,9 @@ class SafetyAndPrivacyController extends Controller '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' => 1, - 'step_fa' => 'گام اول (شناسایی)' + 'step' => $step, + 'step_fa' => SafetyAndPrivacySteps::name($step), + 'is_finished' => false, ]); $safety_and_privacy->recognize_picture = $request->has('recognize_picture') ? @@ -95,25 +101,27 @@ class SafetyAndPrivacyController extends Controller { $user = auth()->user(); - if ($user->edarate_ostani_id || is_null($user->city_id)) { - return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); - } + DB::transaction(function () use ($request, $safetyAndPrivacy, $user) { - if (is_null($user->edarate_shahri_id)) { - return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); - } + $need_judiciary = $request->need_judiciary; - DB::transaction(function () use ($request, $safetyAndPrivacy, $user) - { $judiciary_document = []; - foreach ($request->judiciary_document as $index => $file) { - $judiciary_document[] = FileFacade::save($file, "safety_and_privacy/{$safetyAndPrivacy->id}/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([ - 'judiciary_document' => serialize($judiciary_document), - 'judiciary_document_upload_date' => now(), - 'step' => 2, - 'step_fa' => 'گام دوم (مستندات قضایی)' + '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); @@ -126,20 +134,16 @@ class SafetyAndPrivacyController extends Controller { $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('اداره شهری برای شما در سامانه ثبت نشده است!'); - } - DB::transaction(function () use ($request, $safetyAndPrivacy, $user) { + $step = SafetyAndPrivacySteps::BARKHORD->value; $safetyAndPrivacy->update([ - 'step' => 3, - 'step_fa' => 'گام سوم (برخورد)', + '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); @@ -148,6 +152,20 @@ class SafetyAndPrivacyController extends Controller 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); @@ -155,7 +173,7 @@ class SafetyAndPrivacyController extends Controller public function destroy(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse { - Storage::deleteDirectory("public/safety_and_privacy/{$safetyAndPrivacy->id}"); + FileFacade::deleteDirectory("safety_and_privacy/{$safetyAndPrivacy->id}"); DB::transaction(function () use ($safetyAndPrivacy) { @@ -186,4 +204,66 @@ class SafetyAndPrivacyController extends Controller ->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 map(Request $request): JsonResponse + { + return response()->json(DataTableFacade::run( + SafetyAndPrivacy::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: ['id', 'lat', 'lon', 'step'] + )); + } + + 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(); + } + + 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 supervisorIndex(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + { + return response()->json($safetyAndPrivacyTableService->supervisorDataTable($request)); + } + + public function supervisorExcelReport(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); + } } diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index d322a95a..f5d3bb82 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -92,24 +92,21 @@ class NotificationController extends Controller { $user = auth()->user(); $safety_and_privacy = array(); - if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) { - $activity = SafetyAndPrivacy::query() - ->selectRaw('count(*) as cnt, step') - ->groupby('step') - ->orderBy('step') - ->get(); + 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('استانی برای شما در سامانه ثبت نشده است!')); - $activity = SafetyAndPrivacy::query() + $safety_and_privacy['supervise_cnt'] = SafetyAndPrivacy::query() ->where('province_id', '=', $user->province_id) - ->selectRaw('count(*) as cnt, step') - ->groupby('step') - ->orderBy('step') - ->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('اداره ای برای شما در سامانه ثبت نشده است!')); @@ -117,13 +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(); - } - $safety_and_privacy['step_one'] = isset($activity[0]) ? $activity[0]->cnt : 0; - $safety_and_privacy['step_two'] = isset($activity[1]) ? $activity[1]->cnt : 0; + $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; + } return $safety_and_privacy; } @@ -141,56 +142,44 @@ class NotificationController extends Controller 'supervise_cnt' => 0 ]; - $conditions = []; - $complaintConditions = [ - ['rms_status', '=', 0], - ['edarate_shahri_id', '!=', null] - ]; - if ($user->hasPermissionTo('show-fast-react')) { - $conditions[] = ['status', '=', 2]; + $road_observations['supervise_cnt'] = RoadObserved::query()->where([ + ['rms_status', '<>', 0], + ['status', '=', 0] + ])->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query()->where('rms_status', '=', 0)->count(); } elseif ($user->hasPermissionTo('show-fast-react-province')) { throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); - $conditions = [ - ['status', '=', 2], - ['rms_province_id', '=', $user->province_id] - ]; - $complaintConditions[] = ['province_id', '=', $user->province_id]; + + $road_observations['supervise_cnt'] = RoadObserved::query()->where([ + ['rms_status', '<>', 0], + ['status', '=', 0], + ['province_id', '=', $user->province_id] + ])->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query()->where([ + ['rms_status', '=', 0], + ['province_id', '=', $user->province_id] + ])->count(); } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); - $conditions = [ + + $road_observations['operation_cnt'] = RoadObserved::query()->where([ + ['rms_status', '<>', 0], ['status', '=', 2], ['edarate_shahri_id', '=', $user->edarate_shahri_id] - ]; - $complaintConditions[] = ['edarate_shahri_id', '=', $user->edarate_shahri_id]; + ])->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query()->where([ + ['rms_status', '=', 0], + ['edarate_shahri_id', '=', $user->edarate_shahri_id] + ])->count(); } - if (!empty($conditions)) { - $road_observations['operation_cnt'] = RoadObserved::query()->where($conditions)->count(); - $road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count(); - $road_observations['total'] += $road_observations['operation_cnt'] + $road_observations['complaint_cnt']; - } - - $superviseConditions = [ - ['status', '=', 0] - ]; - - if ($user->hasPermissionTo('supervise-fast-react')) { - $road_observations['supervise_cnt'] = RoadObserved::query()->where($superviseConditions)->count(); - $road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count(); - $road_observations['total'] += $road_observations['supervise_cnt'] + $road_observations['complaint_cnt']; - } - elseif ($user->hasPermissionTo('supervise-fast-react-province')) { - throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); - $superviseConditions[] = ['province_id', '=', $user->province_id]; - $complaintConditions[] = ['province_id', '=', $user->province_id]; - - $road_observations['supervise_cnt'] = RoadObserved::query()->where($superviseConditions)->count(); - $road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count(); - $road_observations['total'] += $road_observations['supervise_cnt'] + $road_observations['complaint_cnt']; - } + $road_observations['total'] += $road_observations['operation_cnt'] + $road_observations['complaint_cnt'] + $road_observations['supervise_cnt']; return $road_observations; } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index bc9e3c68..04705bf0 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -77,6 +77,7 @@ class Kernel extends HttpKernel 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class, 'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class, + 'validate-store-access' => \App\Http\Middleware\ValidateStoreAccess::class, ]; /** diff --git a/app/Http/Middleware/ValidateStoreAccess.php b/app/Http/Middleware/ValidateStoreAccess.php new file mode 100644 index 00000000..ec57469f --- /dev/null +++ b/app/Http/Middleware/ValidateStoreAccess.php @@ -0,0 +1,32 @@ +edarate_ostani_id || is_null($user->city_id), + new ProhibitedAction('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!')); + + throw_if(is_null($user->edarate_shahri_id), + new ProhibitedAction('اداره شهری برای شما در سامانه ثبت نشده است!')); + + return $next($request); + } +} diff --git a/app/Http/Requests/V3/RoadMaintenanceStation/StoreRequest.php b/app/Http/Requests/V3/RoadMaintenanceStation/StoreRequest.php new file mode 100644 index 00000000..e58698ea --- /dev/null +++ b/app/Http/Requests/V3/RoadMaintenanceStation/StoreRequest.php @@ -0,0 +1,57 @@ +user(); + + return $user->hasPermissionTo('add-tollhouse') || + ($user->hasPermissionTo('add-tollhouse-province') && $this->province_id == $user->province_id); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'province_id' => 'required|exists:provinces,id', + 'city_id' => 'required|exists:cities,id', + 'name' => 'required|string|max:255', + 'status' => 'required|in:0,1', + 'type' =>'required|in:1,2,3', + 'team_num' => 'numeric', + 'staff_num' => 'numeric', + 'phone' => 'string|max:50', + 'responsible_name' => 'string|max:255', + 'responsible_mobile' => 'string|max:50', + 'successor_name' => 'string|max:255', + 'successor_mobile' => 'string|max:50', + 'machines_light' => 'numeric', + 'machines_sheavy' => 'numeric', + 'machines_heavy' => 'numeric', + 'code' => 'string|max:50', + 'lat' => 'numeric', + 'lng' => 'numeric', + 'overview_files_1' => 'file|mimes:jpg,jpeg,png,pdf|max:51200', + 'overview_files_2' => 'file|mimes:jpg,jpeg,png,pdf|max:51200', + 'overview_files_3' => 'file|mimes:jpg,jpeg,png,pdf|max:51200', + 'overview_files_4' => 'file|mimes:jpg,jpeg,png,pdf|max:51200', + 'overview_files_5' => 'file|mimes:jpg,jpeg,png,pdf|max:51200', + ]; + } +} diff --git a/app/Http/Requests/V3/RoadMaintenanceStation/UpdateRequest.php b/app/Http/Requests/V3/RoadMaintenanceStation/UpdateRequest.php new file mode 100644 index 00000000..3443e3b1 --- /dev/null +++ b/app/Http/Requests/V3/RoadMaintenanceStation/UpdateRequest.php @@ -0,0 +1,55 @@ +|string> + */ + public function rules(): array + { + return [ + 'province_id' => 'required|exists:provinces,id', + 'city_id' => 'required|exists:cities,id', + 'name' => 'required|string|max:255', + 'status' => 'integer|in:0,1', + 'type' => 'integer|in:1,2,3', + 'team_num' => 'numeric', + 'staff_num' => 'numeric', + 'phone' => 'string|max:50', + 'responsible_name' => 'string|max:255', + 'responsible_mobile' => 'string|max:50', + 'successor_name' => 'string|max:255', + 'successor_mobile' => 'string|max:50', + 'machines_light' => 'numeric', + 'machines_sheavy' => 'numeric', + 'machines_heavy' => 'numeric', + 'lat' => 'numeric', + 'lng' => 'numeric', + 'lat_from' => 'numeric', + 'lng_from' => 'numeric', + 'lat_to' => 'numeric', + 'lng_to' => 'numeric', + 'color' => 'numeric', + 'geometry' => 'numeric', + 'overview_files_1' => 'file|mimes:jpg,jpeg,png,pdf|max:5120', + 'overview_files_2' => 'file|mimes:jpg,jpeg,png,pdf|max:5120', + 'overview_files_3' => 'file|mimes:jpg,jpeg,png,pdf|max:5120', + 'overview_files_4' => 'file|mimes:jpg,jpeg,png,pdf|max:5120', + 'overview_files_5' => 'file|mimes:jpg,jpeg,png,pdf|max:5120', + ]; + } +} diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/FinishRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/FinishRequest.php new file mode 100644 index 00000000..a8cb30bc --- /dev/null +++ b/app/Http/Requests/V3/SafetyAndPrivacy/FinishRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'final_description' => 'required|string', + ]; + } +} diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/RejectRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/RejectRequest.php new file mode 100644 index 00000000..7ddc7700 --- /dev/null +++ b/app/Http/Requests/V3/SafetyAndPrivacy/RejectRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'supervisor_description' => 'required|string', + ]; + } +} diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php index 5d130d51..dc88a0b6 100644 --- a/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php +++ b/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php @@ -22,7 +22,9 @@ class SecondStepStoreRequest extends FormRequest public function rules(): array { return [ - 'judiciary_document' => 'required|array', + 'need_judiciary' => 'required|boolean', + 'operator_description' => 'required_if:need_judiciary,0|string', + 'judiciary_document' => 'required_if:need_judiciary,1|array', 'judiciary_document.*' => 'file', ]; } diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php index 652ea3a4..91879ed5 100644 --- a/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php +++ b/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php @@ -23,6 +23,7 @@ class ThirdStepStoreRequest extends FormRequest { return [ 'action_picture' => 'required|image', + 'action_date' => 'required|date', ]; } } diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/UpdateRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/UpdateRequest.php new file mode 100644 index 00000000..c0dab333 --- /dev/null +++ b/app/Http/Requests/V3/SafetyAndPrivacy/UpdateRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'axis_type_id' => 'required|integer|exists:axis_types,id', + ]; + } +} diff --git a/app/Jobs/SendRoadObservationToNikarayan.php b/app/Jobs/SendRoadObservationToNikarayan.php index 87cdeb0c..6b7abb26 100644 --- a/app/Jobs/SendRoadObservationToNikarayan.php +++ b/app/Jobs/SendRoadObservationToNikarayan.php @@ -45,12 +45,14 @@ class SendRoadObservationToNikarayan implements ShouldQueue ); $soapClient = new SoapClient($url); - - $soapClient->UpdateInfo_RoadObservedProblems($array); + $result = $soapClient->UpdateInfo_RoadObservedProblems($array); + Log::channel('road_observation_problem')->info(json_encode($result), [$this->roadObserved->id]); } catch (\Exception $exception){ Log::channel('road_observation_problem')->error($exception->getMessage(), [ - 'roadObserved' => $this->roadObserved, + 'roadObserved' => $this->roadObserved->id, + 'line' => $exception->getLine(), + 'file' => $exception->getFile(), ]); } } diff --git a/app/Models/PointFile.php b/app/Models/PointFile.php index 4c59eb93..fc437a39 100644 --- a/app/Models/PointFile.php +++ b/app/Models/PointFile.php @@ -2,7 +2,10 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Support\Facades\Storage; class PointFile extends Model { @@ -25,14 +28,23 @@ class PointFile extends Model * @var array */ protected $fillable = [ - 'path' + 'path', + 'point_fileable_id', + 'point_fileable_type', ]; /** * Get the owning point_fileable model. */ - public function point_fileable() + public function point_fileable(): MorphTo { return $this->morphTo(); } + + protected function path(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } } diff --git a/app/Models/RahdariPoint.php b/app/Models/RahdariPoint.php index 66f9fe02..3cbbc611 100644 --- a/app/Models/RahdariPoint.php +++ b/app/Models/RahdariPoint.php @@ -3,6 +3,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphMany; class RahdariPoint extends Model { @@ -69,15 +71,12 @@ class RahdariPoint extends Model 'updated_at_fa', ]; - /** - * Get all of the point's files. - */ - public function files() + public function files(): MorphMany { return $this->morphMany('App\Models\PointFile', 'point_fileable'); } - public function rahdariPointHistories() + public function rahdariPointHistories(): HasMany { return $this->hasMany('App\Models\RahdariPointHistory', 'point_id'); } diff --git a/app/Models/RahdariPointHistory.php b/app/Models/RahdariPointHistory.php index e8d2e9fd..c6d359bc 100644 --- a/app/Models/RahdariPointHistory.php +++ b/app/Models/RahdariPointHistory.php @@ -13,6 +13,11 @@ class RahdariPointHistory extends Model */ protected $fillable = [ 'user_id', + 'previous_province_id', + 'previous_province_name', + 'previous_city_id', + 'previous_city_name', + 'previous_name', 'previous_status', 'previous_type', 'previous_team_num', diff --git a/app/Models/RoadObserved.php b/app/Models/RoadObserved.php index 18c4c9af..ce30a7a2 100644 --- a/app/Models/RoadObserved.php +++ b/app/Models/RoadObserved.php @@ -108,14 +108,20 @@ class RoadObserved extends Model protected function imageAfter(): Attribute { return Attribute::make( - get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + get: fn($value) => $value == null ? null : + (filter_var($value, FILTER_VALIDATE_URL) + ? $value + : Storage::disk('public')->url($value)) ); } protected function imageBefore(): Attribute { return Attribute::make( - get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + get: fn($value) => $value == null ? null : + (filter_var($value, FILTER_VALIDATE_URL) + ? $value + : Storage::disk('public')->url($value)) ); } } diff --git a/app/Models/SafetyAndPrivacy.php b/app/Models/SafetyAndPrivacy.php index 8cb61c14..0ae5ac91 100644 --- a/app/Models/SafetyAndPrivacy.php +++ b/app/Models/SafetyAndPrivacy.php @@ -36,6 +36,16 @@ class SafetyAndPrivacy extends Model 'action_picture_document_upload_date', 'axis_type_id', 'axis_type_name', + 'action_date', + 'status', + 'final_description', + 'is_finished', + 'supervisor_description', + 'status_fa', + 'need_judiciary', + 'operator_description', + 'supervisor_name', + 'supervisor_id' ]; public $table = "safety_and_privacy"; diff --git a/app/Services/Cartables/RoadItemTableService.php b/app/Services/Cartables/RoadItemTableService.php index 0b64e741..2638e5c5 100644 --- a/app/Services/Cartables/RoadItemTableService.php +++ b/app/Services/Cartables/RoadItemTableService.php @@ -53,7 +53,7 @@ class RoadItemTableService $allowedSortings = ['*']; $query = RoadItemsProject::query() - ->select(['id', 'supervisor_description', 'item', 'item_fa', 'sub_item', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', 'province_fa', 'edarat_name', 'supervisor_description', 'item', 'item_fa', 'sub_item', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', 'end_lat', 'end_lng', 'activity_date_time', 'created_at', 'status_fa', 'status']) ->where('is_new', 1) ->where('user_id', auth()->user()->id) diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index e7c9a85d..b6331901 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -2,123 +2,117 @@ namespace App\Services\Cartables; +use App\Exceptions\ProhibitedAction; use App\Facades\DataTable\DataTableFacade; use App\Http\Traits\ApiResponse; use App\Models\Province; use App\Models\SafetyAndPrivacy; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Throwable; class SafetyAndPrivacyTableService { use ApiResponse; - public function dataTable(Request $request, $loadRelations = false) + /** + * @throws Throwable + */ + public function operatorDataTable(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' + $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', 'operator_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')) { - if (is_null($user->province_id)) { - return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); - } + 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')) { - if (is_null($user->edarate_shahri_id)) { - return $this->errorResponse('اداره ای برای شما در سامانه ثبت نشده است!'); - } + $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: ['*'], + allowedSelects: $fields + ); + } + + /** + * @throws Throwable + */ + public function supervisorDataTable(Request $request) + { + $user = auth()->user(); + + $fields = [ + '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' + ]; + + $query = SafetyAndPrivacy::query(); + + 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, $request, allowedFilters: ['*'], - allowedSortings: ['*'] + allowedSortings: ['*'], + allowedSelects: $fields ); } public function countryActivity(Request $request): array { - $fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString(); - $toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString(); - $axisTypeId = $request->axis_type_id; - $activities = []; + $countryQuery = SafetyAndPrivacy::query()->selectRaw('COUNT(*) as qty,info_id, step'); - $country = SafetyAndPrivacy::query() - ->selectRaw('COUNT(*) as qty,info_id, step') - ->whereBetween('created_at', [$fromDate, $toDate]) - ->when($axisTypeId, function ($query) use ($axisTypeId) { - $query->where('axis_type_id', '=', $axisTypeId); - }) - ->groupBy('info_id', 'step') - ->get(); - -// $country = DB::select( -// "SELECT COUNT(*) as qty,info_id, step -// FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' -// GROUP BY info_id,step" -// ); + $country = DataTableFacade::run( + $countryQuery, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedGroupBy: ['info_id', 'step'] + ); $countryTotalSum = 0; $countryData = [ 'name_fa' => 'کشوری', 'province_id' => -1, 'sum' => 0, - '89' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '90' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '91' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], + '89' => ['1' => 0, '2' => 0, '3' => 0,], + '90' => ['1' => 0, '2' => 0, '3' => 0,], + '91' => ['1' => 0, '2' => 0, '3' => 0,], ]; - foreach ($country as $key => $value) { + foreach ($country['data'] as $key => $value) { $countryTotalSum += $value->qty; $countryData[$value->info_id][$value->step] = $value->qty; $countryData["sum"] = $countryTotalSum; } + $activities[] = (object) $countryData; + $provinceQuery = SafetyAndPrivacy::query()->selectRaw('province_id, province_fa, COUNT(*) as qty,info_id, step'); + $provinces = DataTableFacade::run( + $provinceQuery, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedGroupBy: ['info_id', 'step', 'province_id', 'province_fa'] + ); - $provinces = SafetyAndPrivacy::query() - ->selectRaw('province_id, province_fa, COUNT(*) as qty,info_id, step') - ->whereBetween('created_at', [$fromDate, $toDate]) - ->when($axisTypeId, function ($query) use ($axisTypeId) { - $query->where('axis_type_id', '=', $axisTypeId); - }) - ->groupBy('info_id', 'step', 'province_id', 'province_fa') - ->get(); - -// $provinces = DB::select( -// "SELECT province_id, province_fa, COUNT(*) as qty,info_id, step -// FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' -// GROUP BY info_id,step,province_id,province_fa" -// ); - - foreach ($provinces as $value) { + foreach ($provinces['data'] as $value) + { $provinceId = $value->province_id; - - // Check if the province already exists in the activities array if (!isset($activities[$provinceId])) { $activities[$provinceId] = (object) [ 'province_id' => $provinceId, @@ -129,92 +123,53 @@ class SafetyAndPrivacyTableService '91' => ['1' => 0, '2' => 0, '3' => 0], ]; } - $activities[$provinceId]->{$value->info_id}[$value->step] = $value->qty; $activities[$provinceId]->sum += $value->qty; } - $activities = array_values($activities); - - return [ - 'activities' => $activities, - 'fromDate' => $fromDate, - 'toDate' => $toDate, - ]; + return array_values($activities); } public function provinceActivity(Request $request): array { - $fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString(); - $toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString(); - $provinceId = $request->province_id; - $axisTypeId = $request->axis_type_id; $activities = []; - - $province = SafetyAndPrivacy::query() - ->selectRaw('COUNT(*) as qty,info_id, step') - ->where('province_id', '=', $provinceId) - ->whereBetween('created_at', [$fromDate, $toDate]) - ->when($axisTypeId, function ($query) use ($axisTypeId) { - $query->where('axis_type_id', '=', $axisTypeId); - }) - ->groupBy('info_id', 'step') - ->get(); - -// $province = DB::select(' -// SELECT COUNT(*) as qty,info_id, step -// FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" -// GROUP BY info_id,step -// '); + $provinceQuery = SafetyAndPrivacy::query()->selectRaw('COUNT(*) as qty,info_id, step'); + $province = DataTableFacade::run( + $provinceQuery, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedGroupBy: ['info_id', 'step'] + ); $provinceTotalSum = 0; $provinceData = [ 'name_fa' => 'استانی', 'edare_shahri_id' => -1, 'sum' => 0, - '89' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '90' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '91' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], + '89' => ['1' => 0, '2' => 0, '3' => 0,], + '90' => ['1' => 0, '2' => 0, '3' => 0,], + '91' => ['1' => 0, '2' => 0, '3' => 0,], ]; - foreach ($province as $key => $value) { + foreach ($province['data'] as $key => $value) { $provinceTotalSum += $value->qty; $provinceData["sum"] = $provinceTotalSum; $provinceData[$value->info_id][$value->step] = $value->qty; } $activities[] = (object) $provinceData; - $cities = SafetyAndPrivacy::query() - ->selectRaw('edare_shahri_id, COUNT(*) as qty,info_id, step') - ->where('province_id', '=', $provinceId) - ->whereBetween('created_at', [$fromDate, $toDate]) - ->when($axisTypeId, function ($query) use ($axisTypeId) { - $query->where('axis_type_id', '=', $axisTypeId); - }) - ->groupBy('info_id', 'step', 'edare_shahri_id') - ->get(); + $citiesQuery = SafetyAndPrivacy::query()->selectRaw('edare_shahri_id, COUNT(*) as qty,info_id, step'); + $cities = DataTableFacade::run( + $citiesQuery, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedGroupBy: ['info_id', 'step', 'edare_shahri_id'] + ); -// $cities = DB::select(' -// SELECT edare_shahri_id, COUNT(*) as qty,info_id, step -// FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" -// GROUP BY info_id,step,edare_shahri_id -// '); - - foreach ($cities as $value) { + foreach ($cities['data'] as $value) + { $cityId = $value->edare_shahri_id; - - // Initialize data for each unique city if (!isset($activities[$cityId])) { $activities[$cityId] = (object) [ 'edare_shahri_id' => $cityId, @@ -229,12 +184,6 @@ class SafetyAndPrivacyTableService $activities[$cityId]->sum += $value->qty; } - $activities = array_values($activities); - - return [ - 'activities' => $activities, - 'fromDate' => $fromDate, - 'toDate' => $toDate, - ]; + return array_values($activities); } } diff --git a/app/Services/DataTable/DataTableInput.php b/app/Services/DataTable/DataTableInput.php index 8464e878..1bbe5200 100644 --- a/app/Services/DataTable/DataTableInput.php +++ b/app/Services/DataTable/DataTableInput.php @@ -22,6 +22,7 @@ class DataTableInput private array $rels, private array $allowedFilters, private array $allowedSortings, + private ?array $GroupBy, ) { } @@ -74,4 +75,9 @@ class DataTableInput { return $this->rels; } + + public function getGroupBy(): ?array + { + return $this->GroupBy; + } } diff --git a/app/Services/DataTable/DataTableService.php b/app/Services/DataTable/DataTableService.php index 647f6e44..5755ad1d 100644 --- a/app/Services/DataTable/DataTableService.php +++ b/app/Services/DataTable/DataTableService.php @@ -13,6 +13,7 @@ class DataTableService protected array $allowedRelations; protected array $allowedSortings; protected array $allowedSelects; + protected array $allowedGroupBy; private int $totalRowCount; public function __construct( @@ -46,6 +47,12 @@ class DataTableService return $this; } + public function setAllowedGroupBy(array $allowedGroupBy): DataTableService + { + $this->allowedGroupBy = $allowedGroupBy; + return $this; + } + /** * Handle 'getData' operations * @return array @@ -73,6 +80,7 @@ class DataTableService $query = $this->applySelect($query, $this->allowedSelects); $query = $this->includeRelationsInQuery($query, $this->allowedRelations); + $query = $this->applyGroupBy($query, $this->allowedGroupBy); $this->totalRowCount = $query->count(); @@ -88,7 +96,7 @@ class DataTableService foreach ($sorting as $sort){ $query = (new ApplySort($query, $sort))->apply(); } - + return $query; } @@ -101,6 +109,11 @@ class DataTableService return $query; } + protected function applyGroupBy(Builder $query, array $groupBy): Builder + { + return empty($groupBy) ? $query : $query->groupBy($groupBy); + } + protected function includeRelationsInQuery(Builder $query, array $rels): Builder { if (!empty($rels)) { diff --git a/app/Services/NikarayanService.php b/app/Services/NikarayanService.php index 19f4945e..702ab1d4 100644 --- a/app/Services/NikarayanService.php +++ b/app/Services/NikarayanService.php @@ -33,7 +33,7 @@ class NikarayanService $soapClient = new SoapClient($url); $result = $soapClient->UpdateInfo_RoadObservedProblems($array); - Log::channel('nikarayan')->info($result); + Log::channel('nikarayan')->info(json_encode($result)); return $result; } @@ -49,15 +49,14 @@ class NikarayanService /** * @throws SoapFault */ - public function getRoadObservedProblemsByDate() + public function getRoadObservedProblemsByDate($time) { try { $url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl"; - $v = verta(); - $month = $v->month < 10 ? '0' . $v->month : $v->month; - $day = $v->day < 10 ? '0' . $v->day : $v->day; - $date = $v->year . $month . $day; + $month = $time->month < 10 ? '0' . $time->month : $time->month; + $day = $time->day < 10 ? '0' . $time->day : $time->day; + $date = $time->year . $month . $day; $soap_client = new SoapClient($url); return $soap_client->Get_RoadObservedProblems_ByDate(array( diff --git a/database/factories/RoadItemsProjectFactory.php b/database/factories/RoadItemsProjectFactory.php index b6543430..174d68a8 100644 --- a/database/factories/RoadItemsProjectFactory.php +++ b/database/factories/RoadItemsProjectFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Support\Facades\Schema; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> @@ -18,7 +19,16 @@ class RoadItemsProjectFactory extends Factory { return [ 'item' => $this->faker->numberBetween(1, 10), - 'sub_item' => $this->faker->numberBetween(1, 10), - ]; + 'sub_items' => $this->faker->title(), + 'start_lat' =>$this->faker->latitude(), + 'start_lng' =>$this->faker->longitude(), + 'is_new' => $this->faker->boolean(), + 'status' => $this->faker->randomElement([0, 1, 2]), + 'activity_date_time' =>$this->faker->dateTimeBetween('-1 year', 'now'), + 'province_id' => $this->faker->numberBetween(1, 10), + 'city_id' => $this->faker->numberBetween(1, 10), + 'user_id' =>$this->faker->numberBetween(1, 10), + 'user_name' => $this->faker->name(), + ]; } } diff --git a/database/migrations/2025_04_07_133638_add_column_to_safety_and_privacy_table.php b/database/migrations/2025_04_07_133638_add_column_to_safety_and_privacy_table.php new file mode 100644 index 00000000..b3934b8b --- /dev/null +++ b/database/migrations/2025_04_07_133638_add_column_to_safety_and_privacy_table.php @@ -0,0 +1,28 @@ +dateTime('action_date')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('safety_and_privacy', function (Blueprint $table) { + $table->dropColumn('action_date'); + }); + } +}; diff --git a/database/migrations/2025_04_14_150741_add_culums_to_rahdari_point_histories_table.php b/database/migrations/2025_04_14_150741_add_culums_to_rahdari_point_histories_table.php new file mode 100644 index 00000000..4743a7a3 --- /dev/null +++ b/database/migrations/2025_04_14_150741_add_culums_to_rahdari_point_histories_table.php @@ -0,0 +1,40 @@ +after('user_id', function (Blueprint $table) { + $table->unsignedSmallInteger('previous_province_id')->nullable(); + $table->string('previous_province_name')->nullable(); + $table->unsignedSmallInteger('previous_city_id')->nullable(); + $table->string('previous_city_name')->nullable(); + $table->string('previous_name')->nullable(); + }); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('rahdari_point_histories', function (Blueprint $table) { + $table->dropColumn([ + 'previous_province_id', + 'previous_province_name', + 'previous_city_id', + 'previous_city_name', + 'previous_name', + ]); + }); + } +}; 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 new file mode 100644 index 00000000..ac7409c5 --- /dev/null +++ b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php @@ -0,0 +1,44 @@ +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(); + $table->integer('supervisor_id')->nullable(); + $table->string('supervisor_name')->nullable(); + $table->text('judiciary_document')->nullable()->change(); + $table->dateTime('judiciary_document_upload_date')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + */ + 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', 'supervisor_name', 'supervisor_id', + ]); + $table->text('judiciary_document')->change(); + $table->dateTime('judiciary_document_upload_date')->change(); + }); + } +}; diff --git a/resources/views/v3/Reports/RoadItems/OperatorCartableReport.blade.php b/resources/views/v3/Reports/RoadItems/OperatorCartableReport.blade.php index 3894defd..76431163 100644 --- a/resources/views/v3/Reports/RoadItems/OperatorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadItems/OperatorCartableReport.blade.php @@ -97,7 +97,7 @@ {{ $item['sub_item_data'] ? ($item['unit_fa'] ? $item['sub_item_data'] . '(' . $item['unit_fa'] . ')' : $item['sub_item_data'] . '(-)') : '-' }} - {{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }} + {{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }} {{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }} {{ isset($item['start_lat']) && isset($item['start_lng']) ? $item['start_lat'] . ' ' . $item['start_lng'] : '-' }} @@ -114,5 +114,4 @@ - diff --git a/resources/views/v3/Reports/RoadItems/SupervisorCartableReport.blade.php b/resources/views/v3/Reports/RoadItems/SupervisorCartableReport.blade.php index 6203dbbc..d7bb9a9f 100644 --- a/resources/views/v3/Reports/RoadItems/SupervisorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadItems/SupervisorCartableReport.blade.php @@ -97,7 +97,7 @@ {{ $item['sub_item_data'] ? ($item['unit_fa'] ? $item['sub_item_data'] . '(' . $item['unit_fa'] . ')' : $item['sub_item_data'] . '(-)') : '-' }} - {{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }} + {{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }} {{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }} {{ isset($item['start_lat']) && isset($item['start_lng']) ? $item['start_lat'] . ' ' . $item['start_lng'] : '-' }} diff --git a/resources/views/v3/Reports/RoadPatrols/OperatorCartableReport.blade.php b/resources/views/v3/Reports/RoadPatrols/OperatorCartableReport.blade.php index c90cb1da..92e1f1d6 100644 --- a/resources/views/v3/Reports/RoadPatrols/OperatorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadPatrols/OperatorCartableReport.blade.php @@ -74,7 +74,7 @@ {{ $item['id'] ?? '-' }} {{ $item['province_fa'] ?? '-' }} {{ $item['edare_name'] ?? '-' }} - {{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }} + {{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }} {{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }} {{ $item['start_time'] ? verta($item['start_time'])->format('Y/n/j H:i:s') : '-' }} {{ $item['end_time'] ? verta($item['end_time'])->format('Y/n/j H:i:s') : '-' }} diff --git a/resources/views/v3/Reports/RoadPatrols/SupervisorCartableReport.blade.php b/resources/views/v3/Reports/RoadPatrols/SupervisorCartableReport.blade.php index 0fb2a3d1..af572a66 100644 --- a/resources/views/v3/Reports/RoadPatrols/SupervisorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadPatrols/SupervisorCartableReport.blade.php @@ -33,7 +33,7 @@ + style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;"> گزارش کارتابل ارزیابی گشت راهداری @@ -74,7 +74,7 @@ {{ $item['id'] ?? '-' }} {{ $item['province_fa'] ?? '-' }} {{ $item['edare_name'] ?? '-' }} - {{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }} + {{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }} {{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }} {{ $item['start_time'] ? verta($item['start_time'])->format('Y/n/j H:i:s') : '-' }} {{ $item['end_time'] ? verta($item['end_time'])->format('Y/n/j H:i:s') : '-' }} diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php index f7c5bd53..ee8c6c6a 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php @@ -28,12 +28,7 @@ - گزارش نگهداری حریم راه از تاریخ - {{ verta($fromDate)->format('Y/n/j') }} - تا - تاریخ - {{ verta($toDate)->format('Y/n/j') }} - + گزارش نگهداری حریم راه diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/OperatorCartableReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/OperatorCartableReport.blade.php new file mode 100644 index 00000000..043a3f4d --- /dev/null +++ b/resources/views/v3/Reports/SafetyAndPrivacy/OperatorCartableReport.blade.php @@ -0,0 +1,99 @@ + + + + + + + + فعالیت های نگهداری حریم راه + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش فعالیت های نگهداری حریم راه +
+ کد یکتا + + مورد مشاهده شده + + نوع محور + + تاریخ ثبت + + تاریخ بازدید + + تاریخ بارگذاری مستندات قضایی + + تاریخ اقدام + + وضعیت +
{{ $item['id'] ?? '-' }}{{ $item['info_fa'] ?? '-' }}{{ $item['axis_type_name'] ?? '-' }}{{ $item['created_at'] ? verta($item['created_at'])->format('Y/n/j H:i:s') : '-' }}{{ $item['activity_date_time'] ? verta($item['activity_date_time'])->format('Y/n/j H:i:s') : '-' }} + {{ $item['judiciary_document_upload_date'] && $item['judiciary_document_upload_date'] != '0000-00-00 00:00:00' ? verta($item['judiciary_document_upload_date'])->format('Y/n/j H:i:s') : '-' }} + + {{ $item['action_picture_document_upload_date'] ? verta($item['action_date'])->format('Y/n/j H:i:s') : '-' }} + {{ $item['step_fa'] ?? '-' }}
+ + diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php index 7e156b78..df2f7638 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php @@ -27,13 +27,8 @@ - گزارش نگهداری حریم راه از تاریخ - {{ verta($fromDate)->format('Y/n/j') }} - تا - تاریخ - {{ verta($toDate)->format('Y/n/j') }} - + style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;"> + گزارش نگهداری حریم راه diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/SupervisorCartableReport.blade.php similarity index 88% rename from resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php rename to resources/views/v3/Reports/SafetyAndPrivacy/SupervisorCartableReport.blade.php index 48fb08bf..c1065678 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/SupervisorCartableReport.blade.php @@ -21,18 +21,18 @@ - - - @@ -52,7 +52,15 @@ + + - @@ -84,6 +88,8 @@ + + - @endforeach diff --git a/routes/v3.php b/routes/v3.php index 380dd3c9..01f34693 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -10,6 +10,7 @@ use App\Http\Controllers\V3\Dashboard\ItemsManagementController; use App\Http\Controllers\V3\Dashboard\ObservedItemController; use App\Http\Controllers\V3\Dashboard\AccidentReceiptController; use App\Http\Controllers\V3\Dashboard\OtpManagementController; +use App\Http\Controllers\V3\Dashboard\RoadMaintenanceStationController; use App\Http\Controllers\V3\Dashboard\Reports\AccidentReceiptReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController; @@ -17,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; @@ -321,6 +325,7 @@ Route::prefix('road_observations') Route::prefix('log_list') ->name('logList.') + ->middleware('permission:manage-log-list') ->controller(LogListManagementController::class) ->group(function () { Route::get('/', 'index')->name('index'); @@ -333,27 +338,58 @@ Route::prefix('log_list') Route::prefix('safety_and_privacy') ->name('SafetyAndPrivacy.') - ->controller(SafetyAndPrivacyController::class) ->group(function () { - Route::get('/', 'index')->name('index')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri'); - Route::get('/excel_report', 'excelReport')->name('excelReport')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri'); - Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy'); - Route::get('/sub_items', 'subItems')->name('subItems'); - Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy'); - Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-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::name('operator.') + ->controller(OperatorController::class) + ->group(function () { + Route::get('operator', 'index')->name('index') + ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); + Route::get('operator/excel_report', 'excelReport')->name('excelReport') + ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri'); + 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('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('operator/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') @@ -372,6 +408,7 @@ Route::name('items.') Route::prefix('permissions') ->name('permissions.') + ->middleware('permission:manage-permissions') ->controller(PermissionManagementController::class) ->group(function () { Route::get('/', 'index')->name('index'); @@ -382,3 +419,16 @@ Route::prefix('permissions') }); Route::get('/notifications', NotificationController::class)->name('notifications'); + +Route::prefix('road_maintenance_station') + ->name('roadMaintenanceStation.') + ->controller( RoadMaintenanceStationController::class) + ->group(function () { + Route::get('/', 'index')->name('index')->middleware('permission:show-tollhouse|show-tollhouse-province'); + Route::post('/', 'store')->name('store'); + Route::get('/map', 'map')->name('map'); + Route::get('/images/{rahdariPoint}', 'images')->name('images'); + Route::get('/{rahdariPoint}', 'show')->name('show')->middleware('permission:show-tollhouse|show-tollhouse-province'); + Route::post('/{rahdariPoint}', 'update')->name('update')->middleware('permission:edit-tollhouse|edit-tollhouse-province'); + Route::delete('/{rahdariPoint}', 'destroy')->name('destroy')->middleware('permission:delete-tollhouse|delete-tollhouse-province'); + }); diff --git a/tests/Feature/V3/Permission/IndexTest.php b/tests/Feature/V3/Permission/IndexTest.php new file mode 100644 index 00000000..e53c1cd6 --- /dev/null +++ b/tests/Feature/V3/Permission/IndexTest.php @@ -0,0 +1,59 @@ +create(); + + $response = $this->actingAs($user)->getJson(route('v3.permissions.index')); + + $response->assertForbidden(); + } + + public function test_all_permissions_returned_successfully(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->getJson(route('v3.permissions.index', [ + 'start' => 0, + 'size' => 10, + 'filters' => json_encode([]), + 'sorting' => json_encode([]), + ])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'name', + 'name_fa', + 'type', + 'type_fa', + 'description', + ], + ], + "meta" => [ + "totalRowCount" + ] + ]); + } +} diff --git a/tests/Feature/V3/Permission/StoreTest.php b/tests/Feature/V3/Permission/StoreTest.php new file mode 100644 index 00000000..37df8b84 --- /dev/null +++ b/tests/Feature/V3/Permission/StoreTest.php @@ -0,0 +1,297 @@ +create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertForbidden(); + } + + public function test_name_attribute_is_required(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'name' => __('validation.required', ['attribute' => 'نام']) + ]); + } + + public function test_name_attribute_should_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'name' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'name' => __('validation.string', ['attribute' => 'نام']) + ]); + } + + public function test_name_attribute_should_be_unique(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $permission = Permission::factory()->create([ + 'name' => $this->faker->name() + ]); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'name' => $permission->name, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'name' => __('validation.unique', ['attribute' => 'نام']) + ]); + } + + public function test_name_fa_attribute_is_required(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'name_fa' => __('validation.required', ['attribute' => 'name fa']) + ]); + } + + public function test_name_fa_attribute_should_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'name_fa' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'name_fa' => __('validation.string', ['attribute' => 'name fa']) + ]); + } + + public function test_description_attribute_should_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'description' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'description' => __('validation.string', ['attribute' => 'توضیحات']) + ]); + } + + public function test_type_attribute_is_required(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'type' => __('validation.required', ['attribute' => 'type']) + ]); + } + + public function test_type_attribute_should_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'type' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'type' => __('validation.string', ['attribute' => 'type']) + ]); + } + + public function test_type_fa_attribute_is_required(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'type_fa' => __('validation.required', ['attribute' => 'type fa']) + ]); + } + + public function test_type_fa_attribute_should_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'type_fa' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'type_fa' => __('validation.string', ['attribute' => 'type fa']) + ]); + } + + public function test_need_province_attribute_is_required(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'need_province' => __('validation.required', ['attribute' => 'need province']) + ]); + } + + public function test_need_province_attribute_should_be_1_or_0(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'need_province' => $this->faker->numberBetween(3, 9), + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'need_province' => __('validation.in', ['attribute' => 'need province']) + ]); + } + + public function test_need_edare_shahri_attribute_is_required(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'need_edare_shahri' => __('validation.required', ['attribute' => 'need edare shahri']) + ]); + } + + public function test_need_edare_shahri_attribute_should_be_1_or_0(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [ + 'need_edare_shahri' => $this->faker->numberBetween(3, 9), + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'need_edare_shahri' => __('validation.in', ['attribute' => 'need edare shahri']) + ]); + } + + public function test_user_can_create_a_permission() + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-permissions' + ])) + ->create(); + + $inputData = [ + 'name' => $this->faker->name(), + 'name_fa' => $this->faker->name(), + 'description' => $this->faker->lexify(), + 'type' => $this->faker->name(), + 'type_fa' => $this->faker->name(), + 'need_province' => $this->faker->numberBetween(0, 1), + 'need_edare_shahri' => $this->faker->numberBetween(0, 1), + ]; + + $response = $this->actingAs($user)->postJson(route('v3.permissions.store'), $inputData); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful'), + ]); + + $this->assertDatabaseHas('permissions', $inputData); + } +} diff --git a/tests/Feature/V3/RoadItemsProject/DeleteTest.php b/tests/Feature/V3/RoadItemsProject/DeleteTest.php new file mode 100644 index 00000000..09fb4ae8 --- /dev/null +++ b/tests/Feature/V3/RoadItemsProject/DeleteTest.php @@ -0,0 +1,57 @@ +create(); + $roadItem = RoadItemsProject::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.delete', [$roadItem->id])); + $response->assertForbidden(); + } + + public function test_user_cannot_access_authentication_delete(): void + { + $roadItem = RoadItemsProject::factory()->create(); + $response =$this->postJson(route('v3.road_items.delete', [$roadItem->id])); + $response->assertStatus(401); + + } + + public function test_user_can_delete_road_item(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'delete-road-item' + ])) + ->create(); + + $logList = LogList::factory()->create([ + 'log_unique_code' => 1151, + ]); + UserActivityLog::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.delete', [$roadItem->id])); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + $this->assertDatabaseMissing('road_items_projects', [ + 'id' => $roadItem->id, + ]); + } +} diff --git a/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php b/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php index b7e9a765..27888ae7 100644 --- a/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php +++ b/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php @@ -24,6 +24,14 @@ class OperatorIndexTest extends TestCase $response->assertForbidden(); } + public function test_user_cannot_access_authentication_to_operator_index(): void + { + $response = $this->getJson(route('v3.road_items.operatorIndex')); + + $response->assertStatus(401); + } + + public function test_operator_can_see_the_data_table(): void { $user = User::factory() diff --git a/tests/Feature/V3/RoadItemsProject/RestoreTest.php b/tests/Feature/V3/RoadItemsProject/RestoreTest.php new file mode 100644 index 00000000..a0688df5 --- /dev/null +++ b/tests/Feature/V3/RoadItemsProject/RestoreTest.php @@ -0,0 +1,72 @@ +create(); + $roadItem = RoadItemsProject::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id])); + $response->assertForbidden(); + } + public function test_user_cannot_access_authentication_restore(): void + { + $roadItem = RoadItemsProject::factory()->create(); + $response =$this->postJson(route('v3.road_items.restore', [$roadItem->id])); + $response->assertStatus(401); + + } + public function test_user_can_restore_road_item(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'restore-road-item' + ])) + ->create(); + + $logList = LogList::factory()->create([ + 'log_unique_code' => 1150, + ]); + UserActivityLog::factory()->create(); + + $roadItem = RoadItemsProject::factory()->create([ + 'status' => 1, + 'status_fa' => 'تایید شده', + 'supervisor_id' => $user->id, + 'supervisor_name' => $user->name, + 'supervisor_description' => 'تایید شده توسط تست', + ]); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id])); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + + $this->assertDatabaseHas('road_items_projects', [ + 'id' => $roadItem->id, + 'status' => 0, + 'status_fa' => 'در حال بررسی', + 'supervisor_id' => null, + 'supervisor_name' => null, + 'supervisor_description' => null, + 'supervising_time' => null, + ]); + } + +} diff --git a/tests/Feature/V3/RoadItemsProject/StoreTest.php b/tests/Feature/V3/RoadItemsProject/StoreTest.php index ee141ece..7a44821a 100644 --- a/tests/Feature/V3/RoadItemsProject/StoreTest.php +++ b/tests/Feature/V3/RoadItemsProject/StoreTest.php @@ -12,6 +12,7 @@ use App\Models\ObservedItem; use App\Models\Permission; use App\Models\Province; use App\Models\Rahdaran; +use App\Models\RoadItemsProject; use App\Models\User; use App\Models\UserActivityLog; use App\Services\NominatimService; @@ -22,6 +23,8 @@ use Illuminate\Support\Facades\Storage; use Mockery\MockInterface; use Symfony\Component\Finder\Exception\AccessDeniedException; use Tests\TestCase; +use Illuminate\Support\Str; + class StoreTest extends TestCase { @@ -37,104 +40,56 @@ class StoreTest extends TestCase $response->assertForbidden(); } + public function test_user_cannot_access_authentication_store(): void + { +// $roadItem = RoadItemsProject::factory()->create(); + $response =$this->postJson(route('v3.road_items.store')); + $response->assertStatus(401); - public function test_start_point_is_required(): void + } + + public function test_required_fields(): void { $user = User::factory() ->has(Permission::factory([ 'name' => 'create-road-item' ])) ->create(); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); $response->assertUnprocessable() ->assertInvalid([ - 'start_point' => __('validation.required', ['attribute' => 'start point']) + 'start_point' => __('validation.required', ['attribute' => 'start point']), + 'item_id' => __('validation.required', ['attribute' => 'item id']), + 'sub_item_id' => __('validation.required', ['attribute' => 'sub item id']), + 'amount' => __('validation.required', ['attribute' => 'amount']), + 'activity_date' => __('validation.required', ['attribute' => 'تاریخ فعالیت']), + 'activity_time' => __('validation.required', ['attribute' => 'ساعت فعالیت']), + 'machines_id' => __('validation.required', ['attribute' => 'machines id']), + 'rahdaran_id' => __('validation.required', ['attribute' => 'rahdaran id']), ]); } - public function test_item_id_is_required(): void + public function test_integer_fields(): void { $user = User::factory() ->has(Permission::factory([ 'name' => 'create-road-item' ])) ->create(); + $data = [ + 'item_id' => $this->faker->name, + 'sub_item_id' => $this->faker->name, + 'observed_item_id' => $this->faker->name, + ]; - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); + $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); $response->assertUnprocessable() ->assertInvalid([ - 'item_id' => __('validation.required', ['attribute' => 'item id']) - ]); - } - - public function test_item_id_should_be_integer(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'item_id' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'item_id' => __('validation.integer', ['attribute' => 'item id']) - ]); - } - - public function test_sub_item_id_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'sub_item_id' => __('validation.required', ['attribute' => 'sub item id']) - ]); - } - - public function test_sub_item_id_should_be_integer(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'sub_item_id' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'sub_item_id' => __('validation.integer', ['attribute' => 'sub item id']) - ]); - } - - public function test_amount_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'amount' => __('validation.required', ['attribute' => 'amount']) + 'item_id' => __('validation.integer', ['attribute' => 'item id']), + 'sub_item_id' => __('validation.integer', ['attribute' => 'sub item id']), + 'observed_item_id' => __('validation.integer', ['attribute' => 'observed item id']), ]); } @@ -156,7 +111,7 @@ class StoreTest extends TestCase ]); } - public function test_observed_item_id_should_be_integer(): void + public function test_exists_fields(): void { $user = User::factory() ->has(Permission::factory([ @@ -164,523 +119,362 @@ class StoreTest extends TestCase ])) ->create(); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'observed_item_id' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'observed_item_id' => __('validation.integer', ['attribute' => 'observed item id']) - ]); - } - - public function test_observed_item_id_should_be_existed_in_db(): void - { - $observedItem = ObservedItem::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'observed_item_id' => $this->faker->numberBetween(10, 20) - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'observed_item_id' => __('validation.exists', ['attribute' => 'observed item id']) - ]); - } - - public function test_activity_date_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_date' => __('validation.required', ['attribute' => 'تاریخ فعالیت']) - ]); - } - - public function test_activity_date_should_match_the_format(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'activity_date' => $this->faker->date('d-m-Y-H-i-s') - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_date' => __('validation.date_format', ['attribute' => 'تاریخ فعالیت', 'format' => 'Y-m-d']) - ]); - } - - public function test_activity_time_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_time' => __('validation.required', ['attribute' => 'ساعت فعالیت']) - ]); - } - - public function test_activity_time_should_match_the_format(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'activity_time' => $this->faker->date('d-m-Y-H-i-s') - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_time' => __('validation.date_format', ['attribute' => 'ساعت فعالیت', 'format' => 'H:i']) - ]); - } - - public function test_before_image_should_be_image(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'before_image' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'before_image' => __('validation.image', ['attribute' => 'before image']) - ]); - } - - public function test_before_image_should_be_less_than_4096kb(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $image = UploadedFile::fake()->create('image.jpg', 5096); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'before_image' => $image - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'before_image' => __('validation.max.file', ['attribute' => 'before image', 'max' => 4096]) - ]); - } - - public function test_after_image_should_be_image(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'after_image' => $this->faker->randomNumber() - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'after_image' => __('validation.image', ['attribute' => 'after image']) - ]); - } - - public function test_after_image_should_be_less_than_4096kb(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $image = UploadedFile::fake()->create('image.jpg', 5096); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'after_image' => $image - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'after_image' => __('validation.max.file', ['attribute' => 'after image', 'max' => 4096]) - ]); - } - - public function test_cmms_machine_id_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'cmms_machine_id' => __('validation.required', ['attribute' => 'کد یکتا ماشین']) - ]); - } - - public function test_cmms_machine_id_should_already_exists_on_the_table(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'cmms_machine_id' => $this->faker->numberBetween(10, 100) - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'cmms_machine_id' => __('validation.exists', ['attribute' => 'کد یکتا ماشین']) - ]); - } - - public function test_rahdar_id_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'rahdar_id' => __('validation.required', ['attribute' => 'rahdar id']) - ]); - } - - public function test_rahdar_id_should_already_exists_on_the_table(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'rahdar_id' => $this->faker->numberBetween(10, 100) - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'rahdar_id' => __('validation.exists', ['attribute' => 'rahdar id']) - ]); - } - - public function test_province_user_is_prohibited_to_access(): void - { - $edarateOstani = EdarateOstani::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'edarate_ostani_id' => $edarateOstani->id - ]); - $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'machines_id' => [$this->faker->numberBetween(10000, 99999)], + 'rahdaran_id' => [$this->faker->numberBetween(10000, 99999)], + 'observed_item_id' => $this->faker->numberBetween(10000, 99999), ]; $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - $response->assertStatus(400) - ->assertExactJson([ - 'message' => 'امکان ثبت فعالیت برای ادارات استانی و ستادی وجود ندارد!' + $response->assertUnprocessable() + ->assertInvalid([ + 'machines_id.0', + 'rahdaran_id.0', + 'observed_item_id', ]); } - public function test_user_should_have_edarate_shahri_id(): void + public function test_image_fields(): void { - $city = City::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - $user = User::factory() ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id - ]); + 'name' => 'create-road-item'])) + ->create(); $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'before_image' =>$this->faker->name, + 'after_image' =>$this->faker->name, ]; $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - $response->assertStatus(400) - ->assertExactJson([ - 'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!' - ]); - } - - public function test_end_point_required_when_info_item_needs_end_point(): void - { - $city = City::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id, - 'edarate_shahri_id' => $edarateShari->id - ]); - - $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, - ]; - - InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_end_point' => 1 - ]); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - $response->assertUnprocessable() ->assertInvalid([ - 'end_point' => __('validation.required', ['attribute' => 'end_point']) + 'before_image' => __('validation.image', ['attribute' => 'before image']), + 'after_image' => __('validation.image', ['attribute' => 'after image']), ]); } - public function test_before_image_required_when_info_item_needs_image(): void + public function test_image_should_be_less_than_4096kb(): void { - $city = City::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - $user = User::factory() ->has(Permission::factory([ 'name' => 'create-road-item' ])) - ->create([ - 'city_id' => $city->id, - 'edarate_shahri_id' => $edarateShari->id - ]); + ->create(); $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'before_image' => UploadedFile::fake()->create('image.jpg', 5096), + 'after_image' => UploadedFile::fake()->create('image.jpg', 5096), ]; - InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_image' => 1 - ]); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); $response->assertUnprocessable() ->assertInvalid([ - 'before_image' => __('validation.required', ['attribute' => 'before_image']) + 'before_image' => __('validation.max.file', ['attribute' => 'before image', 'max' => 4096]), + 'after_image' => __('validation.max.file', ['attribute' => 'after image', 'max' => 4096]), ]); } - public function test_after_image_required_when_info_item_needs_image(): void + public function test_date_format_fields(): void { - $city = City::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - $user = User::factory() ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id, - 'edarate_shahri_id' => $edarateShari->id - ]); + 'name' => 'create-road-item'])) + ->create(); $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'activity_date' => $this->faker->date('d-m-Y-H-i-s'), + 'activity_time'=> $this->faker->date('d-m-Y-H-i-s'), ]; - InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_image' => 1 - ]); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); $response->assertUnprocessable() ->assertInvalid([ - 'after_image' => __('validation.required', ['attribute' => 'after_image']) + 'activity_date' => __('validation.date_format', ['attribute' => 'تاریخ فعالیت', 'format' => 'Y-m-d']), + 'activity_time' => __('validation.date_format', ['attribute' => 'ساعت فعالیت', 'format' => 'H:i']), ]); } +// +// public function test_province_user_is_prohibited_to_access(): void +// { +// $edarateOstani = EdarateOstani::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'edarate_ostani_id' => $edarateOstani->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertStatus(400) +// ->assertExactJson([ +// 'message' => 'امکان ثبت فعالیت برای ادارات استانی و ستادی وجود ندارد!' +// ]); +// } +// +// public function test_user_should_have_edarate_shahri_id(): void +// { +// $city = City::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertStatus(400) +// ->assertExactJson([ +// 'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!' +// ]); +// } +// +// public function test_end_point_required_when_info_item_needs_end_point(): void +// { +// $city = City::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_end_point' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertUnprocessable() +// ->assertInvalid([ +// 'end_point' => __('validation.required', ['attribute' => 'end_point']) +// ]); +// } +// +// public function test_before_image_required_when_info_item_needs_image(): void +// { +// $city = City::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_image' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertUnprocessable() +// ->assertInvalid([ +// 'before_image' => __('validation.required', ['attribute' => 'before_image']) +// ]); +// } +// +// public function test_after_image_required_when_info_item_needs_image(): void +// { +// $city = City::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_image' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertUnprocessable() +// ->assertInvalid([ +// 'after_image' => __('validation.required', ['attribute' => 'after_image']) +// ]); +// } +// +// public function test_can_store_a_new_road_item_project(): void +// { +// $city = City::factory()->create(); +// $province = Province::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// LogList::factory()->create([ +// 'log_unique_code' => 1154 +// ]); +// UserActivityLog::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'province_id' => $province->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// Storage::fake('public'); +// +// $this->mock(NominatimService::class, function (MockInterface $mock) { +// $mock->shouldReceive('get_way_id_from_nominatim') +// ->once() +// ->andReturn(0); +// }); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// $infoItem = InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_image' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertOk() +// ->assertExactJson([ +// 'message' => __('messages.successful') +// ]); +// +// $this->assertDatabaseHas('road_items_projects', [ +// 'start_lat' => 12, +// 'start_lng' => 12, +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'province_id' => $province->id, +// 'city_id' => $city->id, +// 'user_name' => $user->name, +// 'start_way_id' => 0, +// 'info_id' => $infoItem->id, +// 'status' => 0, +// 'status_fa' => 'در حال بررسی', +// 'edarat_id' => $user->edarate_shahri_id, +// 'cmms_machine_id' => $cmmsMachine->id, +// 'cmms_machine_code' => $cmmsMachine->machine_code, +// 'rahdar_id' => $rahdar->id, +// 'rahdar_code' => $rahdar->code +// ]); +// +// $this->assertDatabaseHas('user_activity_logs', [ +// 'user_id' => $user->id, +// 'username' => $user->username, +// 'log_unique_code' => 1154, +// ]); +// - public function test_can_store_a_new_road_item_project(): void - { - $city = City::factory()->create(); - $province = Province::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - - LogList::factory()->create([ - 'log_unique_code' => 1154 - ]); - UserActivityLog::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id, - 'province_id' => $province->id, - 'edarate_shahri_id' => $edarateShari->id - ]); - - Storage::fake('public'); - - $this->mock(NominatimService::class, function (MockInterface $mock) { - $mock->shouldReceive('get_way_id_from_nominatim') - ->once() - ->andReturn(0); - }); - - $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, - ]; - - $infoItem = InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_image' => 1 - ]); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - - $response->assertOk() - ->assertExactJson([ - 'message' => __('messages.successful') - ]); - - $this->assertDatabaseHas('road_items_projects', [ - 'start_lat' => 12, - 'start_lng' => 12, - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'province_id' => $province->id, - 'city_id' => $city->id, - 'user_name' => $user->name, - 'start_way_id' => 0, - 'info_id' => $infoItem->id, - 'status' => 0, - 'status_fa' => 'در حال بررسی', - 'edarat_id' => $user->edarate_shahri_id, - 'cmms_machine_id' => $cmmsMachine->id, - 'cmms_machine_code' => $cmmsMachine->machine_code, - 'rahdar_id' => $rahdar->id, - 'rahdar_code' => $rahdar->code - ]); - - $this->assertDatabaseHas('user_activity_logs', [ - 'user_id' => $user->id, - 'username' => $user->username, - 'log_unique_code' => 1154, - ]); - } } diff --git a/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php b/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php index 13a080d4..602f4bdb 100644 --- a/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php +++ b/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php @@ -23,6 +23,13 @@ class SupervisorIndexTest extends TestCase $response->assertForbidden(); } + public function test_user_cannot_access_authentication_to_supervisor_index(): void + { + $response = $this->getJson(route('v3.road_items.supervisorIndex')); + + $response->assertStatus(401); + } + public function test_supervisor_can_see_the_data_table(): void { @@ -47,49 +54,21 @@ class SupervisorIndexTest extends TestCase 'data' => [ '*' => [ "id", - "user_id", "start_lat", "start_lng", "end_lat", "end_lng", - "project_distance", "item", "item_fa", - "sub_item", "sub_item_fa", "sub_item_data", - "sub_items", - "sub_items_data", "created_at", - "updated_at", - "province_id", "province_fa", - "city_id", - "city_fa", - "is_new", - "parent_id", - "start_way_id", - "end_way_id", "unit_fa", - "user_name", - "created_at_fa", - "info_id", "status", "status_fa", - "edarat_id", "edarat_name", - "edarat_type", - "activity_date", - "activity_time", "activity_date_time", - "supervisor_id", - "supervisor_name", - "supervisor_description", - "supervising_time", - "cmms_machine_id", - "cmms_machine_code", - "rahdar_id", - "rahdar_code", "can_supervise", ], ] diff --git a/tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php b/tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php new file mode 100644 index 00000000..24c14c43 --- /dev/null +++ b/tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php @@ -0,0 +1,133 @@ +create(); + + $response = $this->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id])); + + $response->assertStatus(401); + } + + public function test_supervisor_without_permission_cannot_verify_road_item(): void + { + $user = User::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(false); + + $roadItem = RoadItemsProject::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id,])); + + $response->assertForbidden(); + } + public function test_validation_fails_when_required_fields_are_missing(): void + { + $user = User::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'verify' => __('validation.required', ['attribute' => 'verify']), + ]); + } + + public function test_validation_fails_when_verify_field_is_invalid(): void + { + $user = User::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]), [ + 'verify' => 5, + 'description' => $this->faker()->sentence(), + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'verify' => __('validation.in', ['attribute' => 'verify']), + ]); + } + + public function test_verify_description_must_be_string(): void + { + $user = User::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]), [ + 'description' => 12345, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'description' => __('validation.string', ['attribute' =>"توضیحات"]), + ]); + } + + + + public function test_supervisor_can_view_road_item_data(): void + { + $user = User::factory()->create(); + + LogList::factory()->create([ + 'log_unique_code' => 1149, + ]); + UserActivityLog::factory()->create(); + + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $description = fake()->sentence(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id,]), [ + 'verify' => 1, + 'description' =>$description, + ]); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + $this->assertDatabaseHas('road_items_projects', [ + 'id' => $roadItem->id, + 'status' => 1, + 'status_fa' => 'تایید شده', + 'supervisor_id' => $user->id, + 'supervisor_name' => $user->name, + 'supervisor_description' =>$description, + ]); + } +}
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
گزارش فعالیت های نگهداری حریم راه - مورد + مورد مشاهده شده + + نوع محور + + تاریخ ثبت @@ -60,7 +68,7 @@ - تاریخ ثبت مستندات قضایی + تاریخ بارگذاری مستندات قضایی @@ -70,10 +78,6 @@ style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;"> وضعیت - تاریخ ثبت -
{{ $item['province_fa'] ?? '-' }} {{ $item['edare_shahri_name'] ?? '-' }} {{ $item['info_fa'] ?? '-' }}{{ $item['axis_type_name'] ?? '-' }}{{ $item['created_at'] ? verta($item['created_at'])->format('Y/n/j H:i:s') : '-' }} {{ $item['activity_date_time'] ? verta($item['activity_date_time'])->format('Y/n/j H:i:s') : '-' }} @@ -91,11 +97,10 @@ - {{ $item['action_picture_document_upload_date'] ? verta($item['action_picture_document_upload_date'])->format('Y/n/j H:i:s') : '-' }} + {{ $item['action_picture_document_upload_date'] ? verta($item['action_date'])->format('Y/n/j H:i:s') : '-' }} {{ $item['step_fa'] ?? '-' }}{{ $item['created_at'] ? verta($item['created_at'])->format('Y/n/j H:i:s') : '-' }}