From 469fc351f5307803e8f5d6b7f43d3b3a39bb9d80 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 17 Feb 2025 13:55:02 +0330 Subject: [PATCH 01/61] creat controller ,request and route about damage and fix model --- .../V3/DamageManagementController.php | 97 +++++++++++++++++++ app/Http/Requests/V3/Damage/DeleteRequest.php | 28 ++++++ app/Http/Requests/V3/Damage/StoreRequest.php | 31 ++++++ app/Http/Requests/V3/Damage/UpdateRequest.php | 31 ++++++ app/Models/Damage.php | 13 ++- database/factories/DamageFactory.php | 26 +++++ database/seeders/DamageSeeder.php | 18 ++++ database/seeders/UsersTableSeeder.php | 2 + routes/v3.php | 13 +++ 9 files changed, 254 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/V3/DamageManagementController.php create mode 100644 app/Http/Requests/V3/Damage/DeleteRequest.php create mode 100644 app/Http/Requests/V3/Damage/StoreRequest.php create mode 100644 app/Http/Requests/V3/Damage/UpdateRequest.php create mode 100644 database/factories/DamageFactory.php create mode 100644 database/seeders/DamageSeeder.php diff --git a/app/Http/Controllers/V3/DamageManagementController.php b/app/Http/Controllers/V3/DamageManagementController.php new file mode 100644 index 00000000..a00eac3c --- /dev/null +++ b/app/Http/Controllers/V3/DamageManagementController.php @@ -0,0 +1,97 @@ +json($data); + } + + public function list(): JsonResponse + { + $damages = Damage::query()->where('status', '=', 1)->get(); + return $this->successResponse($damages); + } + + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + Damage::query()->create([ + 'title' => $request->title, + 'unit' => $request->unit, + 'base_price' => $request->base_price, + 'status' => $request->status, + ]); + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(Damage $damage): JsonResponse + + { + return $this->successResponse($damage); + } + + /** + * Show the form for editing the specified resource. + */ + + public function update(UpdateRequest $request, Damage $damage): JsonResponse + + { + $damage->update([ + 'title' => $request->title, + 'unit' => $request->unit, + 'base_price' => $request->base_price, + 'status' => $request->status, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(DeleteRequest $request, Damage $damage): JsonResponse + { + $damage->update([ + 'status' => $request->status, + ]); + + return $this->successResponse(); + } +} diff --git a/app/Http/Requests/V3/Damage/DeleteRequest.php b/app/Http/Requests/V3/Damage/DeleteRequest.php new file mode 100644 index 00000000..aea281d6 --- /dev/null +++ b/app/Http/Requests/V3/Damage/DeleteRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'status' => 'required|in:0,1', + ]; + } +} diff --git a/app/Http/Requests/V3/Damage/StoreRequest.php b/app/Http/Requests/V3/Damage/StoreRequest.php new file mode 100644 index 00000000..2e3e88ef --- /dev/null +++ b/app/Http/Requests/V3/Damage/StoreRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'title' =>'required|string|max:255|unique:damages,title', + 'unit' =>'required|string|max:255', + 'base_price' =>'required|integer', + 'status' =>'required|in:0,1', + ]; + } +} diff --git a/app/Http/Requests/V3/Damage/UpdateRequest.php b/app/Http/Requests/V3/Damage/UpdateRequest.php new file mode 100644 index 00000000..d3d0e038 --- /dev/null +++ b/app/Http/Requests/V3/Damage/UpdateRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'title' =>'required|string|unique:damages,title', + 'unit' =>'required|string', + 'base_price' =>'required|numeric', + 'status' =>'required|integer', + ]; + } +} diff --git a/app/Models/Damage.php b/app/Models/Damage.php index 23e07551..7ae46d70 100644 --- a/app/Models/Damage.php +++ b/app/Models/Damage.php @@ -2,15 +2,18 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Damage extends Model { - - protected $fillable = [ - 'damage_id', - ]; - public function accidents() + use HasFactory; + + public $timestamps = false; + + protected $guarded = []; + public function accidents(): BelongsToMany { return $this->belongsToMany('App\Accident'); } diff --git a/database/factories/DamageFactory.php b/database/factories/DamageFactory.php new file mode 100644 index 00000000..efe62b9d --- /dev/null +++ b/database/factories/DamageFactory.php @@ -0,0 +1,26 @@ + + */ +class DamageFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'title' => $this->faker->title(), + 'unit' => $this->faker->word(), + 'base_price' => $this->faker->numberBetween(1000, 10000), + 'status' => 1 + ]; + } +} diff --git a/database/seeders/DamageSeeder.php b/database/seeders/DamageSeeder.php new file mode 100644 index 00000000..09078e9c --- /dev/null +++ b/database/seeders/DamageSeeder.php @@ -0,0 +1,18 @@ +create(); + } +} diff --git a/database/seeders/UsersTableSeeder.php b/database/seeders/UsersTableSeeder.php index 56d9496f..f40fd99b 100644 --- a/database/seeders/UsersTableSeeder.php +++ b/database/seeders/UsersTableSeeder.php @@ -1,5 +1,7 @@ name('activitiesOnMap'); Route::get('/show_on_map/{roadPatrol}', 'showOnMap')->name('showOnMap'); }); + +Route::prefix('damages') + ->name('damages.') + ->controller(DamageManagementController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::get('/list', 'list')->name('list'); + Route::post('/', 'store')->name('store'); + Route::get('/{damage}', 'show')->name('show'); + Route::post('/{damage}', 'update')->name('update'); + Route::post('/delete/{damage}', 'destroy')->name('destroy'); + }); From 37da92d87c6759427efd40b90734a1fe792059fd Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 17 Feb 2025 14:49:26 +0330 Subject: [PATCH 02/61] fix controller,request and route --- .../V3/DamageManagementController.php | 10 ++----- app/Http/Requests/V3/Damage/DeleteRequest.php | 28 ------------------- app/Http/Requests/V3/Damage/StoreRequest.php | 1 - app/Http/Requests/V3/Damage/UpdateRequest.php | 4 +-- routes/v3.php | 2 +- 5 files changed, 6 insertions(+), 39 deletions(-) delete mode 100644 app/Http/Requests/V3/Damage/DeleteRequest.php diff --git a/app/Http/Controllers/V3/DamageManagementController.php b/app/Http/Controllers/V3/DamageManagementController.php index a00eac3c..27da5b63 100644 --- a/app/Http/Controllers/V3/DamageManagementController.php +++ b/app/Http/Controllers/V3/DamageManagementController.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers\V3; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; -use App\Http\Requests\V3\Damage\DeleteRequest; use App\Http\Requests\V3\Damage\StoreRequest; use App\Http\Requests\V3\Damage\UpdateRequest; use App\Http\Traits\ApiResponse; @@ -51,7 +50,7 @@ class DamageManagementController extends Controller 'title' => $request->title, 'unit' => $request->unit, 'base_price' => $request->base_price, - 'status' => $request->status, + 'status' => 1, ]); return $this->successResponse(); @@ -77,7 +76,6 @@ class DamageManagementController extends Controller 'title' => $request->title, 'unit' => $request->unit, 'base_price' => $request->base_price, - 'status' => $request->status, ]); return $this->successResponse(); @@ -86,11 +84,9 @@ class DamageManagementController extends Controller /** * Remove the specified resource from storage. */ - public function destroy(DeleteRequest $request, Damage $damage): JsonResponse + public function activate(Damage $damage): JsonResponse { - $damage->update([ - 'status' => $request->status, - ]); + $damage->status == 1 ? $damage->update(['status' => 0]) : $damage->update(['status' => 1]); return $this->successResponse(); } diff --git a/app/Http/Requests/V3/Damage/DeleteRequest.php b/app/Http/Requests/V3/Damage/DeleteRequest.php deleted file mode 100644 index aea281d6..00000000 --- a/app/Http/Requests/V3/Damage/DeleteRequest.php +++ /dev/null @@ -1,28 +0,0 @@ -|string> - */ - public function rules(): array - { - return [ - 'status' => 'required|in:0,1', - ]; - } -} diff --git a/app/Http/Requests/V3/Damage/StoreRequest.php b/app/Http/Requests/V3/Damage/StoreRequest.php index 2e3e88ef..6d8647b0 100644 --- a/app/Http/Requests/V3/Damage/StoreRequest.php +++ b/app/Http/Requests/V3/Damage/StoreRequest.php @@ -25,7 +25,6 @@ class StoreRequest extends FormRequest 'title' =>'required|string|max:255|unique:damages,title', 'unit' =>'required|string|max:255', 'base_price' =>'required|integer', - 'status' =>'required|in:0,1', ]; } } diff --git a/app/Http/Requests/V3/Damage/UpdateRequest.php b/app/Http/Requests/V3/Damage/UpdateRequest.php index d3d0e038..70b0833a 100644 --- a/app/Http/Requests/V3/Damage/UpdateRequest.php +++ b/app/Http/Requests/V3/Damage/UpdateRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\V3\Damage; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rule; class UpdateRequest extends FormRequest { @@ -22,10 +23,9 @@ class UpdateRequest extends FormRequest public function rules(): array { return [ - 'title' =>'required|string|unique:damages,title', + 'title' =>['required', 'string', 'max:255',Rule::unique('damages','title')->ignore($this->damage->id)], 'unit' =>'required|string', 'base_price' =>'required|numeric', - 'status' =>'required|integer', ]; } } diff --git a/routes/v3.php b/routes/v3.php index 9a1abcc3..b21aeb26 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -226,5 +226,5 @@ Route::prefix('damages') Route::post('/', 'store')->name('store'); Route::get('/{damage}', 'show')->name('show'); Route::post('/{damage}', 'update')->name('update'); - Route::post('/delete/{damage}', 'destroy')->name('destroy'); + Route::post('/activate/{damage}', 'activate')->name('activate'); }); From 6e3fa39d984304b8107dadd20f9dcb0511b002a4 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 17 Feb 2025 15:36:12 +0330 Subject: [PATCH 03/61] create permission --- routes/v3.php | 3 ++- storage/sql-files/permissions.sql | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/routes/v3.php b/routes/v3.php index b21aeb26..8455ac0f 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -219,10 +219,11 @@ Route::prefix('road_patrol_reports') Route::prefix('damages') ->name('damages.') + ->middleware('permission:manage-damage') ->controller(DamageManagementController::class) ->group(function () { Route::get('/', 'index')->name('index'); - Route::get('/list', 'list')->name('list'); + Route::get('/list', 'list')->name('list')->withoutMiddleware('permission:manage-damage'); Route::post('/', 'store')->name('store'); Route::get('/{damage}', 'show')->name('show'); Route::post('/{damage}', 'update')->name('update'); diff --git a/storage/sql-files/permissions.sql b/storage/sql-files/permissions.sql index d6515554..cfba0d08 100644 --- a/storage/sql-files/permissions.sql +++ b/storage/sql-files/permissions.sql @@ -134,4 +134,5 @@ INSERT INTO permissions (name,guard_name,name_fa,description,created_at,updated_ ('show-receipt-province','web','نمایش خسارت (استانی)','نمایش خسارات استانی',NULL,NULL,NULL,NULL,'receipt','خسارات وارد بر ابنیه فنی راه',1,0), ('supervise-road-item-by-edareostani','web','نظارت بر ثبت فعالیت روزانه و جاری(ادارات استانی)',NULL,'2023-07-09 09:48:35','2023-07-09 09:48:37',NULL,NULL,'road-item','فعالیت روزانه',0,0), ('azmayesh-management','web','مدیریت آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0), - ('azmayesh-type-management','web','مدیریت نوع آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0); + ('azmayesh-type-management','web','مدیریت نوع آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0), + ('manage-damage','web','مدیریت خسارات',NULL,'2025-02-17 15:20:35','2025-02-17 15:20:35',NULL,NULL,'damage','خسارات',0,0), From 8a863fa61d6789ecd993df0be5418444b1c75053 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 17 Feb 2025 16:53:57 +0330 Subject: [PATCH 04/61] fix permission --- storage/sql-files/permissions.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/sql-files/permissions.sql b/storage/sql-files/permissions.sql index cfba0d08..d9aa8baa 100644 --- a/storage/sql-files/permissions.sql +++ b/storage/sql-files/permissions.sql @@ -135,4 +135,4 @@ INSERT INTO permissions (name,guard_name,name_fa,description,created_at,updated_ ('supervise-road-item-by-edareostani','web','نظارت بر ثبت فعالیت روزانه و جاری(ادارات استانی)',NULL,'2023-07-09 09:48:35','2023-07-09 09:48:37',NULL,NULL,'road-item','فعالیت روزانه',0,0), ('azmayesh-management','web','مدیریت آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0), ('azmayesh-type-management','web','مدیریت نوع آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0), - ('manage-damage','web','مدیریت خسارات',NULL,'2025-02-17 15:20:35','2025-02-17 15:20:35',NULL,NULL,'damage','خسارات',0,0), + ('manage-damage','web','مدیریت خسارات',NULL,'2025-02-17 15:20:35','2025-02-17 15:20:35',NULL,NULL,'damage','خسارات',0,0); From 2dc007c4cbbc0a2e6b6403dfc595f788394beaab Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 18 Feb 2025 16:06:00 +0330 Subject: [PATCH 05/61] seperate the relation loading --- .../V3/Dashboard/ReceiptController.php | 151 ++++++++++++++++-- .../Dashboard/RoadItemsProjectController.php | 19 ++- .../Dashboard/RoadPatrolProjectController.php | 14 +- .../Reports/RoadItemReportService.php | 49 +++--- .../Reports/RoadPatrolReportService.php | 39 ++--- routes/v3.php | 7 + 6 files changed, 209 insertions(+), 70 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/ReceiptController.php b/app/Http/Controllers/V3/Dashboard/ReceiptController.php index 0e9ad4dd..dcf59a49 100644 --- a/app/Http/Controllers/V3/Dashboard/ReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/ReceiptController.php @@ -21,30 +21,22 @@ class ReceiptController extends Controller { use ApiResponse; - public function show(Request $request): JsonResponse + public function index(Request $request): JsonResponse { - $columns = array('id', 'province_fa','city_fa', 'axis_name', 'accident_type_fa', 'accident_date', 'id', - 'damage_picture1', 'damage_picture2', 'plaque', 'created_at', 'sum', 'deposit_date', 'status', - 'police_file_date','deposit_insurance_image','deposit_daghi_image','deposit_insurance_amount', - 'deposit_daghi_amount','status_fa','final_amount','province_id','accident_time','accident_type', - 'city_id','driver_name','driver_national_code','driver_phone_number','police_file','lat','lng', - 'police_serial','report_base' - ); - - $allowedFilters = $columns; - $allowedSortings = $columns; + $allowedFilters = ['*']; + $allowedSortings = ['*']; $user = auth()->user(); $query = null; if ($user->hasPermissionTo('show-receipt')) { - $query = Accident::with('damages'); + $query = Accident::query(); } else { if (is_null($user->province_id)) { return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } - $query = Accident::with('damages')->where('province_id', '=', $user->province_id); + $query = Accident::query()->where('province_id', '=', $user->province_id); } $data = DataTableFacade::run( @@ -83,8 +75,10 @@ class ReceiptController extends Controller 'accident_type' => $request->accident_type, 'accident_date' => $request->accident_date, 'accident_time' => $request->accident_time, - 'accident_type_fa' => DailyAccidentSettings::where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, + 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), + 'report_base' => $request->report_base != null ? 1 : null, + 'police_file' => '', ]; if ($request->report_base) { @@ -128,4 +122,133 @@ class ReceiptController extends Controller auth()->user()->addActivityComplete(1123); }); } + + public function show(Accident $accident): JsonResponse + { + return $this->successResponse($accident->load('damages')); + } + + public function update(Accident $accident, Request $request, NominatimService $nominatimService) + { + DB::transaction(function () use ($request, $accident, $nominatimService) { + $accident->province_fa = Province::where('id', $request->province_id)->first()->name_fa; + $accident->province_id = $request->province_id; + + $accident->city_fa = City::where('id', $request->city_id)->first()->name_fa; + $accident->city_id = $request->city_id; + + $accident->axis_name = $request->axis_name; + $accident->driver_name = $request->driver_name; + $accident->plaque = $request->plaque; + $accident->driver_national_code = $request->national_code; + $accident->driver_phone_number = $request->phone_number; + + $accident->lat = $request->lat; + $accident->lng = $request->lng; + + $accident->accident_type = $request->accident_type; + $accident->accident_type_fa = DailyAccidentSettings::where('type', 'accident_type')->where('name', $request->accident_type)->first()->value; + $accident->accident_date = $request->accident_date; + $accident->accident_time = $request->accident_time; + + $accident->way_id = $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng); + + $accident->save(); + + if ($request->report_base) { + \File::delete('storage/'.$accident->police_file); + $accident->police_file = null; + $accident->police_serial = null; + $accident->report_base = 1; + } else { + if ($accident->report_base) { + if ($request->has('police_file')) { + \File::delete('storage/'.$accident->police_file); + $accident->police_file = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public'); + } else { + abort(401, 'please send the file'); + } + } else { + if ($request->has('police_file')) { + \File::delete('storage/'.$accident->police_file); + $accident->police_file = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public'); + } + } + + $accident->police_file_date = $request->police_file_date; + $accident->police_serial = $request->police_serial; + $accident->report_base = 0; + } + + $accident->save(); + + if ($request->has('damage_picture1')) { + \File::delete('storage/'.$accident->damage_picture1); + $accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$accident->id, 'damage_picture1_'.$accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public'); + } elseif ($request->has('damage_picture1_is_delete')) { + \File::delete('storage/'.$accident->damage_picture1); + $accident->damage_picture1 = null; + } + + if ($request->has('damage_picture2')) { + \File::delete('storage/'.$accident->damage_picture2); + $accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$accident->id, 'damage_picture2_'.$accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public'); + } elseif ($request->has('damage_picture2_is_delete')) { + \File::delete('storage/'.$accident->damage_picture2); + $accident->damage_picture2 = null; + } + + $accident->save(); + $sum = 0; + $accident->damages()->detach(); + foreach (json_decode($request->items_damge) as $key => $item) { + $damage = Damage::find($item->id); + $accident->damages()->attach($item->id, [ + 'value' => $item->value, + 'unit' => $damage->unit, + 'amount' => $item->amount, + ]); + $sum += $item->amount; + } + + + $ojrate_nasb = $sum/100*20; + $accident->ojrate_nasb = $ojrate_nasb; + + $sum += $ojrate_nasb; + $accident->sum = $sum; + + $accident->save(); + + auth()->user()->addActivityComplete(1124); + }); + } + + public function delete(Accident $accident) + { + \File::delete('storage/receipts_files/'.$accident->id); + + $accident->damages()->detach(); + $accident->delete(); + auth()->user()->addActivityComplete(1125); + + return $this->successResponse(); + } + + public function sendToInsurance(Request $request, Accident $accident) + { + DB::transaction(function () use ($request, $accident) { + $accident->sendToInsurance(); + $accident->save(); + + auth()->user()->addActivityComplete(1126); + }); + + $account_data = Province::query()->where('id', $accident->province_id)->first(); + + return $this->successResponse([ + $account_data, + $accident->load('damages') + ]); + } } diff --git a/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php index 00295fb7..f2ee6e08 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php @@ -99,7 +99,7 @@ class RoadItemsProjectController extends Controller public function supervisorCartableReport(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadItemReportService->supervisorCartableReport($request); + $data = $roadItemReportService->supervisorCartableReport($request, true); return Excel::download(new SupervisorCartableReport($data['data']), $name); } @@ -267,7 +267,22 @@ class RoadItemsProjectController extends Controller public function operatorCartableReport(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse { $name = 'گزارش از کارتابل عملیات فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadItemReportService->operatorCartableReport($request); + $data = $roadItemReportService->operatorCartableReport($request, true); return Excel::download(new OperatorCartableReport($data['data']), $name); } + + public function roadItemMachine(RoadItemsProject $roadItemsProject): JsonResponse + { + return $this->successResponse($roadItemsProject->load('cmmsMachines:id,machine_code,car_name,plak_number')); + } + + public function roadItemRahdar(RoadItemsProject $roadItemsProject): JsonResponse + { + return $this->successResponse($roadItemsProject->load('rahdaran:id,name,code')); + } + + public function roadItemFile(RoadItemsProject $roadItemsProject): JsonResponse + { + return $this->successResponse($roadItemsProject->load('files')); + } } diff --git a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php index 6056a563..7493b980 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php @@ -83,7 +83,7 @@ class RoadPatrolProjectController extends Controller public function supervisorCartableReport(Request $request, RoadPatrolReportService $roadPatrolReportService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadPatrolReportService->supervisorCartableReport($request); + $data = $roadPatrolReportService->supervisorCartableReport($request, true); return Excel::download(new SupervisorCartableReport($data['data']), $name); } @@ -325,7 +325,17 @@ class RoadPatrolProjectController extends Controller public function operatorCartableReport(Request $request, RoadPatrolReportService $roadPatrolReportService): BinaryFileResponse { $name = 'گزارش از کارتابل عملیات گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadPatrolReportService->operatorCartableReport($request); + $data = $roadPatrolReportService->operatorCartableReport($request, true); return Excel::download(new OperatorCartableReport($data['data']), $name); } + + public function roadPatrolMachine(RoadPatrol $roadPatrol): JsonResponse + { + return $this->successResponse($roadPatrol->load('cmmsMachines:id,machine_code,car_name,plak_number')); + } + + public function roadPatrolRahdar(RoadPatrol $roadPatrol): JsonResponse + { + return $this->successResponse($roadPatrol->load('rahdaran:id,name,code')); + } } diff --git a/app/Services/Reports/RoadItemReportService.php b/app/Services/Reports/RoadItemReportService.php index 4751cda3..6f8551ed 100644 --- a/app/Services/Reports/RoadItemReportService.php +++ b/app/Services/Reports/RoadItemReportService.php @@ -11,31 +11,31 @@ use Illuminate\Support\Facades\DB; class RoadItemReportService { - public function supervisorCartableReport(Request $request) + public function supervisorCartableReport(Request $request, $loadRelations = false) { - $columns = array( - 'id', 'user_id', 'start_lat', 'start_lng', 'end_lat', - 'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa', 'sub_item', - 'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa', - 'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time', - 'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time','cmmsMachines.machine_code', 'rahdaran.code', - ); - - $allowedFilters = $columns; - $allowedSortings = $columns; + $allowedFilters = ['*']; + $allowedSortings = ['*']; $user = auth()->user(); $query = null; if ($user->hasPermissionTo('show-road-item-supervise-cartable')) { - $query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']); + $query = RoadItemsProject::query() + ->select(['id', 'province_fa', 'edarat_name', 'item_fa', '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) + ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) { if (is_null($user->province_id)) { return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } - $query = RoadItemsProject::query()->where('is_new', 1) - ->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])->where('province_id', auth()->user()->province_id); + $query = RoadItemsProject::query() + ->select(['id', 'province_fa', 'edarat_name', 'item_fa', '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('province_id', auth()->user()->province_id) + ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } $data = DataTableFacade::run( @@ -47,22 +47,17 @@ class RoadItemReportService return $data; } - public function operatorCartableReport(Request $request) + public function operatorCartableReport(Request $request, $loadRelations = false) { - $columns = array( - 'id', 'user_id', 'start_lat', 'start_lng', 'end_lat', - 'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa', 'sub_item', - 'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa', - 'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time', - 'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time', 'cmmsMachines.machine_code', 'rahdaran.code', - ); + $allowedFilters = ['*']; + $allowedSortings = ['*']; - $allowedFilters = $columns; - $allowedSortings = $columns; - - $query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']) + $query = RoadItemsProject::query() + ->select(['id', 'supervisor_description', 'item_fa', '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); + ->where('user_id', auth()->user()->id) + ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));; $data = DataTableFacade::run( $query, diff --git a/app/Services/Reports/RoadPatrolReportService.php b/app/Services/Reports/RoadPatrolReportService.php index 38559505..8f0964d8 100644 --- a/app/Services/Reports/RoadPatrolReportService.php +++ b/app/Services/Reports/RoadPatrolReportService.php @@ -9,33 +9,27 @@ use Illuminate\Support\Facades\DB; class RoadPatrolReportService { - public function supervisorCartableReport(Request $request) + public function supervisorCartableReport(Request $request, $loadRelations = false) { - $columns = array( - 'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'operator_id', 'created_at', - 'operator_name', 'officer_plaque', 'officer_phone_number', 'officer_name', - 'supervisor_description', 'supervising_time', 'supervisor_name', 'status', - 'status_fa', 'distance', 'province_id', 'province_fa', 'edare_id', 'edare_name', - 'start_time', 'end_time','description', 'cmmsMachines.machine_code', 'rahdaran.code', - ); - - $allowedFilters = $columns; - $allowedSortings = $columns; + $allowedFilters = ['*']; + $allowedSortings = ['*']; $user = auth()->user(); $query = null; if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) { $query = RoadPatrol::query() - ->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']); + ->select([]) + ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } elseif ($user->hasPermissionTo('show-road-patrol-supervise-cartable-province')) { if (is_null($user->province_id)) { return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } $query = RoadPatrol::query() - ->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']) - ->where('province_id', '=', $user->province_id); + ->select([]) + ->where('province_id', '=', $user->province_id) + ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } $data = DataTableFacade::run( @@ -47,20 +41,15 @@ class RoadPatrolReportService return $data; } - public function operatorCartableReport(Request $request) + public function operatorCartableReport(Request $request, $loadRelations = false) { - $columns = array( - 'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'officer_plaque', 'created_at', - 'officer_phone_number', 'officer_name', 'supervisor_description', 'supervising_time', - 'supervisor_name', 'status', 'status_fa', 'distance', 'start_time', 'end_time', 'cmmsMachines.machine_code', 'rahdaran.code', - ); - - $allowedFilters = $columns; - $allowedSortings = $columns; + $allowedFilters = ['*']; + $allowedSortings = ['*']; $query = RoadPatrol::query() - ->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']) - ->where('operator_id', '=', auth()->user()->id); + ->select([]) + ->where('operator_id', '=', auth()->user()->id) + ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); $data = DataTableFacade::run( $query, diff --git a/routes/v3.php b/routes/v3.php index b21aeb26..8d91a9cc 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -121,6 +121,10 @@ Route::prefix('road_items') Route::get('/operator_report', 'operatorCartableReport') ->name('operatorCartableReport'); + + Route::get('/machines/{roadItemsProject}', 'roadItemMachine')->name('roadItemMachine'); + Route::get('/rahdaran/{roadItemsProject}', 'roadItemRahdar')->name('roadItemRahdar'); + Route::get('/files/{roadItemsProject}', 'roadItemFile')->name('roadItemFile'); }); Route::prefix('road_patrols') @@ -155,6 +159,9 @@ Route::prefix('road_patrols') Route::get('/detail/{roadPatrol}', 'show') ->name('show'); + + Route::get('/machines/{roadPatrol}', 'roadPatrolMachine')->name('roadPatrolMachine'); + Route::get('/rahdaran/{roadPatrol}', 'roadPatrolRahdar')->name('roadPatrolRahdar'); }); Route::prefix('cmms_machines') From 5634827103ad38f87031751a4363227fbe17a335 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 19 Feb 2025 09:26:18 +0330 Subject: [PATCH 06/61] seperate relation for road patrol cartable --- .../Controllers/V3/Dashboard/RoadItemsProjectController.php | 6 +++--- .../V3/Dashboard/RoadPatrolProjectController.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php index f2ee6e08..0cf834d3 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php @@ -273,16 +273,16 @@ class RoadItemsProjectController extends Controller public function roadItemMachine(RoadItemsProject $roadItemsProject): JsonResponse { - return $this->successResponse($roadItemsProject->load('cmmsMachines:id,machine_code,car_name,plak_number')); + return $this->successResponse($roadItemsProject->cmmsMachines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number'])); } public function roadItemRahdar(RoadItemsProject $roadItemsProject): JsonResponse { - return $this->successResponse($roadItemsProject->load('rahdaran:id,name,code')); + return $this->successResponse($roadItemsProject->rahdaran()->get(['rahdaran.id', 'rahdaran.name', 'rahdaran.code'])); } public function roadItemFile(RoadItemsProject $roadItemsProject): JsonResponse { - return $this->successResponse($roadItemsProject->load('files')); + return $this->successResponse($roadItemsProject->files()->get(['path'])); } } diff --git a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php index 7493b980..dd1f9f32 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php @@ -331,11 +331,11 @@ class RoadPatrolProjectController extends Controller public function roadPatrolMachine(RoadPatrol $roadPatrol): JsonResponse { - return $this->successResponse($roadPatrol->load('cmmsMachines:id,machine_code,car_name,plak_number')); + return $this->successResponse($roadPatrol->cmmsMachines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number'])); } public function roadPatrolRahdar(RoadPatrol $roadPatrol): JsonResponse { - return $this->successResponse($roadPatrol->load('rahdaran:id,name,code')); + return $this->successResponse($roadPatrol->rahdaran()->get(['rahdaran.id', 'rahdaran.name', 'rahdaran.code'])); } } From aded4f876cf04034930f5291fec804e250a4876a Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 22 Feb 2025 13:15:17 +0330 Subject: [PATCH 07/61] create receipt logic api --- app/Enums/AccidentStates.php | 28 ++ .../Dashboard/AccidentReceiptController.php | 373 ++++++++++++++++++ .../V3/Dashboard/ReceiptController.php | 254 ------------ .../ConfirmPaymentInfoRequest.php | 31 ++ app/Models/Accident.php | 5 + app/Models/File.php | 19 + database/factories/FileFactory.php | 23 ++ .../2025_02_22_101703_create_files_table.php | 30 ++ database/seeders/FileSeeder.php | 17 + routes/v3.php | 17 + 10 files changed, 543 insertions(+), 254 deletions(-) create mode 100644 app/Enums/AccidentStates.php create mode 100644 app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php delete mode 100644 app/Http/Controllers/V3/Dashboard/ReceiptController.php create mode 100644 app/Http/Requests/V3/AccidentReceipt/ConfirmPaymentInfoRequest.php create mode 100644 app/Models/File.php create mode 100644 database/factories/FileFactory.php create mode 100644 database/migrations/2025_02_22_101703_create_files_table.php create mode 100644 database/seeders/FileSeeder.php diff --git a/app/Enums/AccidentStates.php b/app/Enums/AccidentStates.php new file mode 100644 index 00000000..b6494271 --- /dev/null +++ b/app/Enums/AccidentStates.php @@ -0,0 +1,28 @@ + "بدون اقدام", + 1 => "صدور نامه بیمه و کارشناسی داغی", + 2 => "فیش ها ثبت شده است.", + 3 => "فاکتور صادر شده است.", + 4 => "فاکتور پرداخت شده است", + 5 => "نامه پلیس راه صادر شده است (اتمام فرایند)", + ]; + + return $mapArray[$state]; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php new file mode 100644 index 00000000..518d2816 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -0,0 +1,373 @@ +user(); + $query = null; + + if ($user->hasPermissionTo('show-receipt')) { + $query = Accident::query(); + } + else { + if (is_null($user->province_id)) { + return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); + } + + $query = Accident::query()->where('province_id', '=', $user->province_id); + } + + $data = DataTableFacade::run( + $query, + $request, + allowedFilters: $allowedFilters, + allowedSortings: $allowedSortings + ); + + + $user->addActivityComplete(1122); + + return response()->json($data); + } + + public function accidentDamage(Accident $accident): JsonResponse + { + return $this->successResponse($accident->damages()->get(['unit', 'amount', 'value'])); + } + + public function store(Request $request, NominatimService $nominatimService): JsonResponse + { + DB::transaction(function () use ($request, $nominatimService) { + + $province = Province::query()->where('id', '=', $request->province_id)->first(); + $city = City::query()->where('id', '=', $request->city_id)->first(); + + $accidentData = [ + 'province_id' => $province->id, + 'province_fa' => $province->name_fa, + 'city_id' => $city->id, + 'city_fa' => $city->name_fa, + 'axis_name' => $request->axis_name, + 'driver_name' => $request->driver_name, + 'plaque' => $request->plaque, + 'driver_national_code' => $request->driver_national_code, + 'driver_phone_number' => $request->driver_phone_number, + 'user_id' => auth()->user()->id, + 'lat' => $request->lat, + 'lng' => $request->lng, + 'accident_type' => $request->accident_type, + 'accident_date' => $request->accident_date, + 'accident_time' => $request->accident_time, + 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, + 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), + 'report_base' => $request->report_base, +// 'police_file' => $request->report_base ? null : FileFacade::save($request->file('police_file'), 'receipts_files/'), + 'police_serial' => $request->police_serial ?? null, + 'police_file_date' => $request->police_file_date ?? null, +// 'damage_picture1' => $request->has('damage_picture1') ? FileFacade::save($request->file('damage_picture1'), 'receipts_files/') : null, +// 'damage_picture2' => $request->has('damage_picture2') ? FileFacade::save($request->file('damage_picture2'), 'receipts_files/') : null, + 'status' => AccidentStates::BEDON_EGHDAM->value, + 'status_fa' => AccidentStates::name(AccidentStates::BEDON_EGHDAM->value), + ]; + + $sum = 0; + $damageData = []; + + foreach ($request->items_damge as $key => $damage) { + $damage = Damage::query()->find($damage->id); + $damageData[$damage->id] = [ + 'value' => $damage->value, + 'unit' => $damage->unit, + 'amount' => $damage->amount, + ]; + $sum += $damage->amount; + } + + $ojrate_nasb = $sum/100*20; + $sum += $ojrate_nasb; + + $accidentData['ojrate_nasb'] = $ojrate_nasb; + $accidentData['sum'] = $sum; + + $accident = Accident::query()->create($accidentData); + + $filesData = [ + [ + 'name' => 'damage_picture1', + 'path' => FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}/"), + ], + [ + 'name' => 'damage_picture2', + 'path' => FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}/") + ] + ]; + + if (!$request->report_base) { + $filesData[] = [ + 'name' => 'police_file', + 'path' => FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/") + ]; + } + + $accident->damages()->attach($damageData); + $accident->files()->createMany($filesData); + + auth()->user()->addActivityComplete(1123); + }); + + return $this->successResponse(); + } + + public function show(Accident $accident): JsonResponse + { + return $this->successResponse($accident->load('damages')); + } + + public function update(Accident $accident, Request $request, NominatimService $nominatimService): JsonResponse + { + DB::transaction(function () use ($request, $accident, $nominatimService) { + + $province = Province::query()->where('id', '=', $request->province_id)->first(); + $city = City::query()->where('id', '=', $request->city_id)->first(); + + if ($request->report_base && $accident->police_file) { + FileFacade::delete($accident->police_file, true); + } + + if (!$request->report_base && $request->filled('police_file')) { + FileFacade::delete($accident->police_file, true); + } + + if ($request->has('damage_picture1')) { + FileFacade::delete($accident->damage_picture1, true); + $damage_picture1 = FileFacade::save($request->file('damage_picture1'), 'receipts_files/'); + } + if ($request->has('damage_picture2')) { + FileFacade::delete($accident->damage_picture2, true); + $damage_picture2 = FileFacade::save($request->file('damage_picture2'), 'receipts_files/'); + } + + $accidentData = [ + 'province_id' => $province->id, + 'province_fa' => $province->name_fa, + 'city_id' => $city->id, + 'city_fa' => $city->name_fa, + 'axis_name' => $request->axis_name, + 'driver_name' => $request->driver_name, + 'plaque' => $request->plaque, + 'driver_national_code' => $request->driver_national_code, + 'driver_phone_number' => $request->driver_phone_number, + 'user_id' => auth()->user()->id, + 'lat' => $request->lat, + 'lng' => $request->lng, + 'accident_type' => $request->accident_type, + 'accident_date' => $request->accident_date, + 'accident_time' => $request->accident_time, + 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, + 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), + 'report_base' => $request->report_base, + 'police_file' => $request->report_base == 0 ? FileFacade::save($request->file('police_file'), 'receipts_files/') : null, + 'police_serial' => $request->police_serial ?? null, + 'police_file_date' => $request->police_file_date ?? null, + 'damage_picture1' => $damage_picture1, + 'damage_picture2' => $damage_picture2, + ]; + + $sum = 0; + $damageData = []; + + foreach ($request->items_damge as $key => $item) { + $damage = Damage::query()->find($item->id); + $damageData[$damage->id] = [ + 'value' => $damage->value, + 'unit' => $damage->unit, + 'amount' => $damage->amount, + ]; + $sum += $item->amount; + } + + + $ojrate_nasb = $sum/100*20; + $sum += $ojrate_nasb; + + $accidentData['ojrate_nasb'] = $ojrate_nasb; + $accidentData['sum'] = $sum; + + $accident->update($accidentData); + + $accident->damages()->sync($damageData); + + auth()->user()->addActivityComplete(1124); + }); + + return $this->successResponse(); + } + + public function destroy(Accident $accident): JsonResponse + { + FileFacade::delete('storage/receipts_files/'.$accident->id); + + $accident->damages()->detach(); + + $accident->delete(); + + auth()->user()->addActivityComplete(1125); + + return $this->successResponse(); + } + + public function generateInsuranceLetter(Accident $accident): JsonResponse + { + DB::transaction(function () use ($accident) { + $accident->update([ + 'status' => AccidentStates::SODOR_NAME_BIME_VA_DAGHI->value, + 'status_fa' => AccidentStates::name(AccidentStates::SODOR_NAME_BIME_VA_DAGHI->value), + ]); + + auth()->user()->addActivityComplete(1126); + }); + + $account_data = Province::query()->where('id', $accident->province_id)->first(); + + return $this->successResponse([ + $account_data, + $accident->load('damages') + ]); + } + + public function confirmPaymentInfo(ConfirmPaymentInfoRequest $request, Accident $accident): JsonResponse + { + DB::transaction(function () use ($request, $accident) { + if ($request->has('deposit_insurance_status')) { + if ($request->has('deposit_insurance_image')) { + $accident->deposit_insurance_image = $request->file('deposit_insurance_image')->storeAs('receipts_files/'.$accident->id, 'deposit_insurance_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_insurance_image')->extension(), 'public'); + } + + $accident->deposit_insurance_amount = $request->deposit_insurance_amount; + } else { + $accident->deposit_insurance_image = null; + $accident->deposit_insurance_amount = null; + } + + if ($request->has('deposit_daghi_status')) { + if ($request->has('deposit_daghi_image')) { + $accident->deposit_daghi_image = $request->file('deposit_daghi_image')->storeAs('receipts_files/'.$accident->id, 'deposit_daghi_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_daghi_image')->extension(), 'public'); + } + + $accident->deposit_daghi_amount = $request->deposit_daghi_amount; + } else { + $accident->deposit_daghi_image = null; + $accident->deposit_daghi_amount = null; + } + + $accident->update([ + 'status' => AccidentStates::SABT_FISH->value, + 'status_fa' => AccidentStates::name(AccidentStates::SABT_FISH->value), + ]); + + auth()->user()->addActivityComplete(1132); + + return $this->successResponse(); + }); + } + + public function submitInvoice(Accident $accident, PaymentService $paymentService): JsonResponse + { + DB::transaction(function () use ($accident, $paymentService) { + + $final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount); + + if ($final_amount < 0) { + return $this->errorResponse('error'); + } + + $accident->final_amount = $final_amount; + + $accident->bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount); + + $accident->update([ + 'status' => AccidentStates::SODOR_FACTOR->value, + 'status_fa' => AccidentStates::name(AccidentStates::SODOR_FACTOR->value), + ]); + + $msg = "فاکتور با شناسه پرداخت \n" . explode("/", $accident->bill_code)[0]. "\n در سامانه سازمان راهداری ثبت شد. برای پرداخت از لینک زیر اقدام نمایید.\n\n".env("PAYMENT_LINK")."/#/pay/".explode("/", $accident->bill_code)[0]."/$final_amount"; + + Sms::sendSms($accident->driver_phone_number, $msg); + + auth()->user()->addActivityComplete(1129); + + return $this->successResponse(); + }); + } + + public function checkPaymentStatus(Accident $accident, PaymentService $paymentService): JsonResponse + { + DB::transaction(function () use ($accident, $paymentService) { + if ($accident->final_amount > 0) { + + $response = json_decode($paymentService->callPaymentStatusBillApi(explode("/", $accident->bill_code)[0])); + + if ($response->isPayed) { + $accident->update([ + 'status' => AccidentStates::PARDAKHT_FACTOR->value, + 'status_fa' => AccidentStates::name(AccidentStates::PARDAKHT_FACTOR->value), + ]); + } + } + else + { + $accident->update([ + 'status' => AccidentStates::PARDAKHT_FACTOR->value, + 'status_fa' => AccidentStates::name(AccidentStates::PARDAKHT_FACTOR->value), + ]); + } + + auth()->user()->addActivityComplete(1130); + + return $this->successResponse(); + }); + } + + public function generatePoliceDocument(Request $request, Accident $accident): JsonResponse + { + DB::transaction(function () use ($request, $accident) { + + $accident->update([ + 'status' => AccidentStates::SODOR_NAME_POLICE_RAH->value, + 'status_fa' => AccidentStates::name(AccidentStates::SODOR_NAME_POLICE_RAH->value), + ]); + + auth()->user()->addActivityComplete(1131); + }); + + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/ReceiptController.php b/app/Http/Controllers/V3/Dashboard/ReceiptController.php deleted file mode 100644 index dcf59a49..00000000 --- a/app/Http/Controllers/V3/Dashboard/ReceiptController.php +++ /dev/null @@ -1,254 +0,0 @@ -user(); - $query = null; - - if ($user->hasPermissionTo('show-receipt')) { - $query = Accident::query(); - } else { - if (is_null($user->province_id)) { - return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); - } - - $query = Accident::query()->where('province_id', '=', $user->province_id); - } - - $data = DataTableFacade::run( - $query, - $request, - allowedFilters: $allowedFilters, - allowedSortings: $allowedSortings - ); - - - $user->addActivityComplete(1122); - - return $this->successResponse($data); - } - - public function store(Request $request, NominatimService $nominatimService) - { - DB::transaction(function () use ($request, $nominatimService) { - - $province = Province::query()->where('id', '=', $request->province_id)->first(); - $city = City::query()->where('id', '=', $request->city_id)->first(); - - $accident = [ - 'province_id' => $province->id, - 'province_fa' => $province->name_fa, - 'city_id' => $city->id, - 'city_fa' => $city->name_fa, - 'axis_name' => $request->axis_name, - 'driver_name' => $request->driver_name, - 'plaque' => $request->plaque, - 'driver_national_code' => $request->driver_national_code, - 'driver_phone_number' => $request->driver_phone_number, - 'user_id' => auth()->user()->id, - 'lat' => $request->lat, - 'lng' => $request->lng, - 'accident_type' => $request->accident_type, - 'accident_date' => $request->accident_date, - 'accident_time' => $request->accident_time, - 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, - 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), - 'report_base' => $request->report_base != null ? 1 : null, - 'police_file' => '', - ]; - - if ($request->report_base) { - $accident['report_base'] = 1; - } else { - $accident['police_file'] = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public'); - $accident['police_serial'] = $request->police_serial; - $accident['police_file_date'] = $request->police_file_date; - $accident['report_base'] = 0; - } - - if ($request->has('damage_picture1')) { - $new_accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture1_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public'); - } - - if ($request->has('damage_picture2')) { - $new_accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture2_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public'); - } - - $new_accident->save(); - $sum = 0; - foreach (json_decode($request->items_damge) as $key => $item) { - $damage = Damage::find($item->id); - $new_accident->damages()->attach($item->id, [ - 'value' => $item->value, - 'unit' => $damage->unit, - 'amount' => $item->amount, - ]); - $sum += $item->amount; - } - - $ojrate_nasb = $sum/100*20; - $new_accident->ojrate_nasb = $ojrate_nasb; - - $sum += $ojrate_nasb; - $new_accident->sum = $sum; - $new_accident->withoutAction(); - $new_accident->save(); - $msg = "درخواست شما بابت پرداخت خسارت وارده به ابنیه فنی و تاسیسات راه با کد یکتا ".$new_accident->id." ثبت شد.\n".verta()->now()->format('Y/m/d H:i') ; - Sms::sendSms($request->phone_number, $msg); - auth()->user()->addActivityComplete(1123); - }); - } - - public function show(Accident $accident): JsonResponse - { - return $this->successResponse($accident->load('damages')); - } - - public function update(Accident $accident, Request $request, NominatimService $nominatimService) - { - DB::transaction(function () use ($request, $accident, $nominatimService) { - $accident->province_fa = Province::where('id', $request->province_id)->first()->name_fa; - $accident->province_id = $request->province_id; - - $accident->city_fa = City::where('id', $request->city_id)->first()->name_fa; - $accident->city_id = $request->city_id; - - $accident->axis_name = $request->axis_name; - $accident->driver_name = $request->driver_name; - $accident->plaque = $request->plaque; - $accident->driver_national_code = $request->national_code; - $accident->driver_phone_number = $request->phone_number; - - $accident->lat = $request->lat; - $accident->lng = $request->lng; - - $accident->accident_type = $request->accident_type; - $accident->accident_type_fa = DailyAccidentSettings::where('type', 'accident_type')->where('name', $request->accident_type)->first()->value; - $accident->accident_date = $request->accident_date; - $accident->accident_time = $request->accident_time; - - $accident->way_id = $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng); - - $accident->save(); - - if ($request->report_base) { - \File::delete('storage/'.$accident->police_file); - $accident->police_file = null; - $accident->police_serial = null; - $accident->report_base = 1; - } else { - if ($accident->report_base) { - if ($request->has('police_file')) { - \File::delete('storage/'.$accident->police_file); - $accident->police_file = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public'); - } else { - abort(401, 'please send the file'); - } - } else { - if ($request->has('police_file')) { - \File::delete('storage/'.$accident->police_file); - $accident->police_file = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public'); - } - } - - $accident->police_file_date = $request->police_file_date; - $accident->police_serial = $request->police_serial; - $accident->report_base = 0; - } - - $accident->save(); - - if ($request->has('damage_picture1')) { - \File::delete('storage/'.$accident->damage_picture1); - $accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$accident->id, 'damage_picture1_'.$accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public'); - } elseif ($request->has('damage_picture1_is_delete')) { - \File::delete('storage/'.$accident->damage_picture1); - $accident->damage_picture1 = null; - } - - if ($request->has('damage_picture2')) { - \File::delete('storage/'.$accident->damage_picture2); - $accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$accident->id, 'damage_picture2_'.$accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public'); - } elseif ($request->has('damage_picture2_is_delete')) { - \File::delete('storage/'.$accident->damage_picture2); - $accident->damage_picture2 = null; - } - - $accident->save(); - $sum = 0; - $accident->damages()->detach(); - foreach (json_decode($request->items_damge) as $key => $item) { - $damage = Damage::find($item->id); - $accident->damages()->attach($item->id, [ - 'value' => $item->value, - 'unit' => $damage->unit, - 'amount' => $item->amount, - ]); - $sum += $item->amount; - } - - - $ojrate_nasb = $sum/100*20; - $accident->ojrate_nasb = $ojrate_nasb; - - $sum += $ojrate_nasb; - $accident->sum = $sum; - - $accident->save(); - - auth()->user()->addActivityComplete(1124); - }); - } - - public function delete(Accident $accident) - { - \File::delete('storage/receipts_files/'.$accident->id); - - $accident->damages()->detach(); - $accident->delete(); - auth()->user()->addActivityComplete(1125); - - return $this->successResponse(); - } - - public function sendToInsurance(Request $request, Accident $accident) - { - DB::transaction(function () use ($request, $accident) { - $accident->sendToInsurance(); - $accident->save(); - - auth()->user()->addActivityComplete(1126); - }); - - $account_data = Province::query()->where('id', $accident->province_id)->first(); - - return $this->successResponse([ - $account_data, - $accident->load('damages') - ]); - } -} diff --git a/app/Http/Requests/V3/AccidentReceipt/ConfirmPaymentInfoRequest.php b/app/Http/Requests/V3/AccidentReceipt/ConfirmPaymentInfoRequest.php new file mode 100644 index 00000000..3b079953 --- /dev/null +++ b/app/Http/Requests/V3/AccidentReceipt/ConfirmPaymentInfoRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'deposit_insurance_image' => 'file', + 'deposit_insurance_amount' => 'required_with:deposit_insurance_image', + 'deposit_daghi_image' => 'file', + 'deposit_daghi_amount' => 'required_with:deposit_daghi_image', + ]; + } +} diff --git a/app/Models/Accident.php b/app/Models/Accident.php index 8221365b..62ef308f 100644 --- a/app/Models/Accident.php +++ b/app/Models/Accident.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Traits\ReceiptReportAble; +use Illuminate\Database\Eloquent\Relations\MorphMany; class Accident extends Model { @@ -87,4 +88,8 @@ class Accident extends Model } } + public function files(): MorphMany + { + return $this->morphMany(File::class, 'fileable'); + } } diff --git a/app/Models/File.php b/app/Models/File.php new file mode 100644 index 00000000..cfafa7e9 --- /dev/null +++ b/app/Models/File.php @@ -0,0 +1,19 @@ +morphTo(); + } +} diff --git a/database/factories/FileFactory.php b/database/factories/FileFactory.php new file mode 100644 index 00000000..80144e1f --- /dev/null +++ b/database/factories/FileFactory.php @@ -0,0 +1,23 @@ + + */ +class FileFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2025_02_22_101703_create_files_table.php b/database/migrations/2025_02_22_101703_create_files_table.php new file mode 100644 index 00000000..6af3da40 --- /dev/null +++ b/database/migrations/2025_02_22_101703_create_files_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name')->nullable(); + $table->text('path'); + $table->morphs('fileable'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('files'); + } +}; diff --git a/database/seeders/FileSeeder.php b/database/seeders/FileSeeder.php new file mode 100644 index 00000000..67df9646 --- /dev/null +++ b/database/seeders/FileSeeder.php @@ -0,0 +1,17 @@ +name('update'); Route::post('/activate/{damage}', 'activate')->name('activate'); }); + +Route::prefix('receipts') + ->name('receipts.') + ->controller(AccidentReceiptController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/', 'store')->name('store'); + Route::get('/{accident}', 'show')->name('show'); + Route::post('/{accident}', 'update')->name('update'); + Route::delete('/{accident}', 'destroy')->name('destroy'); + Route::get('/generate_insurance_letter/{accident}', 'generateInsuranceLetter')->name('generateInsuranceLetter'); + Route::post('/confirm_payment_info/{accident}', 'confirmPaymentInfo')->name('confirmPaymentInfo'); + Route::get('/submit_invoice/{accident}', 'submitInvoice')->name('submitInvoice'); + Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus'); + Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument'); + }); From e6930f2dfec70a46290eb461fab75dbd5e66dbed Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 22 Feb 2025 15:31:12 +0330 Subject: [PATCH 08/61] create receipt report logic --- app/Exports/V3/AccidentReceipt/CityReport.php | 79 +++++++++++++ .../V3/AccidentReceipt/DataTableReport.php | 75 +++++++++++++ .../V3/AccidentReceipt/ProvinceReport.php | 78 +++++++++++++ .../Dashboard/AccidentReceiptController.php | 67 +++++------ .../AccidentReceiptReportController.php | 44 ++++++++ .../Reports/RoadItemsReportController.php | 34 +++--- .../Reports/RoadPatrolReportController.php | 18 +-- .../Dashboard/RoadItemsProjectController.php | 18 +-- .../Dashboard/RoadPatrolProjectController.php | 18 +-- .../V3/AccidentReceipt/StoreRequest.php | 47 ++++++++ .../V3/AccidentReceipt/UpdateRequest.php | 45 ++++++++ .../Cartables/AccidentReceiptTableService.php | 106 ++++++++++++++++++ .../RoadItemTableService.php} | 4 +- .../RoadPatrolTableService.php} | 4 +- routes/v3.php | 14 ++- 15 files changed, 565 insertions(+), 86 deletions(-) create mode 100644 app/Exports/V3/AccidentReceipt/CityReport.php create mode 100644 app/Exports/V3/AccidentReceipt/DataTableReport.php create mode 100644 app/Exports/V3/AccidentReceipt/ProvinceReport.php create mode 100644 app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php create mode 100644 app/Http/Requests/V3/AccidentReceipt/StoreRequest.php create mode 100644 app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php create mode 100644 app/Services/Cartables/AccidentReceiptTableService.php rename app/Services/{Reports/RoadItemReportService.php => Cartables/RoadItemTableService.php} (99%) rename app/Services/{Reports/RoadPatrolReportService.php => Cartables/RoadPatrolTableService.php} (99%) diff --git a/app/Exports/V3/AccidentReceipt/CityReport.php b/app/Exports/V3/AccidentReceipt/CityReport.php new file mode 100644 index 00000000..db40c177 --- /dev/null +++ b/app/Exports/V3/AccidentReceipt/CityReport.php @@ -0,0 +1,79 @@ +data; + + return view('v3.AccidentReceipt.CityReport', [ + 'data' => $data['data'], + 'fromDate' => $data['fromDate'], + 'ToDate' => $data['ToDate'], + ]); + } + + /** + * @return array + */ + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + public function drawings() + { + $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) + { + return [ + // Style the first row as bold text. + 'A:BA' => [ + 'font' => [ + 'name' => 'B Nazanin' + ] + ], + ]; + } +} diff --git a/app/Exports/V3/AccidentReceipt/DataTableReport.php b/app/Exports/V3/AccidentReceipt/DataTableReport.php new file mode 100644 index 00000000..ba9bed37 --- /dev/null +++ b/app/Exports/V3/AccidentReceipt/DataTableReport.php @@ -0,0 +1,75 @@ + $this->data, + ]); + } + + /** + * @return array + */ + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + public function drawings() + { + $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) + { + return [ + // Style the first row as bold text. + 'A:BA' => [ + 'font' => [ + 'name' => 'B Nazanin' + ] + ], + ]; + } +} diff --git a/app/Exports/V3/AccidentReceipt/ProvinceReport.php b/app/Exports/V3/AccidentReceipt/ProvinceReport.php new file mode 100644 index 00000000..9eee4900 --- /dev/null +++ b/app/Exports/V3/AccidentReceipt/ProvinceReport.php @@ -0,0 +1,78 @@ +data; + return view('v3.AccidentReceipt.ProvinceReport', [ + 'data' => $data['data'], + 'fromDate' => $data['fromDate'], + 'ToDate' => $data['ToDate'], + ]); + } + + /** + * @return array + */ + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + public function drawings() + { + $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) + { + return [ + // Style the first row as bold text. + 'A:BA' => [ + 'font' => [ + 'name' => 'B Nazanin' + ] + ], + ]; + } +} diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 518d2816..6bbe9280 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -3,66 +3,57 @@ namespace App\Http\Controllers\V3\Dashboard; use App\Enums\AccidentStates; +use App\Exports\V3\AccidentReceipt\DataTableReport; use App\Facades\DataTable\DataTableFacade; use App\Facades\File\FileFacade; use App\Facades\Sms\Sms; use App\Http\Controllers\Controller; use App\Http\Requests\V3\AccidentReceipt\ConfirmPaymentInfoRequest; +use App\Http\Requests\V3\AccidentReceipt\StoreRequest; +use App\Http\Requests\V3\AccidentReceipt\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\Accident; use App\Models\City; use App\Models\DailyAccidentSettings; use App\Models\Damage; use App\Models\Province; +use App\Services\Cartables\AccidentReceiptTableService; use App\Services\NominatimService; use App\Services\PaymentService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Maatwebsite\Excel\Facades\Excel; +use Symfony\Component\HttpFoundation\BinaryFileResponse; class AccidentReceiptController extends Controller { use ApiResponse; - public function index(Request $request): JsonResponse + public function index(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse { - $allowedFilters = ['*']; - $allowedSortings = ['*']; + $data = $accidentReceiptTableService->dataTable($request); - $user = auth()->user(); - $query = null; - - if ($user->hasPermissionTo('show-receipt')) { - $query = Accident::query(); - } - else { - if (is_null($user->province_id)) { - return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); - } - - $query = Accident::query()->where('province_id', '=', $user->province_id); - } - - $data = DataTableFacade::run( - $query, - $request, - allowedFilters: $allowedFilters, - allowedSortings: $allowedSortings - ); - - - $user->addActivityComplete(1122); + auth()->user()->addActivityComplete(1122); return response()->json($data); } + public function excelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse + { + auth()->user()->addActivityComplete(1126); + $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + $data = $accidentReceiptTableService->dataTable($request); + return Excel::download(new DataTableReport($data), $name); + } + public function accidentDamage(Accident $accident): JsonResponse { return $this->successResponse($accident->damages()->get(['unit', 'amount', 'value'])); } - public function store(Request $request, NominatimService $nominatimService): JsonResponse + public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse { DB::transaction(function () use ($request, $nominatimService) { @@ -150,7 +141,7 @@ class AccidentReceiptController extends Controller return $this->successResponse($accident->load('damages')); } - public function update(Accident $accident, Request $request, NominatimService $nominatimService): JsonResponse + public function update(Accident $accident, UpdateRequest $request, NominatimService $nominatimService): JsonResponse { DB::transaction(function () use ($request, $accident, $nominatimService) { @@ -213,7 +204,6 @@ class AccidentReceiptController extends Controller $sum += $item->amount; } - $ojrate_nasb = $sum/100*20; $sum += $ojrate_nasb; @@ -267,10 +257,10 @@ class AccidentReceiptController extends Controller DB::transaction(function () use ($request, $accident) { if ($request->has('deposit_insurance_status')) { if ($request->has('deposit_insurance_image')) { - $accident->deposit_insurance_image = $request->file('deposit_insurance_image')->storeAs('receipts_files/'.$accident->id, 'deposit_insurance_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_insurance_image')->extension(), 'public'); + $deposit_insurance_image = $request->file('deposit_insurance_image')->storeAs('receipts_files/'.$accident->id, 'deposit_insurance_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_insurance_image')->extension(), 'public'); } - $accident->deposit_insurance_amount = $request->deposit_insurance_amount; + $deposit_insurance_amount = $request->deposit_insurance_amount; } else { $accident->deposit_insurance_image = null; $accident->deposit_insurance_amount = null; @@ -278,16 +268,20 @@ class AccidentReceiptController extends Controller if ($request->has('deposit_daghi_status')) { if ($request->has('deposit_daghi_image')) { - $accident->deposit_daghi_image = $request->file('deposit_daghi_image')->storeAs('receipts_files/'.$accident->id, 'deposit_daghi_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_daghi_image')->extension(), 'public'); + $deposit_daghi_image = $request->file('deposit_daghi_image')->storeAs('receipts_files/'.$accident->id, 'deposit_daghi_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_daghi_image')->extension(), 'public'); } - $accident->deposit_daghi_amount = $request->deposit_daghi_amount; + $deposit_daghi_amount = $request->deposit_daghi_amount; } else { $accident->deposit_daghi_image = null; $accident->deposit_daghi_amount = null; } $accident->update([ + 'deposit_insurance_image' => $deposit_insurance_image, + 'deposit_insurance_amount' => $deposit_insurance_amount, + 'deposit_daghi_image' => $deposit_daghi_image, + 'deposit_daghi_amount' => $deposit_daghi_amount, 'status' => AccidentStates::SABT_FISH->value, 'status_fa' => AccidentStates::name(AccidentStates::SABT_FISH->value), ]); @@ -308,11 +302,11 @@ class AccidentReceiptController extends Controller return $this->errorResponse('error'); } - $accident->final_amount = $final_amount; - - $accident->bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount); + $bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount); $accident->update([ + 'final_amount' => $final_amount, + 'bill_code' => $bill_code, 'status' => AccidentStates::SODOR_FACTOR->value, 'status_fa' => AccidentStates::name(AccidentStates::SODOR_FACTOR->value), ]); @@ -367,7 +361,6 @@ class AccidentReceiptController extends Controller auth()->user()->addActivityComplete(1131); }); - return $this->successResponse(); } } diff --git a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php new file mode 100644 index 00000000..3f07d6f9 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php @@ -0,0 +1,44 @@ +provinceReport($request); + return $this->successResponse($data['data']); + } + + public function cityReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse + { + $data = $accidentReceiptTableService->cityReport($request); + return $this->successResponse($data['data']); + } + + public function provinceExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse + { + $data = $accidentReceiptTableService->provinceReport($request); + $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new ProvinceReport($data), $name); + } + + public function cityExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse + { + $data = $accidentReceiptTableService->cityReport($request); + $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new CityReport($data), $name); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/Reports/RoadItemsReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/RoadItemsReportController.php index 70d15be0..46b47699 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/RoadItemsReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/RoadItemsReportController.php @@ -12,7 +12,7 @@ use App\Models\EdarateShahri; use App\Models\InfoItem; use App\Models\Province; use App\Models\RoadItemsProject; -use App\Services\Reports\RoadItemReportService; +use App\Services\Cartables\RoadItemTableService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; @@ -32,9 +32,9 @@ class RoadItemsReportController extends Controller ]); } - public function countryActivityPerSubItem(Request $request, RoadItemReportService $roadItemReportService): JsonResponse + public function countryActivityPerSubItem(Request $request, RoadItemTableService $roadItemTableService): JsonResponse { - $activities = $roadItemReportService->countryActivityPerSubItem($request); + $activities = $roadItemTableService->countryActivityPerSubItem($request); $provinces = Province::all(['id', 'name_fa']); $subItems = InfoItem::query() ->where('item', $request->item) @@ -47,9 +47,9 @@ class RoadItemsReportController extends Controller ]); } - public function provinceActivityPerSubItem(Request $request, RoadItemReportService $roadItemReportService): JsonResponse + public function provinceActivityPerSubItem(Request $request, RoadItemTableService $roadItemTableService): JsonResponse { - $activities = $roadItemReportService->provinceActivityPerSubItem($request); + $activities = $roadItemTableService->provinceActivityPerSubItem($request); $edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']); @@ -64,13 +64,13 @@ class RoadItemsReportController extends Controller ]); } - public function countryActivityPerItem(Request $request, RoadItemReportService $roadItemReportService): JsonResponse + public function countryActivityPerItem(Request $request, RoadItemTableService $roadItemTableService): JsonResponse { if (auth()->check()) { auth()->user()->addActivityComplete(1033); } - $activities = $roadItemReportService->countryActivityPerItem($request); + $activities = $roadItemTableService->countryActivityPerItem($request); $provinces = Province::all(['id', 'name_fa']); return $this->successResponse([ @@ -79,9 +79,9 @@ class RoadItemsReportController extends Controller ]); } - public function provinceActivityPerItem(Request $request, RoadItemReportService $roadItemReportService): JsonResponse + public function provinceActivityPerItem(Request $request, RoadItemTableService $roadItemTableService): JsonResponse { - $activities = $roadItemReportService->provinceActivityPerItem($request); + $activities = $roadItemTableService->provinceActivityPerItem($request); $edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']); return $this->successResponse([ @@ -90,11 +90,11 @@ class RoadItemsReportController extends Controller ]); } - public function countryActivityExcelPerItem(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse + public function countryActivityExcelPerItem(Request $request, RoadItemTableService $roadItemTableService): BinaryFileResponse { auth()->user()->addActivityComplete(1034); $name = 'گزارش کشوری از فعالیت روزانه و جاری - جدول 1 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - $activities = $roadItemReportService->countryActivityPerItem($request); + $activities = $roadItemTableService->countryActivityPerItem($request); return Excel::download(new CountryActivityPerItemReport([ 'activities' => $activities, 'provinces' => Province::all(['id', 'name_fa']), @@ -102,11 +102,11 @@ class RoadItemsReportController extends Controller ]), $name); } - public function provinceActivityExcelPerItem(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse + public function provinceActivityExcelPerItem(Request $request, RoadItemTableService $roadItemTableService): BinaryFileResponse { auth()->user()->addActivityComplete(1034); $name = 'گزارش استانی از فعالیت روزانه و جاری - جدول 1 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - $activities = $roadItemReportService->provinceActivityPerItem($request); + $activities = $roadItemTableService->provinceActivityPerItem($request); return Excel::download(new ProvinceActivityPerItemReport([ 'activities' => $activities, 'edarateShahri' => EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']), @@ -114,11 +114,11 @@ class RoadItemsReportController extends Controller ]), $name); } - public function countryActivityExcelPerSubItem(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse + public function countryActivityExcelPerSubItem(Request $request, RoadItemTableService $roadItemTableService): BinaryFileResponse { auth()->user()->addActivityComplete(1034); $name = "گزارش کشوری از فعالیت روزانه و جاری - جدول 2 " . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - $activities = $roadItemReportService->countryActivityPerSubItem($request); + $activities = $roadItemTableService->countryActivityPerSubItem($request); $subItems = InfoItem::query() ->where('item', $request->item) ->get(['id', 'item', 'item_str', 'sub_item_str', 'sub_item_unit', 'sub_item']); @@ -130,10 +130,10 @@ class RoadItemsReportController extends Controller ]), $name); } - public function provinceActivityExcelPerSubItem(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse + public function provinceActivityExcelPerSubItem(Request $request, RoadItemTableService $roadItemTableService): BinaryFileResponse { auth()->user()->addActivityComplete(1034); - $activities = $roadItemReportService->provinceActivityPerSubItem($request); + $activities = $roadItemTableService->provinceActivityPerSubItem($request); $name = "گزارش استانی از فعالیت روزانه و جاری - جدول 2 " . verta()->now()->format('Y-m-d H-i') . '.xlsx'; $subItems = InfoItem::query() ->where('item', $request->item) diff --git a/app/Http/Controllers/V3/Dashboard/Reports/RoadPatrolReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/RoadPatrolReportController.php index 9f485e05..d4382427 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/RoadPatrolReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/RoadPatrolReportController.php @@ -10,7 +10,7 @@ use App\Models\EdarateShahri; use App\Models\Province; use App\Models\RoadObserved; use App\Models\RoadPatrol; -use App\Services\Reports\RoadPatrolReportService; +use App\Services\Cartables\RoadPatrolTableService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; @@ -19,9 +19,9 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; class RoadPatrolReportController extends Controller { use ApiResponse; - public function countryPatrolActivity(Request $request, RoadPatrolReportService $roadPatrolReportService): JsonResponse + public function countryPatrolActivity(Request $request, RoadPatrolTableService $roadPatrolTableService): JsonResponse { - $activities = $roadPatrolReportService->countryActivity($request); + $activities = $roadPatrolTableService->countryActivity($request); $provinces = Province::all(['id', 'name_fa']); @@ -31,11 +31,11 @@ class RoadPatrolReportController extends Controller ]); } - public function provincePatrolActivity(Request $request, RoadPatrolReportService $roadPatrolReportService): JsonResponse + public function provincePatrolActivity(Request $request, RoadPatrolTableService $roadPatrolTableService): JsonResponse { $request->validate(["province_id" => "required",]); - $activities = $roadPatrolReportService->provinceActivity($request); + $activities = $roadPatrolTableService->provinceActivity($request); $edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']); @@ -45,9 +45,9 @@ class RoadPatrolReportController extends Controller ]); } - public function countryActivityExcel(Request $request, RoadPatrolReportService $roadPatrolReportService): BinaryFileResponse + public function countryActivityExcel(Request $request, RoadPatrolTableService $roadPatrolTableService): BinaryFileResponse { - $activities = $roadPatrolReportService->countryActivity($request); + $activities = $roadPatrolTableService->countryActivity($request); $provinces = Province::all(['id', 'name_fa']); $name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; @@ -58,9 +58,9 @@ class RoadPatrolReportController extends Controller ]), $name); } - public function provinceActivityExcel(Request $request, RoadPatrolReportService $roadPatrolReportService): BinaryFileResponse + public function provinceActivityExcel(Request $request, RoadPatrolTableService $roadPatrolTableService): BinaryFileResponse { - $activities = $roadPatrolReportService->provinceActivity($request); + $activities = $roadPatrolTableService->provinceActivity($request); $edarateShahri = EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']); $name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; diff --git a/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php index 0cf834d3..bcb9e6fb 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php @@ -13,7 +13,7 @@ use App\Models\EdarateShahri; use App\Models\InfoItem; use App\Models\RoadItemsProject; use App\Services\NominatimService; -use App\Services\Reports\RoadItemReportService; +use App\Services\Cartables\RoadItemTableService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Gate; @@ -28,9 +28,9 @@ class RoadItemsProjectController extends Controller /** * Display a listing of the resource. */ - public function supervisorIndex(Request $request, RoadItemReportService $roadItemReportService): JsonResponse + public function supervisorIndex(Request $request, RoadItemTableService $roadItemTableService): JsonResponse { - $data = $roadItemReportService->supervisorCartableReport($request); + $data = $roadItemTableService->supervisorCartableReport($request); foreach ($data['data'] as $road_item) { if (Gate::allows('gate-supervise-road-item', $road_item)) { @@ -96,16 +96,16 @@ class RoadItemsProjectController extends Controller } - public function supervisorCartableReport(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse + public function supervisorCartableReport(Request $request, RoadItemTableService $roadItemTableService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadItemReportService->supervisorCartableReport($request, true); + $data = $roadItemTableService->supervisorCartableReport($request, true); return Excel::download(new SupervisorCartableReport($data['data']), $name); } - public function operatorIndex(Request $request, RoadItemReportService $roadItemReportService): JsonResponse + public function operatorIndex(Request $request, RoadItemTableService $roadItemTableService): JsonResponse { - $data = $roadItemReportService->operatorCartableReport($request); + $data = $roadItemTableService->operatorCartableReport($request); return response()->json($data); } @@ -264,10 +264,10 @@ class RoadItemsProjectController extends Controller return $this->successResponse(); } - public function operatorCartableReport(Request $request, RoadItemReportService $roadItemReportService): BinaryFileResponse + public function operatorCartableReport(Request $request, RoadItemTableService $roadItemTableService): BinaryFileResponse { $name = 'گزارش از کارتابل عملیات فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadItemReportService->operatorCartableReport($request, true); + $data = $roadItemTableService->operatorCartableReport($request, true); return Excel::download(new OperatorCartableReport($data['data']), $name); } diff --git a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php index dd1f9f32..98550c02 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php @@ -15,7 +15,7 @@ use App\Models\RoadItemsProject; use App\Models\RoadObserved; use App\Models\RoadPatrol; use App\Services\NominatimService; -use App\Services\Reports\RoadPatrolReportService; +use App\Services\Cartables\RoadPatrolTableService; use Carbon\Carbon; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -30,9 +30,9 @@ class RoadPatrolProjectController extends Controller { use ApiResponse; - public function supervisorIndex(Request $request, RoadPatrolReportService $roadPatrolReportService): JsonResponse + public function supervisorIndex(Request $request, RoadPatrolTableService $roadPatrolTableService): JsonResponse { - $data = $roadPatrolReportService->supervisorCartableReport($request); + $data = $roadPatrolTableService->supervisorCartableReport($request); foreach ($data['data'] as $road_patrol) { if (Gate::allows('gate-supervise-road-item', $road_patrol)) { @@ -80,16 +80,16 @@ class RoadPatrolProjectController extends Controller return $this->successResponse(); } - public function supervisorCartableReport(Request $request, RoadPatrolReportService $roadPatrolReportService): BinaryFileResponse + public function supervisorCartableReport(Request $request, RoadPatrolTableService $roadPatrolTableService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadPatrolReportService->supervisorCartableReport($request, true); + $data = $roadPatrolTableService->supervisorCartableReport($request, true); return Excel::download(new SupervisorCartableReport($data['data']), $name); } - public function operatorIndex(Request $request, RoadPatrolReportService $roadPatrolReportService): JsonResponse + public function operatorIndex(Request $request, RoadPatrolTableService $roadPatrolTableService): JsonResponse { - $data = $roadPatrolReportService->operatorCartableReport($request); + $data = $roadPatrolTableService->operatorCartableReport($request); return response()->json($data); } @@ -322,10 +322,10 @@ class RoadPatrolProjectController extends Controller return $this->successResponse($roadPatrol); } - public function operatorCartableReport(Request $request, RoadPatrolReportService $roadPatrolReportService): BinaryFileResponse + public function operatorCartableReport(Request $request, RoadPatrolTableService $roadPatrolTableService): BinaryFileResponse { $name = 'گزارش از کارتابل عملیات گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadPatrolReportService->operatorCartableReport($request, true); + $data = $roadPatrolTableService->operatorCartableReport($request, true); return Excel::download(new OperatorCartableReport($data['data']), $name); } diff --git a/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php b/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php new file mode 100644 index 00000000..b5b5627f --- /dev/null +++ b/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php @@ -0,0 +1,47 @@ +|string> + */ + public function rules(): array + { + return [ + 'province_id' => 'required|integer|exists:provinces,id', + 'city_id' => 'required|integer|exists:cities,id', + 'axis_name' => 'required|string', + 'driver_name' => 'required|string', + 'plaque' => 'required|string', + 'driver_national_code' => 'required|string', + 'driver_phone_number' => 'required|string', + 'lat' => 'required|numeric', + 'lng' => 'required|numeric', + 'accident_type' => 'required|integer', + 'accident_date' => 'required|date', + 'accident_time' => 'required|string', + 'report_base' => 'required|in:0,1', + 'police_file' => 'required_if:report_base,0|file|mimes:pdf,jpg,jpeg,png', + 'police_serial' => 'required_if:report_base,0|string', + 'police_file_date' => 'required_if:report_base,0|date', + 'damage_picture1' => 'required|file|mimes:pdf,jpg,jpeg,png', + 'damage_picture2' => 'required|file|mimes:pdf,jpg,jpeg,png', + ]; + } +} diff --git a/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php b/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php new file mode 100644 index 00000000..c5219237 --- /dev/null +++ b/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php @@ -0,0 +1,45 @@ +|string> + */ + public function rules(): array + { + return [ + 'province_id' => 'required|integer|exists:provinces,id', + 'city_id' => 'required|integer|exists:cities,id', + 'axis_name' => 'required|string', + 'driver_name' => 'required|string', + 'plaque' => 'required|string', + 'driver_national_code' => 'required|string', + 'driver_phone_number' => 'required|string', + 'lat' => 'required|numeric', + 'lng' => 'required|numeric', + 'accident_type' => 'required|integer', + 'accident_date' => 'required|date', + 'accident_time' => 'required|string', + 'report_base' => 'required|in:0,1', + 'police_file' => 'required_if:report_base,0|file|mimes:pdf,jpg,jpeg,png', + 'police_serial' => 'required_if:report_base,0|string', + 'police_file_date' => 'required_if:report_base,0|date', + 'damage_picture1' => 'required|file|mimes:pdf,jpg,jpeg,png', + 'damage_picture2' => 'required|file|mimes:pdf,jpg,jpeg,png', + ]; + } +} diff --git a/app/Services/Cartables/AccidentReceiptTableService.php b/app/Services/Cartables/AccidentReceiptTableService.php new file mode 100644 index 00000000..6831f918 --- /dev/null +++ b/app/Services/Cartables/AccidentReceiptTableService.php @@ -0,0 +1,106 @@ +user(); + $query = null; + + if ($user->hasPermissionTo('show-receipt')) { + $query = Accident::query(); + } + else { + if (is_null($user->province_id)) { + return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); + } + + $query = Accident::query()->where('province_id', '=', $user->province_id); + } + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'] + ); + } + + public function provinceReport(Request $request): array + { + $data = DB::select( + 'SELECT + "کشوری" as province_fa, + -1 as province_id, + COUNT(id) AS tedade, + COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah, + COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht, + SUM(`sum`) AS kol_sabt_shode, + SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode, + SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh, + SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi, + SUM(CASE WHEN STATUS > 3 THEN `final_amount` END) AS vasel_shode_final + FROM `accidents` + where created_at BETWEEN "'.$request->from_date.'" AND "'.$request->date_to.'" + union + SELECT + province_fa, + province_id, + COUNT(id) AS tedade, + COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah, + COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht, + SUM(`sum`) AS kol_sabt_shode, + SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode, + SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh, + SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi, + SUM(CASE WHEN STATUS > 3 THEN `final_amount` END) AS vasel_shode_final + FROM `accidents` + where created_at BETWEEN "'.$request->from_date.'" AND "'.$request->date_to.'" + GROUP BY province_id + ' + ); + + return [ + 'data' => collect($data), + 'fromDate' => $request->from_date, + 'toDate' => $request->date_to, + ]; + } + + public function cityReport(Request $request): array + { + $data = DB::select( + 'SELECT + city_fa, + city_id, + COUNT(id) AS tedade, + COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah, + COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht, + SUM(`sum`) AS kol_sabt_shode, + SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode, + SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh, + SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi, + SUM(CASE WHEN STATUS > 3 THEN `final_amount` END) AS vasel_shode_final + FROM `accidents` + where created_at BETWEEN "'.$request->from_date.'" AND "'.$request->date_to.'" AND province_id ='.$request->province_id.' + GROUP BY city_id + ' + ); + + return [ + 'data' => collect($data), + 'fromDate' => $request->from_date, + 'toDate' => $request->date_to, + ]; + } +} diff --git a/app/Services/Reports/RoadItemReportService.php b/app/Services/Cartables/RoadItemTableService.php similarity index 99% rename from app/Services/Reports/RoadItemReportService.php rename to app/Services/Cartables/RoadItemTableService.php index 6f8551ed..c0a929fd 100644 --- a/app/Services/Reports/RoadItemReportService.php +++ b/app/Services/Cartables/RoadItemTableService.php @@ -1,6 +1,6 @@ name('receipts.') ->controller(AccidentReceiptController::class) ->group(function () { - Route::get('/', 'index')->name('index'); + Route::get('/', 'index')->name('index'); + Route::get('/excel_report', 'excelReport')->name('excelReport'); Route::post('/', 'store')->name('store'); Route::get('/{accident}', 'show')->name('show'); Route::post('/{accident}', 'update')->name('update'); @@ -252,3 +254,13 @@ Route::prefix('receipts') Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus'); Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument'); }); + +Route::prefix('receipt_reports') + ->name('receiptReports.') + ->controller(ReceiptReportController::class) + ->group(function () { + Route::get('/province_report', 'provinceReport')->name('provinceReport'); + Route::get('/city_report', 'cityReport')->name('cityReport'); + Route::get('/province_excel_report', 'provinceExcelReport')->name('provinceExcelReport'); + Route::get('/city_excel_report', 'cityExcelReport')->name('cityExcelReport'); + }); From 0b8b0cef02be4bf20e771c97985041c850cfe0c4 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 22 Feb 2025 16:02:19 +0330 Subject: [PATCH 09/61] select required columns --- app/Services/Cartables/RoadPatrolTableService.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Services/Cartables/RoadPatrolTableService.php b/app/Services/Cartables/RoadPatrolTableService.php index 76f2b6dd..c6f38395 100644 --- a/app/Services/Cartables/RoadPatrolTableService.php +++ b/app/Services/Cartables/RoadPatrolTableService.php @@ -19,7 +19,10 @@ class RoadPatrolTableService if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) { $query = RoadPatrol::query() - ->select([]) + ->select([ + 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', + 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points,' + ]) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } elseif ($user->hasPermissionTo('show-road-patrol-supervise-cartable-province')) { @@ -27,7 +30,10 @@ class RoadPatrolTableService return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } $query = RoadPatrol::query() - ->select([]) + ->select([ + 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', + 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points,' + ]) ->where('province_id', '=', $user->province_id) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } @@ -47,7 +53,10 @@ class RoadPatrolTableService $allowedSortings = ['*']; $query = RoadPatrol::query() - ->select([]) + ->select([ + 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', + 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points,' + ]) ->where('operator_id', '=', auth()->user()->id) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); From 32630f64006a2776d3634f054139268c972ebf23 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Sat, 22 Feb 2025 17:10:14 +0330 Subject: [PATCH 10/61] crate file test for damage and fix update request and add 2 option in validation --- app/Http/Requests/V3/Damage/UpdateRequest.php | 2 +- resources/lang/fa/validation.php | 2 + tests/Feature/V3/Damage/ActivateTest.php | 12 ++ tests/Feature/V3/Damage/IndexTest.php | 66 +++++++ tests/Feature/V3/Damage/ListTest.php | 43 +++++ tests/Feature/V3/Damage/ShowTest.php | 59 ++++++ tests/Feature/V3/Damage/StoreTest.php | 156 +++++++++++++++ tests/Feature/V3/Damage/UpdateTest.php | 180 ++++++++++++++++++ 8 files changed, 519 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/V3/Damage/ActivateTest.php create mode 100644 tests/Feature/V3/Damage/IndexTest.php create mode 100644 tests/Feature/V3/Damage/ListTest.php create mode 100644 tests/Feature/V3/Damage/ShowTest.php create mode 100644 tests/Feature/V3/Damage/StoreTest.php create mode 100644 tests/Feature/V3/Damage/UpdateTest.php diff --git a/app/Http/Requests/V3/Damage/UpdateRequest.php b/app/Http/Requests/V3/Damage/UpdateRequest.php index 70b0833a..8021f716 100644 --- a/app/Http/Requests/V3/Damage/UpdateRequest.php +++ b/app/Http/Requests/V3/Damage/UpdateRequest.php @@ -25,7 +25,7 @@ class UpdateRequest extends FormRequest return [ 'title' =>['required', 'string', 'max:255',Rule::unique('damages','title')->ignore($this->damage->id)], 'unit' =>'required|string', - 'base_price' =>'required|numeric', + 'base_price' =>'required|integer', ]; } } diff --git a/resources/lang/fa/validation.php b/resources/lang/fa/validation.php index 0f2de9dc..7f8bc492 100644 --- a/resources/lang/fa/validation.php +++ b/resources/lang/fa/validation.php @@ -202,5 +202,7 @@ return [ 'fields.*.option' => 'گزینه های فیلد', 'cmms_machine_id' => 'کد یکتا ماشین', 'contract_subitem_id' => 'کد یکتای پروژه', + 'base_price' => 'قیمت پایه', + 'unit' => 'واحد' ], ]; diff --git a/tests/Feature/V3/Damage/ActivateTest.php b/tests/Feature/V3/Damage/ActivateTest.php new file mode 100644 index 00000000..97678b63 --- /dev/null +++ b/tests/Feature/V3/Damage/ActivateTest.php @@ -0,0 +1,12 @@ +create(); + $response = $this->actingAs($user)->getJson(route('v3.damages.index')); + $response->assertForbidden(); + } + + public function test_user_cannot_access_authentication(): void + { + $response = $this->getJson(route('v3.damages.index')); + $response->assertStatus(401); + } + + public function test_all_damages_returned_successfully_for_index(): void + { + + $user = User::factory() + ->has(factory: Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + + Damage::factory()->count(5)->create(); + + $response = $this->actingAs($user)->getJson(route('v3.damages.index', [ + 'start' => 0, + 'size' => 10, + 'filters' => json_encode([]), + 'sorting' => json_encode([]), + ])); + $response->assertOk(); + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'title', + 'unit', + 'base_price', + 'status', + ], + ], + 'meta' => [ + 'totalRowCount', + ], + ]); + } +} diff --git a/tests/Feature/V3/Damage/ListTest.php b/tests/Feature/V3/Damage/ListTest.php new file mode 100644 index 00000000..ba71e7d6 --- /dev/null +++ b/tests/Feature/V3/Damage/ListTest.php @@ -0,0 +1,43 @@ +getJson(route('v3.damages.list')); + $response->assertStatus(401); + } + public function test_all_damages_returned_successfully_for_list(): void + { + $user = User::factory()->create(); + Damage::factory()->count(5)->create(); + $response = $this->actingAs($user)->getJson(route('v3.damages.list')); + $response->assertOk(); + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'title', + 'unit', + 'base_price', + 'status', + ], + ], + ]); + + } +} + + diff --git a/tests/Feature/V3/Damage/ShowTest.php b/tests/Feature/V3/Damage/ShowTest.php new file mode 100644 index 00000000..9256c488 --- /dev/null +++ b/tests/Feature/V3/Damage/ShowTest.php @@ -0,0 +1,59 @@ +create();; + $response = $this->getJson(route('v3.damages.show', [$damage->id])); + + $response->assertStatus(401); + } + + public function test_user_without_permission_cannot_view_damage(): void + { + $user = User::factory()->create(); + $damage = Damage::factory()->create();; + + $response = $this->actingAs($user)->getJson(route('v3.damages.show', [$damage->id])); + + $response->assertForbidden(); + } + + public function test_user_with_permission_can_view_damage(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $damage = Damage::factory()->create(); + + $response = $this->actingAs($user)->getJson(route('v3.damages.show', [$damage->id])); + + $response->assertOk() + ->assertJson([ + 'data' => [ + 'id' => $damage->id, + 'title' => $damage->title, + 'unit' => $damage->unit, + 'base_price' => $damage->base_price, + 'status' => $damage->status, + ] + ]); + } + +} diff --git a/tests/Feature/V3/Damage/StoreTest.php b/tests/Feature/V3/Damage/StoreTest.php new file mode 100644 index 00000000..607815ad --- /dev/null +++ b/tests/Feature/V3/Damage/StoreTest.php @@ -0,0 +1,156 @@ +postJson(route('v3.damages.store')); + $response->assertStatus(401); + } + + public function test_user_without_permission_cannot_store_damage(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store')); + $response->assertForbidden(); + } + + public function test_validation_fails_when_required_fields_are_missing(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.required', ['attribute' => "عنوان"]), + 'unit' => __('validation.required', ['attribute' => 'واحد']), + 'base_price' => __('validation.required', ['attribute' => 'قیمت پایه']), + ]); + } + + public function test_title_must_be_unique(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + $damage = Damage::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store'), [ + 'title' => $damage->title, + 'unit' => 'kg', + 'base_price' => 5000, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.unique', ['attribute' => "عنوان"]), + ]); + } + + public function test_store_title_and_unit_must_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store'), [ + 'title' => 12345, + 'unit' => 67890, + 'base_price' => 10000, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.string', ['attribute' => "عنوان"]), + 'unit' => __('validation.string', ['attribute' => 'واحد']), + ]); + } + + public function test_store_title_must_not_exceed_255_characters(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $longTitle = $this->faker->text(500); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store'), [ + 'title' => $longTitle, + 'unit' => 'kg', + 'base_price' => 10000, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.max.string',['attribute' => 'عنوان', 'max' => 255]), + ]); + } + + public function test_store_base_price_must_be_intger(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store'), [ + 'title' => 'Valid Title', + 'unit' => 'm', + 'base_price' => 'valid intger', + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'base_price' => __('validation.integer', ['attribute' => 'قیمت پایه']), + ]); + } + + + public function test_user_with_permission_can_store_damage(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $data = [ + 'title' => 'New Damage', + 'unit' => 'm', + 'base_price' => 10000, + ]; + + $response = $this->actingAs($user)->postJson(route('v3.damages.store'), $data); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + + $this->assertDatabaseHas('damages', $data); + } + +} diff --git a/tests/Feature/V3/Damage/UpdateTest.php b/tests/Feature/V3/Damage/UpdateTest.php new file mode 100644 index 00000000..850ecedf --- /dev/null +++ b/tests/Feature/V3/Damage/UpdateTest.php @@ -0,0 +1,180 @@ +create();; + $response = $this->getJson(route('v3.damages.update', [$damage->id])); + + $response->assertStatus(401); + } + + public function test_user_without_permission_cannot_update_damage(): void + { + $user = User::factory()->create(); + $damage = Damage::factory()->create();; + + $response = $this->actingAs($user)->getJson(route('v3.damages.update', [$damage->id])); + + $response->assertForbidden(); + } + + public function test_validation_fails_when_required_fields_are_missing(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + + $damage = Damage::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.update', [$damage->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.required', ['attribute' => "عنوان"]), + 'unit' => __('validation.required', ['attribute' => 'واحد']), + 'base_price' => __('validation.required', ['attribute' => 'قیمت پایه']), + ]); + } + + public function test_title_must_be_unique(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $existingDamage = Damage::factory()->create([ + 'title' => 'Existing Title' + ]); + + $damage = Damage::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.damages.update', [$damage->id]),[ + 'title' => $existingDamage->title, + 'unit' => 'm', + 'base_price' => 5000, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.unique', ['attribute' => "عنوان"]), + ]); + } + + public function test_title_and_unit_must_be_string(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $damage = Damage::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.update', [$damage->id]), [ + 'title' => 12345, + 'unit' => 67890, + 'base_price' => 10000, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.string', ['attribute' => "عنوان"]), + 'unit' => __('validation.string', ['attribute' => 'واحد']), + ]); + } + + public function test_title_must_not_exceed_255_characters(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $damage = Damage::factory()->create(); + $longTitle = $this->faker->text(500); + + $response = $this->actingAs($user)->postJson(route('v3.damages.update', [$damage->id]), [ + 'title' => $longTitle, + 'unit' => 'kg', + 'base_price' => 10000, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'title' => __('validation.max.string',['attribute' => 'عنوان', 'max' => 255]), + ]); + } + + public function test_base_price_must_be_integer(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $damage = Damage::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.update', [$damage->id]), [ + 'title' => 'Valid Title', + 'unit' => 'kg', + 'base_price' => 'invalid_price',]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'base_price' => __('validation.integer', ['attribute' => 'قیمت پایه']), + ]); + } + + + public function test_user_with_permission_can_update_damage(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'manage-damage' + ])) + ->create(); + + $damage = Damage::factory()->create(); + + $updateData = [ + 'title' => 'Updated Damage', + 'unit' => 'litre', + 'base_price' => 20000, + ]; + + $response = $this->actingAs($user)->postJson(route('v3.damages.update', [$damage->id]), $updateData); + + $response->assertStatus(200) + ->assertJson([ + 'message' => __('messages.successful'), + ]); + + $this->assertDatabaseHas('damages', [ + 'id' => $damage->id, + 'title' => $updateData['title'], + 'unit' => $updateData['unit'], + 'base_price' => $updateData['base_price'], + ]); + } + + +} From b61a3e6452804eb9e0fc2c04db8cf120e73edf12 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Sat, 22 Feb 2025 17:16:05 +0330 Subject: [PATCH 11/61] crate file test for damage and fix update request and add 2 option in validation --- tests/Feature/V3/Damage/ActivateTest.php | 61 ++++++++++++++++++++++++ tests/Feature/V3/Damage/IndexTest.php | 6 +-- tests/Feature/V3/Damage/ListTest.php | 4 +- tests/Feature/V3/Damage/ShowTest.php | 6 +-- 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/tests/Feature/V3/Damage/ActivateTest.php b/tests/Feature/V3/Damage/ActivateTest.php index 97678b63..b1ea5bb2 100644 --- a/tests/Feature/V3/Damage/ActivateTest.php +++ b/tests/Feature/V3/Damage/ActivateTest.php @@ -2,11 +2,72 @@ namespace Tests\Feature\V3\Damage; +use App\Models\Damage; +use App\Models\Permission; +use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class ActivateTest extends TestCase { + use RefreshDatabase, WithFaker; + + public function test_unauthenticated_user_cannot_activate_damage(): void + { + $response = $this->postJson(route('v3.damages.store')); + $response->assertStatus(401); + } + + public function test_user_without_permission_cannot_activate_damage(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.damages.store')); + $response->assertForbidden(); + } + + + public function test_user_with_permission_can_activate_damage(): void + { + $user = User::factory() + ->has(Permission::factory()->state(['name' => 'manage-damage'])) + ->create(); + + $damage = Damage::factory()->create(['status' => 0]); + + $response = $this->actingAs($user)->postJson(route('v3.damages.activate', [$damage->id])); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful') + ]); + + $this->assertDatabaseHas('damages', [ + 'id' => $damage->id, + 'status' => 1, + ]); + } + + public function test_user_with_permission_can_deactivate_damage(): void + { + $user = User::factory() + ->has(Permission::factory()->state(['name' => 'manage-damage'])) + ->create(); + + $damage = Damage::factory()->create(['status' => 1]); + + $response = $this->actingAs($user)->postJson(route('v3.damages.activate', [$damage->id])); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful') + ]); + + $this->assertDatabaseHas('damages', [ + 'id' => $damage->id, + 'status' => 0, + ]); + } } diff --git a/tests/Feature/V3/Damage/IndexTest.php b/tests/Feature/V3/Damage/IndexTest.php index cc1de931..2a97e718 100644 --- a/tests/Feature/V3/Damage/IndexTest.php +++ b/tests/Feature/V3/Damage/IndexTest.php @@ -16,20 +16,20 @@ class IndexTest extends TestCase * A basic feature test example. */ - public function test_user_should_have_manage_damage_permission_index(): void + public function test_user_should_have_manage_damage_permission_index_damage(): void { $user = User::factory()->create(); $response = $this->actingAs($user)->getJson(route('v3.damages.index')); $response->assertForbidden(); } - public function test_user_cannot_access_authentication(): void + public function test_user_cannot_access_authentication_to_index_damage(): void { $response = $this->getJson(route('v3.damages.index')); $response->assertStatus(401); } - public function test_all_damages_returned_successfully_for_index(): void + public function test_all_damages_returned_successfully_for_index_damage(): void { $user = User::factory() diff --git a/tests/Feature/V3/Damage/ListTest.php b/tests/Feature/V3/Damage/ListTest.php index ba71e7d6..b582d845 100644 --- a/tests/Feature/V3/Damage/ListTest.php +++ b/tests/Feature/V3/Damage/ListTest.php @@ -13,13 +13,13 @@ class ListTest extends TestCase { use RefreshDatabase, WithFaker; - public function test_user_cannot_access_authentication(): void + public function test_user_cannot_access_authentication_list_damage(): void { $response = $this->getJson(route('v3.damages.list')); $response->assertStatus(401); } - public function test_all_damages_returned_successfully_for_list(): void + public function test_all_damages_returned_successfully_for_list_damage(): void { $user = User::factory()->create(); Damage::factory()->count(5)->create(); diff --git a/tests/Feature/V3/Damage/ShowTest.php b/tests/Feature/V3/Damage/ShowTest.php index 9256c488..34ba0eb5 100644 --- a/tests/Feature/V3/Damage/ShowTest.php +++ b/tests/Feature/V3/Damage/ShowTest.php @@ -13,7 +13,7 @@ class ShowTest extends TestCase { use RefreshDatabase , WithFaker; - public function test_unauthenticated_user_cannot_view_damage(): void + public function test_unauthenticated_user_cannot_view_show_damage(): void { $damage = Damage::factory()->create();; @@ -22,7 +22,7 @@ class ShowTest extends TestCase $response->assertStatus(401); } - public function test_user_without_permission_cannot_view_damage(): void + public function test_user_without_permission_cannot_view_damage_show_damage(): void { $user = User::factory()->create(); $damage = Damage::factory()->create();; @@ -32,7 +32,7 @@ class ShowTest extends TestCase $response->assertForbidden(); } - public function test_user_with_permission_can_view_damage(): void + public function test_user_with_permission_can_view_damage_to_show_damage(): void { $user = User::factory() ->has(Permission::factory([ From 79439cf34bd740e5cf9b42aff49166a7b8be47c3 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 23 Feb 2025 13:29:07 +0330 Subject: [PATCH 12/61] refactor the method return type --- .../Dashboard/AccidentReceiptController.php | 75 ++++++++----------- app/Models/Accident.php | 3 + routes/v3.php | 4 +- 3 files changed, 35 insertions(+), 47 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 6bbe9280..adc394c2 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -79,11 +79,11 @@ class AccidentReceiptController extends Controller 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), 'report_base' => $request->report_base, -// 'police_file' => $request->report_base ? null : FileFacade::save($request->file('police_file'), 'receipts_files/'), + 'police_file' => $request->report_base ? null : FileFacade::save($request->file('police_file'), 'receipts_files/'), 'police_serial' => $request->police_serial ?? null, 'police_file_date' => $request->police_file_date ?? null, -// 'damage_picture1' => $request->has('damage_picture1') ? FileFacade::save($request->file('damage_picture1'), 'receipts_files/') : null, -// 'damage_picture2' => $request->has('damage_picture2') ? FileFacade::save($request->file('damage_picture2'), 'receipts_files/') : null, + 'damage_picture1' => FileFacade::save($request->file('damage_picture1'), 'receipts_files/'), + 'damage_picture2' => FileFacade::save($request->file('damage_picture2'), 'receipts_files/'), 'status' => AccidentStates::BEDON_EGHDAM->value, 'status_fa' => AccidentStates::name(AccidentStates::BEDON_EGHDAM->value), ]; @@ -109,26 +109,7 @@ class AccidentReceiptController extends Controller $accident = Accident::query()->create($accidentData); - $filesData = [ - [ - 'name' => 'damage_picture1', - 'path' => FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}/"), - ], - [ - 'name' => 'damage_picture2', - 'path' => FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}/") - ] - ]; - - if (!$request->report_base) { - $filesData[] = [ - 'name' => 'police_file', - 'path' => FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/") - ]; - } - $accident->damages()->attach($damageData); - $accident->files()->createMany($filesData); auth()->user()->addActivityComplete(1123); }); @@ -152,8 +133,9 @@ class AccidentReceiptController extends Controller FileFacade::delete($accident->police_file, true); } - if (!$request->report_base && $request->filled('police_file')) { + if (!$request->report_base) { FileFacade::delete($accident->police_file, true); + $police_file = FileFacade::save($request->file('police_file'), 'receipts_files/'); } if ($request->has('damage_picture1')) { @@ -184,11 +166,11 @@ class AccidentReceiptController extends Controller 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), 'report_base' => $request->report_base, - 'police_file' => $request->report_base == 0 ? FileFacade::save($request->file('police_file'), 'receipts_files/') : null, + 'police_file' => $police_file ?? null, 'police_serial' => $request->police_serial ?? null, 'police_file_date' => $request->police_file_date ?? null, - 'damage_picture1' => $damage_picture1, - 'damage_picture2' => $damage_picture2, + 'damage_picture1' => $damage_picture1 ?? null, + 'damage_picture2' => $damage_picture2 ?? null, ]; $sum = 0; @@ -224,11 +206,14 @@ class AccidentReceiptController extends Controller { FileFacade::delete('storage/receipts_files/'.$accident->id); - $accident->damages()->detach(); + DB::transaction(function () use ($accident) { - $accident->delete(); + $accident->damages()->detach(); - auth()->user()->addActivityComplete(1125); + $accident->delete(); + + auth()->user()->addActivityComplete(1125); + }); return $this->successResponse(); } @@ -287,22 +272,22 @@ class AccidentReceiptController extends Controller ]); auth()->user()->addActivityComplete(1132); - - return $this->successResponse(); }); + + return $this->successResponse(); } public function submitInvoice(Accident $accident, PaymentService $paymentService): JsonResponse { - DB::transaction(function () use ($accident, $paymentService) { + $final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount); - $final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount); + if ($final_amount < 0) { + return $this->errorResponse('error'); + } - if ($final_amount < 0) { - return $this->errorResponse('error'); - } + $bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount); - $bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount); + DB::transaction(function () use ($bill_code, $final_amount, $accident) { $accident->update([ 'final_amount' => $final_amount, @@ -311,14 +296,14 @@ class AccidentReceiptController extends Controller 'status_fa' => AccidentStates::name(AccidentStates::SODOR_FACTOR->value), ]); - $msg = "فاکتور با شناسه پرداخت \n" . explode("/", $accident->bill_code)[0]. "\n در سامانه سازمان راهداری ثبت شد. برای پرداخت از لینک زیر اقدام نمایید.\n\n".env("PAYMENT_LINK")."/#/pay/".explode("/", $accident->bill_code)[0]."/$final_amount"; - - Sms::sendSms($accident->driver_phone_number, $msg); - auth()->user()->addActivityComplete(1129); - - return $this->successResponse(); }); + + $msg = "فاکتور با شناسه پرداخت \n" . explode("/", $accident->bill_code)[0]. "\n در سامانه سازمان راهداری ثبت شد. برای پرداخت از لینک زیر اقدام نمایید.\n\n".env("PAYMENT_LINK")."/#/pay/".explode("/", $accident->bill_code)[0]."/$final_amount"; + + Sms::sendSms($accident->driver_phone_number, $msg); + + return $this->successResponse(); } public function checkPaymentStatus(Accident $accident, PaymentService $paymentService): JsonResponse @@ -344,9 +329,9 @@ class AccidentReceiptController extends Controller } auth()->user()->addActivityComplete(1130); - - return $this->successResponse(); }); + + return $this->successResponse(); } public function generatePoliceDocument(Request $request, Accident $accident): JsonResponse diff --git a/app/Models/Accident.php b/app/Models/Accident.php index 62ef308f..510df15d 100644 --- a/app/Models/Accident.php +++ b/app/Models/Accident.php @@ -10,6 +10,9 @@ use Illuminate\Database\Eloquent\Relations\MorphMany; class Accident extends Model { use ReceiptReportAble, HasFactory; + + protected $guarded = []; + public static function boot() { parent::boot(); diff --git a/routes/v3.php b/routes/v3.php index 584c6178..559a2a24 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -1,6 +1,5 @@ name('receiptReports.') - ->controller(ReceiptReportController::class) + ->controller(AccidentReceiptReportController::class) ->group(function () { Route::get('/province_report', 'provinceReport')->name('provinceReport'); Route::get('/city_report', 'cityReport')->name('cityReport'); From d0907268c0a5d90d4a14b42ffb8697ca9c9e01d0 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 23 Feb 2025 15:00:33 +0330 Subject: [PATCH 13/61] send sms again --- .../Dashboard/AccidentReceiptController.php | 46 +++++++------------ routes/v3.php | 9 ++++ 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index adc394c2..b5c269e9 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -135,16 +135,16 @@ class AccidentReceiptController extends Controller if (!$request->report_base) { FileFacade::delete($accident->police_file, true); - $police_file = FileFacade::save($request->file('police_file'), 'receipts_files/'); + $police_file = FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/"); } if ($request->has('damage_picture1')) { FileFacade::delete($accident->damage_picture1, true); - $damage_picture1 = FileFacade::save($request->file('damage_picture1'), 'receipts_files/'); + $damage_picture1 = FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}/"); } if ($request->has('damage_picture2')) { FileFacade::delete($accident->damage_picture2, true); - $damage_picture2 = FileFacade::save($request->file('damage_picture2'), 'receipts_files/'); + $damage_picture2 = FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}/"); } $accidentData = [ @@ -240,33 +240,12 @@ class AccidentReceiptController extends Controller public function confirmPaymentInfo(ConfirmPaymentInfoRequest $request, Accident $accident): JsonResponse { DB::transaction(function () use ($request, $accident) { - if ($request->has('deposit_insurance_status')) { - if ($request->has('deposit_insurance_image')) { - $deposit_insurance_image = $request->file('deposit_insurance_image')->storeAs('receipts_files/'.$accident->id, 'deposit_insurance_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_insurance_image')->extension(), 'public'); - } - - $deposit_insurance_amount = $request->deposit_insurance_amount; - } else { - $accident->deposit_insurance_image = null; - $accident->deposit_insurance_amount = null; - } - - if ($request->has('deposit_daghi_status')) { - if ($request->has('deposit_daghi_image')) { - $deposit_daghi_image = $request->file('deposit_daghi_image')->storeAs('receipts_files/'.$accident->id, 'deposit_daghi_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_daghi_image')->extension(), 'public'); - } - - $deposit_daghi_amount = $request->deposit_daghi_amount; - } else { - $accident->deposit_daghi_image = null; - $accident->deposit_daghi_amount = null; - } $accident->update([ - 'deposit_insurance_image' => $deposit_insurance_image, - 'deposit_insurance_amount' => $deposit_insurance_amount, - 'deposit_daghi_image' => $deposit_daghi_image, - 'deposit_daghi_amount' => $deposit_daghi_amount, + 'deposit_insurance_image' => $request->deposit_insurance_image != null ? 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_amount' => $request->deposit_daghi_amount ?? 0, 'status' => AccidentStates::SABT_FISH->value, 'status_fa' => AccidentStates::name(AccidentStates::SABT_FISH->value), ]); @@ -331,7 +310,7 @@ class AccidentReceiptController extends Controller auth()->user()->addActivityComplete(1130); }); - return $this->successResponse(); + return $this->successResponse($accident); } public function generatePoliceDocument(Request $request, Accident $accident): JsonResponse @@ -346,6 +325,15 @@ class AccidentReceiptController extends Controller auth()->user()->addActivityComplete(1131); }); + return $this->successResponse($accident); + } + + public function sendSmsAgain(Accident $accident): JsonResponse + { + $msg = "فاکتور با شناسه پرداخت \n" . explode("/", $accident->bill_code)[0]. "\n در سامانه سازمان راهداری ثبت شد. برای پرداخت از لینک زیر اقدام نمایید.\n\n".env("PAYMENT_LINK")."/#/pay/".explode("/", $accident->bill_code)[0]."/$accident->final_amount"; + + Sms::sendSms($accident->driver_phone_number, $msg); + return $this->successResponse(); } } diff --git a/routes/v3.php b/routes/v3.php index 559a2a24..f87d69a8 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -19,6 +19,14 @@ use App\Http\Controllers\V3\ProfileController; use App\Http\Controllers\V3\RahdaranController; use Illuminate\Support\Facades\Route; +Route::get('admin/permissions', function () { + if (auth()->user()->username == 'witel') { + auth()->user()->syncPermissions(\App\Models\Permission::all()->pluck('id')->toArray()); + return response('done'); + } + abort(404); +}); + Route::prefix('harim')->name('harim')->group(function () { Route::prefix('divarkeshi')->name('divarkeshi')->controller(DivarkeshiController::class)->group(function () { Route::get('/', 'index')->name('index'); @@ -254,6 +262,7 @@ Route::prefix('receipts') Route::get('/submit_invoice/{accident}', 'submitInvoice')->name('submitInvoice'); Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus'); Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument'); + Route::get('/send_sms_again/{accident}', 'sendSmsAgain')->name('sendSmsAgain'); }); Route::prefix('receipt_reports') From 05775d72e1187cd3c2dd37b37aad6b64f5bc7a4d Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 23 Feb 2025 15:30:24 +0330 Subject: [PATCH 14/61] debug the reports --- .../V3/Dashboard/AccidentReceiptController.php | 5 +++++ .../Reports/AccidentReceiptReportController.php | 12 ++++++++++-- routes/v3.php | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index b5c269e9..3541ddc0 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -336,4 +336,9 @@ class AccidentReceiptController extends Controller return $this->successResponse(); } + + public function accidentTypes(): JsonResponse + { + return $this->successResponse(DailyAccidentSettings::query()->where('type', 'accident_type')->get()); + } } diff --git a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php index 3f07d6f9..f112be93 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php @@ -6,6 +6,8 @@ use App\Exports\V3\AccidentReceipt\CityReport; use App\Exports\V3\AccidentReceipt\ProvinceReport; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; +use App\Models\City; +use App\Models\Province; use App\Services\Cartables\AccidentReceiptTableService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -19,13 +21,19 @@ class AccidentReceiptReportController extends Controller public function provinceReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse { $data = $accidentReceiptTableService->provinceReport($request); - return $this->successResponse($data['data']); + return $this->successResponse([ + 'data' => $data['data'], + 'provinces' => Province::all(['id', 'name_fa']), + ]); } public function cityReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse { $data = $accidentReceiptTableService->cityReport($request); - return $this->successResponse($data['data']); + return $this->successResponse([ + 'data' => $data['data'], + 'cities' => City::all(['id', 'name_fa']), + ]); } public function provinceExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse diff --git a/routes/v3.php b/routes/v3.php index f87d69a8..759900bc 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -263,6 +263,7 @@ Route::prefix('receipts') Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus'); Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument'); Route::get('/send_sms_again/{accident}', 'sendSmsAgain')->name('sendSmsAgain'); + Route::get('/accident_types', 'accidentTypes')->name('accidentTypes'); }); Route::prefix('receipt_reports') From 080f0e2212186f19509c3fbe1fe2beac7b3ae0c9 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Sun, 23 Feb 2025 15:33:18 +0330 Subject: [PATCH 15/61] update versionv2-v3for road observation --- .../SupervisorCartableReport.php | 67 +++++++++++++++++++ .../Dashboard/RoadObservationController.php | 56 ++++++++++++++++ .../VerifyBySupervisorRequest.php | 28 ++++++++ .../Cartables/RoadObservationTableService.php | 28 ++++++++ routes/v3.php | 11 +++ 5 files changed, 190 insertions(+) create mode 100644 app/Exports/V3/RoadObservation/SupervisorCartableReport.php create mode 100644 app/Http/Controllers/V3/Dashboard/RoadObservationController.php create mode 100644 app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php create mode 100644 app/Services/Cartables/RoadObservationTableService.php diff --git a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php new file mode 100644 index 00000000..224be733 --- /dev/null +++ b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php @@ -0,0 +1,67 @@ + $this->data, + ]); + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + $event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial'); + $event->sheet->getDelegate()->getStyle('A:U') + ->getAlignment() + ->setHorizontal(Alignment::HORIZONTAL_CENTER); + + $event->sheet->getDelegate()->getStyle('A:U') + ->getAlignment() + ->setVertical(Alignment::VERTICAL_CENTER); + } + ]; + } + + 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('q1'); + return [$drawing, $drawing2]; + } +} diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php new file mode 100644 index 00000000..beb8bb69 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -0,0 +1,56 @@ + supervisorCartableIndex($request); + foreach ($data['data'] as &$roadItem) { + $roadItem['can_supervise'] = Gate::allows('gate-supervise-road-item', $roadItem) ? 1 : 0; + } + + return response()->json($data); + } + + public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse + { + $statusFa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید'; + + $roadObserved->update([ + 'status' => $request->verify, + 'status_fa' => $statusFa, + 'supervisor_id' => Auth::id(), + 'supervisor_name' => Auth::user()->name, + 'supervisor_description' => $request->description, + 'supervising_time' => now(), + ]); + + Auth::user()->addActivityComplete(1138); + + return response()->json(['status' => 'succeed']); + } + + + public function supervisorCartableReport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + + { + $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d') . '.xlsx'; + $data = $roadObservationTableService->supervisorCartableIndex($request, true); + + return Excel::download(new SupervisorCartableReport($data['data']), $name); +} + +} diff --git a/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php b/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php new file mode 100644 index 00000000..32d4b335 --- /dev/null +++ b/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + {return [ + 'verify' => ['required', 'in:1,2'], + 'description' => ['nullable', 'string'], + ]; + } +} diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php new file mode 100644 index 00000000..035e6445 --- /dev/null +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -0,0 +1,28 @@ +user(); + + if ($user->hasPermissionTo('supervise-fast-react')) { + $query = RoadObserved::query(); + } + elseif ($user->hasPermissionTo('supervise-fast-react-province') && $user->province_id) { + $query = RoadObserved::where('province_id', $user->province_id); + } + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*']); + } +} \ No newline at end of file diff --git a/routes/v3.php b/routes/v3.php index 584c6178..7c618393 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -12,6 +12,7 @@ use App\Http\Controllers\V3\Dashboard\AccidentReceiptController; use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController; 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\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; @@ -265,3 +266,13 @@ Route::prefix('receipt_reports') Route::get('/province_excel_report', 'provinceExcelReport')->name('provinceExcelReport'); Route::get('/city_excel_report', 'cityExcelReport')->name('cityExcelReport'); }); + +Route::prefix('road_observations') + ->name('roadObservations.') + ->middleware('permission:manage-road-observation') + ->controller(RoadObservationController::class) + ->group(function () { + Route::get('/', 'supervisorIndex')->name('index'); + Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); + Route::get('/report', 'supervisorReport')->name('report'); + }); From 3ccaaf74916607bfe187568163763ecc8116de43 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 23 Feb 2025 15:53:49 +0330 Subject: [PATCH 16/61] rename the damage item --- .../Dashboard/AccidentReceiptController.php | 20 +++++++++---------- .../AccidentReceiptReportController.php | 8 +++++--- .../V3/AccidentReceipt/StoreRequest.php | 3 +++ .../V3/AccidentReceipt/UpdateRequest.php | 3 +++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 3541ddc0..9520c2d2 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -91,14 +91,14 @@ class AccidentReceiptController extends Controller $sum = 0; $damageData = []; - foreach ($request->items_damge as $key => $damage) { - $damage = Damage::query()->find($damage->id); - $damageData[$damage->id] = [ - 'value' => $damage->value, + foreach ($request->damage_items as $key => $item) { + $damage = Damage::query()->find($item->id); + $damageData[$item->id] = [ + 'value' => $item->value, 'unit' => $damage->unit, - 'amount' => $damage->amount, + 'amount' => $item->amount, ]; - $sum += $damage->amount; + $sum += $item->amount; } $ojrate_nasb = $sum/100*20; @@ -176,12 +176,12 @@ class AccidentReceiptController extends Controller $sum = 0; $damageData = []; - foreach ($request->items_damge as $key => $item) { + foreach ($request->damage_items as $key => $item) { $damage = Damage::query()->find($item->id); - $damageData[$damage->id] = [ - 'value' => $damage->value, + $damageData[$item->id] = [ + 'value' => $item->value, 'unit' => $damage->unit, - 'amount' => $damage->amount, + 'amount' => $item->amount, ]; $sum += $item->amount; } diff --git a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php index f112be93..1af76f3c 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php @@ -22,7 +22,7 @@ class AccidentReceiptReportController extends Controller { $data = $accidentReceiptTableService->provinceReport($request); return $this->successResponse([ - 'data' => $data['data'], + 'activities' => $data['data'], 'provinces' => Province::all(['id', 'name_fa']), ]); } @@ -31,8 +31,10 @@ class AccidentReceiptReportController extends Controller { $data = $accidentReceiptTableService->cityReport($request); return $this->successResponse([ - 'data' => $data['data'], - 'cities' => City::all(['id', 'name_fa']), + 'activities' => $data['data'], + 'cities' => City::query()->where('province_id', '=', $request->province_id) + ->where('type_id', '=', 1) + ->get(['id', 'name_fa']), ]); } diff --git a/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php b/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php index b5b5627f..5b7f34bf 100644 --- a/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php +++ b/app/Http/Requests/V3/AccidentReceipt/StoreRequest.php @@ -42,6 +42,9 @@ class StoreRequest extends FormRequest 'police_file_date' => 'required_if:report_base,0|date', 'damage_picture1' => 'required|file|mimes:pdf,jpg,jpeg,png', 'damage_picture2' => 'required|file|mimes:pdf,jpg,jpeg,png', + 'damage_items' => 'required|array', + 'damage_items.*.value' => 'required', + 'damage_items.*.amount' => 'required', ]; } } diff --git a/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php b/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php index c5219237..3b50bdf5 100644 --- a/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php +++ b/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php @@ -40,6 +40,9 @@ class UpdateRequest extends FormRequest 'police_file_date' => 'required_if:report_base,0|date', 'damage_picture1' => 'required|file|mimes:pdf,jpg,jpeg,png', 'damage_picture2' => 'required|file|mimes:pdf,jpg,jpeg,png', + 'damage_items' => 'required|array', + 'damage_items.*.value' => 'required', + 'damage_items.*.amount' => 'required', ]; } } From a537a19faad016a436df17877d53567beee1a30e Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 23 Feb 2025 16:47:30 +0330 Subject: [PATCH 17/61] debug update method --- .../Dashboard/AccidentReceiptController.php | 60 +++++++++---------- .../Cartables/AccidentReceiptTableService.php | 14 +++++ 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 9520c2d2..9a589e11 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -92,13 +92,13 @@ class AccidentReceiptController extends Controller $damageData = []; foreach ($request->damage_items as $key => $item) { - $damage = Damage::query()->find($item->id); - $damageData[$item->id] = [ - 'value' => $item->value, + $damage = Damage::query()->find($item['id']); + $damageData[$item['id']] = [ + 'value' => $item['value'], 'unit' => $damage->unit, - 'amount' => $item->amount, + 'amount' => $item['amount'], ]; - $sum += $item->amount; + $sum += $item['amount']; } $ojrate_nasb = $sum/100*20; @@ -129,24 +129,6 @@ class AccidentReceiptController extends Controller $province = Province::query()->where('id', '=', $request->province_id)->first(); $city = City::query()->where('id', '=', $request->city_id)->first(); - if ($request->report_base && $accident->police_file) { - FileFacade::delete($accident->police_file, true); - } - - if (!$request->report_base) { - FileFacade::delete($accident->police_file, true); - $police_file = FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/"); - } - - if ($request->has('damage_picture1')) { - FileFacade::delete($accident->damage_picture1, true); - $damage_picture1 = FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}/"); - } - if ($request->has('damage_picture2')) { - FileFacade::delete($accident->damage_picture2, true); - $damage_picture2 = FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}/"); - } - $accidentData = [ 'province_id' => $province->id, 'province_fa' => $province->name_fa, @@ -166,24 +148,40 @@ class AccidentReceiptController extends Controller 'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), 'report_base' => $request->report_base, - 'police_file' => $police_file ?? null, 'police_serial' => $request->police_serial ?? null, 'police_file_date' => $request->police_file_date ?? null, - 'damage_picture1' => $damage_picture1 ?? null, - 'damage_picture2' => $damage_picture2 ?? null, ]; + if ($request->report_base && $accident->police_file) { + FileFacade::delete($accident->police_file, true); + } + + if (!$request->report_base) { + FileFacade::delete($accident->police_file, true); + $accidentData['police_file'] = FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/"); + } + + if ($request->has('damage_picture1')) { + FileFacade::delete($accident->damage_picture1, true); + $accidentData['damage_picture1'] = FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}/"); + } + + if ($request->has('damage_picture2')) { + FileFacade::delete($accident->damage_picture2, true); + $accidentData['damage_picture2'] = FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}/"); + } + $sum = 0; $damageData = []; foreach ($request->damage_items as $key => $item) { - $damage = Damage::query()->find($item->id); - $damageData[$item->id] = [ - 'value' => $item->value, + $damage = Damage::query()->find($item['id']); + $damageData[$item['id']] = [ + 'value' => $item['value'], 'unit' => $damage->unit, - 'amount' => $item->amount, + 'amount' => $item['amount'], ]; - $sum += $item->amount; + $sum += $item['amount']; } $ojrate_nasb = $sum/100*20; diff --git a/app/Services/Cartables/AccidentReceiptTableService.php b/app/Services/Cartables/AccidentReceiptTableService.php index 6831f918..3a0ace1a 100644 --- a/app/Services/Cartables/AccidentReceiptTableService.php +++ b/app/Services/Cartables/AccidentReceiptTableService.php @@ -81,6 +81,20 @@ class AccidentReceiptTableService { $data = DB::select( 'SELECT + "استانی" as city_fa, + -1 as city_id, + COUNT(id) AS tedade, + COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah, + COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht, + SUM(`sum`) AS kol_sabt_shode, + SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode, + SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh, + SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi, + SUM(CASE WHEN STATUS > 3 THEN `final_amount` END) AS vasel_shode_final + FROM `accidents` + where created_at BETWEEN "'.$request->from_date.'" AND "'.$request->date_to.'" AND province_id ='.$request->province_id.' + union + SELECT city_fa, city_id, COUNT(id) AS tedade, From baab9196d789a040227b21fa0eed922fe654e0dc Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 24 Feb 2025 09:53:36 +0330 Subject: [PATCH 18/61] create blade excel files --- app/Exports/V3/AccidentReceipt/CityReport.php | 79 ----------- .../V3/AccidentReceipt/CountryReport.php | 123 ++++++++++++++++++ .../V3/AccidentReceipt/DataTableReport.php | 2 +- .../V3/AccidentReceipt/ProvinceReport.php | 56 +++++++- .../Dashboard/AccidentReceiptController.php | 2 +- .../AccidentReceiptReportController.php | 31 +++-- .../Cartables/AccidentReceiptTableService.php | 13 +- .../AccidentReceipt/CountryReport.blade.php | 108 +++++++++++++++ .../AccidentReceipt/DataTableReport.blade.php | 82 ++++++++++++ .../AccidentReceipt/ProvinceReport.blade.php | 109 ++++++++++++++++ routes/v3.php | 4 +- 11 files changed, 503 insertions(+), 106 deletions(-) delete mode 100644 app/Exports/V3/AccidentReceipt/CityReport.php create mode 100644 app/Exports/V3/AccidentReceipt/CountryReport.php create mode 100644 resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php create mode 100644 resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php create mode 100644 resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php diff --git a/app/Exports/V3/AccidentReceipt/CityReport.php b/app/Exports/V3/AccidentReceipt/CityReport.php deleted file mode 100644 index db40c177..00000000 --- a/app/Exports/V3/AccidentReceipt/CityReport.php +++ /dev/null @@ -1,79 +0,0 @@ -data; - - return view('v3.AccidentReceipt.CityReport', [ - 'data' => $data['data'], - 'fromDate' => $data['fromDate'], - 'ToDate' => $data['ToDate'], - ]); - } - - /** - * @return array - */ - public function registerEvents(): array - { - return [ - AfterSheet::class => function (AfterSheet $event) { - $event->sheet->getDelegate()->setRightToLeft(true); - }, - ]; - } - - public function drawings() - { - $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) - { - return [ - // Style the first row as bold text. - 'A:BA' => [ - 'font' => [ - 'name' => 'B Nazanin' - ] - ], - ]; - } -} diff --git a/app/Exports/V3/AccidentReceipt/CountryReport.php b/app/Exports/V3/AccidentReceipt/CountryReport.php new file mode 100644 index 00000000..e37c0386 --- /dev/null +++ b/app/Exports/V3/AccidentReceipt/CountryReport.php @@ -0,0 +1,123 @@ +data; + + foreach (Province::all() as $province) { + + $existingProvince = array_search($province->id, array_column($data['data'], 'province_id')); + + if ($existingProvince) { + $activities[] = [ + 'name' => $province->name_fa, + 'tedade' => $data['data'][$existingProvince]->tedade, + 'police_rah' => $data['data'][$existingProvince]->police_rah, + 'gozaresh_gasht' => $data['data'][$existingProvince]->gozaresh_gasht, + 'kol_sabt_shode' => $data['data'][$existingProvince]->kol_sabt_shode, + 'vasel_shode' => $data['data'][$existingProvince]->vasel_shode ?? 0, + 'vasel_shode_bimeh' => $data['data'][$existingProvince]->vasel_shode_bimeh ?? 0, + 'vasel_shode_daghi' => $data['data'][$existingProvince]->vasel_shode_daghi ?? 0, + 'vasel_shode_final' => $data['data'][$existingProvince]->vasel_shode_final ?? 0, + ]; + } else { + $activities[] = [ + 'name' => $province->name_fa, + 'tedade' => "", + 'police_rah' => "", + 'gozaresh_gasht' => "", + 'kol_sabt_shode' => "", + 'vasel_shode' => "", + 'vasel_shode_bimeh' => "", + 'vasel_shode_daghi' => "", + 'vasel_shode_final' => "", + ]; + } + } + + $activities[] = [ + 'name' => 'کشوری', + 'tedade' => $data['data'][-1]->tedade, + 'police_rah' => $data['data'][-1]->police_rah, + 'gozaresh_gasht' => $data['data'][-1]->gozaresh_gasht, + 'kol_sabt_shode' => $data['data'][-1]->kol_sabt_shode, + 'vasel_shode' => $data['data'][-1]->vasel_shode ?? 0, + 'vasel_shode_bimeh' => $data['data'][-1]->vasel_shode_bimeh ?? 0, + 'vasel_shode_daghi' => $data['data'][-1]->vasel_shode_daghi ?? 0, + 'vasel_shode_final' => $data['data'][-1]->vasel_shode_final ?? 0, + ]; + + return view('v3.Reports.AccidentReceipt.CountryReport', [ + 'data' => $activities, + 'fromDate' => $data['fromDate'], + 'toDate' => $data['toDate'], + ]); + } + + /** + * @return array + */ + 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 [ + // Style the first row as bold text. + 'A:BA' => [ + 'font' => [ + 'name' => 'B Nazanin' + ] + ], + ]; + } +} diff --git a/app/Exports/V3/AccidentReceipt/DataTableReport.php b/app/Exports/V3/AccidentReceipt/DataTableReport.php index ba9bed37..4d6a0a5f 100644 --- a/app/Exports/V3/AccidentReceipt/DataTableReport.php +++ b/app/Exports/V3/AccidentReceipt/DataTableReport.php @@ -20,7 +20,7 @@ class DataTableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawi public function view(): View { - return view('v3.AccidentReceipt.DataTableReport', [ + return view('v3.Reports.AccidentReceipt.DataTableReport', [ 'data' => $this->data, ]); } diff --git a/app/Exports/V3/AccidentReceipt/ProvinceReport.php b/app/Exports/V3/AccidentReceipt/ProvinceReport.php index 9eee4900..9339384b 100644 --- a/app/Exports/V3/AccidentReceipt/ProvinceReport.php +++ b/app/Exports/V3/AccidentReceipt/ProvinceReport.php @@ -20,11 +20,57 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin public function view(): View { - $data = $this->data; - return view('v3.AccidentReceipt.ProvinceReport', [ - 'data' => $data['data'], - 'fromDate' => $data['fromDate'], - 'ToDate' => $data['ToDate'], + $inputData = $this->data; + $reportData =$inputData['report']; + + foreach ($inputData['cities'] as $city) { + + $existingCity = array_search($city->id, array_column($inputData['data'], 'city_id')); + + if ($existingCity) { + $activities[] = [ + 'name' => $city->name_fa, + 'tedade' => $reportData['data'][$existingCity]->tedade, + 'police_rah' => $reportData['data'][$existingCity]->police_rah, + 'gozaresh_gasht' => $reportData['data'][$existingCity]->gozaresh_gasht, + 'kol_sabt_shode' => $reportData['data'][$existingCity]->kol_sabt_shode, + 'vasel_shode' => $reportData['data'][$existingCity]->vasel_shode ?? 0, + 'vasel_shode_bimeh' => $reportData['data'][$existingCity]->vasel_shode_bimeh ?? 0, + 'vasel_shode_daghi' => $reportData['data'][$existingCity]->vasel_shode_daghi ?? 0, + 'vasel_shode_final' => $reportData['data'][$existingCity]->vasel_shode_final ?? 0, + ]; + } else { + $activities[] = [ + 'name' => $city->name_fa, + 'tedade' => "", + 'police_rah' => "", + 'gozaresh_gasht' => "", + 'kol_sabt_shode' => "", + 'vasel_shode' => "", + 'vasel_shode_bimeh' => "", + 'vasel_shode_daghi' => "", + 'vasel_shode_final' => "", + ]; + } + } + + $activities[] = [ + 'name' => 'استانی', + 'tedade' => $reportData['data'][-1]->tedade, + 'police_rah' => $reportData['data'][-1]->police_rah, + 'gozaresh_gasht' => $reportData['data'][-1]->gozaresh_gasht, + 'kol_sabt_shode' => $reportData['data'][-1]->kol_sabt_shode, + 'vasel_shode' => $reportData['data'][-1]->vasel_shode ?? 0, + 'vasel_shode_bimeh' => $reportData['data'][-1]->vasel_shode_bimeh ?? 0, + 'vasel_shode_daghi' => $reportData['data'][-1]->vasel_shode_daghi ?? 0, + 'vasel_shode_final' => $reportData['data'][-1]->vasel_shode_final ?? 0, + ]; + + + return view('v3.Reports.AccidentReceipt.ProvinceReport', [ + 'data' => $activities, + 'fromDate' => $reportData['fromDate'], + 'toDate' => $reportData['toDate'], ]); } diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 9a589e11..9a31cdb2 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -44,7 +44,7 @@ class AccidentReceiptController extends Controller { auth()->user()->addActivityComplete(1126); $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - $data = $accidentReceiptTableService->dataTable($request); + $data = $accidentReceiptTableService->dataTable($request, true); return Excel::download(new DataTableReport($data), $name); } diff --git a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php index 1af76f3c..e9a29694 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers\V3\Dashboard\Reports; -use App\Exports\V3\AccidentReceipt\CityReport; use App\Exports\V3\AccidentReceipt\ProvinceReport; +use App\Exports\V3\AccidentReceipt\CountryReport; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; use App\Models\City; @@ -18,18 +18,18 @@ class AccidentReceiptReportController extends Controller { use ApiResponse; - public function provinceReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse + public function countryReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse { - $data = $accidentReceiptTableService->provinceReport($request); + $data = $accidentReceiptTableService->countryReport($request); return $this->successResponse([ 'activities' => $data['data'], 'provinces' => Province::all(['id', 'name_fa']), ]); } - public function cityReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse + public function provinceReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse { - $data = $accidentReceiptTableService->cityReport($request); + $data = $accidentReceiptTableService->provinceReport($request); return $this->successResponse([ 'activities' => $data['data'], 'cities' => City::query()->where('province_id', '=', $request->province_id) @@ -38,17 +38,22 @@ class AccidentReceiptReportController extends Controller ]); } + public function countryExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse + { + $data = $accidentReceiptTableService->countryReport($request); + $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; + return Excel::download(new CountryReport($data), $name); + } + public function provinceExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse { $data = $accidentReceiptTableService->provinceReport($request); $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - return Excel::download(new ProvinceReport($data), $name); - } - - public function cityExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse - { - $data = $accidentReceiptTableService->cityReport($request); - $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - return Excel::download(new CityReport($data), $name); + return Excel::download(new ProvinceReport([ + 'report' => $data, + 'cities' => City::query()->where('province_id', '=', $request->province_id) + ->where('type_id', '=', 1) + ->get(['id', 'name_fa']), + ]), $name); } } diff --git a/app/Services/Cartables/AccidentReceiptTableService.php b/app/Services/Cartables/AccidentReceiptTableService.php index 3a0ace1a..e757516f 100644 --- a/app/Services/Cartables/AccidentReceiptTableService.php +++ b/app/Services/Cartables/AccidentReceiptTableService.php @@ -12,20 +12,23 @@ class AccidentReceiptTableService { use ApiResponse; - public function dataTable(Request $request) + public function dataTable(Request $request, $loadRelations = false) { $user = auth()->user(); $query = null; if ($user->hasPermissionTo('show-receipt')) { - $query = Accident::query(); + $query = Accident::query() + ->when($loadRelations, fn ($query) => $query->with('damages')); } else { if (is_null($user->province_id)) { return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } - $query = Accident::query()->where('province_id', '=', $user->province_id); + $query = Accident::query() + ->where('province_id', '=', $user->province_id) + ->when($loadRelations, fn ($query) => $query->with('damages')); } return DataTableFacade::run( @@ -36,7 +39,7 @@ class AccidentReceiptTableService ); } - public function provinceReport(Request $request): array + public function countryReport(Request $request): array { $data = DB::select( 'SELECT @@ -77,7 +80,7 @@ class AccidentReceiptTableService ]; } - public function cityReport(Request $request): array + public function provinceReport(Request $request): array { $data = DB::select( 'SELECT diff --git a/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php new file mode 100644 index 00000000..9ba1263b --- /dev/null +++ b/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php @@ -0,0 +1,108 @@ + + + + + + + + کشوری + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $road) + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش خسارات وارده به ابنیه فنی و تاسیسات راه از تاریخ + {{ verta($fromDate)->format('Y/n/j') }} + تا + تاریخ + {{ verta($ToDate)->format('Y/n/j') }} + +
+ اداره کل + + تعداد کل + + نحوه شناسایی خسارت + + مبلغ کل خسارت ثبت شده (ریال) + + کل مبلغ وصول شده (ریال) + + مبلغ وصول شده به تفکیک نوع پرداخت (ریال) +
+ گزارش پلیس راه + + گزارش گشت راهداری + + بیمه + + کسر داغی + + شخص +
+ {{ $road['name'] }} + {{ $road['tedade'] }} + {{ $road['police_rah'] }} + {{ $road['gozaresh_gasht'] }} + {{ $road['kol_sabt_shode'] }} + {{ $road['vasel_shode'] }} + {{ $road['vasel_shode_bimeh'] }} + {{ $road['vasel_shode_daghi'] }} + {{ $road['vasel_shode_final'] }}
+ + diff --git a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php new file mode 100644 index 00000000..024c9621 --- /dev/null +++ b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php @@ -0,0 +1,82 @@ + + + + + + + خسارات وارده به تفکیک استان + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + @php + $temp = ''; + @endphp + @foreach ($item->damages as $damage) + @php + $temp .= $damage->title." (".$damage->pivot->value." ".$damage->unit.") - "; + @endphp + @endforeach + + + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{verta()->now()->format('Y/m/d H:i')}} +
گزارش کلی خسارات وارده
شناسه ثبت در سامانه RMSتاریخ ثبت در سامانهنام استاننام شهرستانتاریخ تصادفساعت تصادفنوع خسارتنوع تجهیزات خسارت دیدهمبلغ برآورد اولیهآخرین وضعیتمبلغ وصولی به حساب ادارهمیزان فرانشیز کسر شدهمیزان داغی تجهیزات خسارت دیده موجود انبار ادارهمبلغ فیشمبلغ بیمهمبلغ داغی
{{$item->id}}{{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}}{{$item->province_fa}}{{$item->city_fa}}{{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}}{{$item->accident_time}}{{$item->accident_type_fa}}{{$temp}}{{$item->sum ?? 0}}{{$item->status_fa}}{{$item->deposit_insurance_amount + $item->final_amount}}{{$item->final_amount}}{{$item->deposit_insurance_amount}}{{$item->deposit_daghi_amount}}
+ + diff --git a/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php new file mode 100644 index 00000000..ae8d4da5 --- /dev/null +++ b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php @@ -0,0 +1,109 @@ + + + + + + + + استانی + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $road) + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش خسارات وارده به ابنیه فنی و تاسیسات راه از تاریخ + {{ verta($fromDate)->format('Y/n/j') }} + تا + تاریخ + {{ verta($toDate)->format('Y/n/j') }} + +
+ اداره کل + + تعداد کل + + نحوه شناسایی خسارت + + مبلغ کل خسارت ثبت شده (ریال) + + کل مبلغ وصول شده (ریال) + + مبلغ وصول شده به تفکیک نوع پرداخت (ریال) +
+ گزارش پلیس راه + + گزارش گشت راهداری + + بیمه + + کسر داغی + + شخص +
+ {{ $road['name'] }} + {{ $road['tedade'] }} + {{ $road['police_rah'] }} + {{ $road['gozaresh_gasht'] }} + {{ $road['kol_sabt_shode'] }} + {{ $road['vasel_shode'] }} + {{ $road['vasel_shode_bimeh'] }} + {{ $road['vasel_shode_daghi'] }} + {{ $road['vasel_shode_final'] }}
+ + diff --git a/routes/v3.php b/routes/v3.php index 759900bc..7c68023c 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -270,8 +270,8 @@ Route::prefix('receipt_reports') ->name('receiptReports.') ->controller(AccidentReceiptReportController::class) ->group(function () { + Route::get('/country_report', 'countryReport')->name('countryReport'); Route::get('/province_report', 'provinceReport')->name('provinceReport'); - Route::get('/city_report', 'cityReport')->name('cityReport'); + Route::get('/country_excel_report', 'countryExcelReport')->name('countryExcelReport'); Route::get('/province_excel_report', 'provinceExcelReport')->name('provinceExcelReport'); - Route::get('/city_excel_report', 'cityExcelReport')->name('cityExcelReport'); }); From 918a91d52a17dc55cd610aba77871721f06c8982 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 24 Feb 2025 11:00:59 +0330 Subject: [PATCH 19/61] debug the blade file --- .../Dashboard/AccidentReceiptController.php | 2 +- app/Models/Accident.php | 23 ++++++++++ .../AccidentReceipt/DataTableReport.blade.php | 46 ++++++------------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 9a31cdb2..530b4add 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -45,7 +45,7 @@ class AccidentReceiptController extends Controller auth()->user()->addActivityComplete(1126); $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; $data = $accidentReceiptTableService->dataTable($request, true); - return Excel::download(new DataTableReport($data), $name); + return Excel::download(new DataTableReport($data['data']), $name); } public function accidentDamage(Accident $accident): JsonResponse diff --git a/app/Models/Accident.php b/app/Models/Accident.php index 510df15d..f1495dce 100644 --- a/app/Models/Accident.php +++ b/app/Models/Accident.php @@ -2,10 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Traits\ReceiptReportAble; use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Support\Facades\Storage; class Accident extends Model { @@ -95,4 +97,25 @@ class Accident extends Model { return $this->morphMany(File::class, 'fileable'); } + + protected function damagePicture1(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } + + protected function damagePicture2(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } + + protected function policeFile(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } } diff --git a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php index 024c9621..beb27f54 100644 --- a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php @@ -22,21 +22,16 @@ - شناسه ثبت در سامانه RMS - تاریخ ثبت در سامانه - نام استان - نام شهرستان + کد یکتا + استان + شهرستان + نام محور + نوع تصادف تاریخ تصادف - ساعت تصادف - - نوع خسارت - - نوع تجهیزات خسارت دیده - مبلغ برآورد اولیه - آخرین وضعیت - مبلغ وصولی به حساب اداره - میزان فرانشیز کسر شده - میزان داغی تجهیزات خسارت دیده موجود انبار اداره + مبلغ کل خسارت + پلاک + تاریخ ثبت + آخرین وضعیت مبلغ فیش مبلغ بیمه مبلغ داغی @@ -47,30 +42,15 @@ @foreach ($data as $item) {{$item->id}} - {{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}} {{$item->province_fa}} {{$item->city_fa}} - {{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}} - {{$item->accident_time}} - + {{$item->axis_name}} {{$item->accident_type_fa}} - @php - $temp = ''; - @endphp - @foreach ($item->damages as $damage) - @php - $temp .= $damage->title." (".$damage->pivot->value." ".$damage->unit.") - "; - @endphp - @endforeach - - {{$temp}} - - + {{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j') ($item->accident_time)}} {{$item->sum ?? 0}} + {{$item->plaque}} + {{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}} {{$item->status_fa}} - {{$item->deposit_insurance_amount + $item->final_amount}} - - {{$item->final_amount}} {{$item->deposit_insurance_amount}} {{$item->deposit_daghi_amount}} From d9d51c63c68a6c780ea11f22da0540d15ae8a728 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 24 Feb 2025 11:12:54 +0330 Subject: [PATCH 20/61] fix and update v2 for operator --- .../OperatorCartableReport.php | 70 ++++++++++++++++++ .../Dashboard/RoadObservationController.php | 56 +++++++++------ .../VerifyBySupervisorRequest.php | 5 +- .../Cartables/RoadObservationTableService.php | 71 +++++++++++++++++-- routes/v3.php | 9 +-- 5 files changed, 180 insertions(+), 31 deletions(-) create mode 100644 app/Exports/V3/RoadObservation/OperatorCartableReport.php diff --git a/app/Exports/V3/RoadObservation/OperatorCartableReport.php b/app/Exports/V3/RoadObservation/OperatorCartableReport.php new file mode 100644 index 00000000..18e0ef18 --- /dev/null +++ b/app/Exports/V3/RoadObservation/OperatorCartableReport.php @@ -0,0 +1,70 @@ + $this->data, + ]); + + } + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + $event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial'); + $event->sheet->getDelegate()->getStyle('A:U') + ->getAlignment() + ->setHorizontal(Alignment::HORIZONTAL_CENTER); + + $event->sheet->getDelegate()->getStyle('A:U') + ->getAlignment() + ->setVertical(Alignment::VERTICAL_CENTER); + } + ]; + } + + 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('q1'); + return [$drawing, $drawing2]; + } + +} diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index beb8bb69..bdc10f8c 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -1,9 +1,11 @@ supervisorCartableIndex($request); - foreach ($data['data'] as &$roadItem) { - $roadItem['can_supervise'] = Gate::allows('gate-supervise-road-item', $roadItem) ? 1 : 0; - } - return response()->json($data); } - public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse + public function verifybysupervisor (VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse { $statusFa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید'; $roadObserved->update([ - 'status' => $request->verify, - 'status_fa' => $statusFa, - 'supervisor_id' => Auth::id(), - 'supervisor_name' => Auth::user()->name, - 'supervisor_description' => $request->description, - 'supervising_time' => now(), - ]); + 'status' => $request->verify, + 'status_fa' => $statusFa, + 'supervisor_id' => auth()->user()->id(), + 'supervisor_name' => auth()->user()->name, + 'supervisor_description' => $request->description, + 'supervising_time' => now(), + ]); - Auth::user()->addActivityComplete(1138); + auth()->user()->addActivityComplete(1138); + + return $this->successResponse(['status' => 'succeed']); - return response()->json(['status' => 'succeed']); } - - public function supervisorCartableReport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + public function supervisorcartablereport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { - $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d') . '.xlsx'; + $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->supervisorCartableIndex($request, true); - return Excel::download(new SupervisorCartableReport($data['data']), $name); -} + return Excel::download(new SupervisorCartableReport($data), $name); + } + + public function operatorindex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse + { + $data = $roadObservationTableService->operatorCartableIndex($request); + return response()->json($data); + } + + public function operatorcartablereport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + { + $name = 'گزارش از کارتابل ارزیابی واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; + $data = $roadObservationTableService->operatorCartableIndex($request); + return Excel::download(new OperatorCartableReport($data), $name); + } } + diff --git a/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php b/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php index 32d4b335..e2154f30 100644 --- a/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php +++ b/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\V3\RoadObservation; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Support\Facades\Gate; class VerifyBySupervisorRequest extends FormRequest { @@ -11,7 +12,7 @@ class VerifyBySupervisorRequest extends FormRequest */ public function authorize(): bool { - return true; + return Gate::allows('gate-supervise-road-observed'); } /** @@ -22,7 +23,7 @@ class VerifyBySupervisorRequest extends FormRequest public function rules(): array {return [ 'verify' => ['required', 'in:1,2'], - 'description' => ['nullable', 'string'], + 'description' => ['string'], ]; } } diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index 035e6445..9b8bbafd 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -3,20 +3,83 @@ namespace App\Services\Cartables; use App\Facades\DataTable\DataTableFacade; +use App\Http\Traits\ApiResponse; use App\Models\RoadObserved; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class RoadObservationTableService { - public function supervisorCartableIndex(Request $request, $loadRelations = false) + use ApiResponse; + public function supervisorCartableIndex(Request $request) { $user = auth()->user(); + $fields = [ + 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', + 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', + 'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', + 'road_observeds.province_id', 'province_fa', 'city_fa', 'edarate_shahri.name_fa', + 'status', 'status_fa', 'supervisor_description', 'supervising_time' + ]; + + if ($user->hasPermissionTo('supervise-fast-react')) { - $query = RoadObserved::query(); + $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->whereNotNull('road_observeds.status'); } - elseif ($user->hasPermissionTo('supervise-fast-react-province') && $user->province_id) { - $query = RoadObserved::where('province_id', $user->province_id); + elseif ($user->hasPermissionTo('supervise-fast-react-province')) + { + if (is_null($user->province_id)) + { + return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); + } + + $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('road_observeds.province_id', $user->province_id) + ->whereNotNull('road_observeds.status'); + } + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*']); + } + + public function operatorCartableIndex(Request $request) + { + $user = auth()->user(); + + $fields = [ + 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', + 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', + 'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa', + 'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_fa', + 'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time' + ]; + + $query = RoadObserved::query() + ->where('rms_status', '!=', 0) + ->whereNotNull('road_observeds.province_id') + ->whereNotNull('status') + ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') + ->select($fields) + ->addSelect([ + DB::raw("CONCAT('https://rms.rmto.ir/', image_before) as image_before"), + DB::raw("CONCAT('https://rms.rmto.ir/', image_after) as image_after") + ]); + + if ($user->hasPermissionTo('show-fast-react-province')) { + if (is_null($user->province_id)) { + return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); + } + $query->where('rms_province_id', $user->province_id); + } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { + if (is_null($user->edarate_shahri_id)) { + return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); + } + $query->where('edarate_shahri_id', $user->edarate_shahri_id); } return DataTableFacade::run( diff --git a/routes/v3.php b/routes/v3.php index 7c618393..22ec9951 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -269,10 +269,11 @@ Route::prefix('receipt_reports') Route::prefix('road_observations') ->name('roadObservations.') - ->middleware('permission:manage-road-observation') ->controller(RoadObservationController::class) ->group(function () { - Route::get('/', 'supervisorIndex')->name('index'); - Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); - Route::get('/report', 'supervisorReport')->name('report'); + Route::get('/supervisor_index', 'supervisorindex')->name('supervisorIndex')->middleware('supervise-fast-react-province','supervise-fast-react'); + Route::post('/verify/{road_observed}', 'verifybysupervisor')->name('verifyBySupervisor'); + Route::get('/supervisor_report', 'supervisorcartablereport')->name('report'); + Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('show-fast-react','show-fast-react-province'); + Route::get('/operator_report', 'operatorcartablereport')->name('operatorExcelReport'); }); From 19dd88cd25093ffca87fe67de7bf2fe594eaec38 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 24 Feb 2025 11:26:53 +0330 Subject: [PATCH 21/61] debug my code --- .../Dashboard/RoadObservationController.php | 20 +++++++++---------- routes/v3.php | 10 +++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index bdc10f8c..1000a9ce 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -10,22 +10,20 @@ use App\Models\RoadObserved; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Services\Cartables\RoadObservationTableservice; -use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Facades\Excel; -use Illuminate\Support\Facades\Gate; use Symfony\Component\HttpFoundation\BinaryFileResponse; class RoadObservationController extends Controller { use ApiResponse; - public function supervisorindex (Request $request,RoadObservationTableservice $roadObservationTableservice ): JsonResponse + public function supervisorIndex (Request $request,RoadObservationTableservice $roadObservationTableservice ): JsonResponse { - $data = $roadObservationTableservice-> supervisorCartableIndex($request); + $data = $roadObservationTableservice->supervisorCartableIndex($request); return response()->json($data); } - public function verifybysupervisor (VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse + public function verifyBySupervisor (VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse { $statusFa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید'; @@ -40,30 +38,30 @@ class RoadObservationController extends Controller auth()->user()->addActivityComplete(1138); - return $this->successResponse(['status' => 'succeed']); + return $this->successResponse(); } - public function supervisorcartablereport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + public function supervisorCartableReport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->supervisorCartableIndex($request, true); - return Excel::download(new SupervisorCartableReport($data), $name); + return Excel::download(new SupervisorCartableReport($data['data']), $name); } - public function operatorindex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse + public function operatorIndex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse { $data = $roadObservationTableService->operatorCartableIndex($request); return response()->json($data); } - public function operatorcartablereport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + public function operatorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->operatorCartableIndex($request); - return Excel::download(new OperatorCartableReport($data), $name); + return Excel::download(new OperatorCartableReport($data['data']), $name); } } diff --git a/routes/v3.php b/routes/v3.php index 22ec9951..fb984f0f 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -271,9 +271,9 @@ Route::prefix('road_observations') ->name('roadObservations.') ->controller(RoadObservationController::class) ->group(function () { - Route::get('/supervisor_index', 'supervisorindex')->name('supervisorIndex')->middleware('supervise-fast-react-province','supervise-fast-react'); - Route::post('/verify/{road_observed}', 'verifybysupervisor')->name('verifyBySupervisor'); - Route::get('/supervisor_report', 'supervisorcartablereport')->name('report'); - Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('show-fast-react','show-fast-react-province'); - Route::get('/operator_report', 'operatorcartablereport')->name('operatorExcelReport'); + Route::get('/supervisor_index', 'supervisorIndex')->name('supervisorIndex')->middleware('permission:supervise-fast-react-province|supervise-fast-react'); + Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); + Route::get('/supervisor_report', 'supervisorCartableReport')->name('report'); + Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('permission:show-fast-react|show-fast-react-province'); + Route::get('/operator_report', 'operatorCartableReport')->name('operatorExcelReport'); }); From ff83fde991160d1420dc78eeac4c04775ec0f12b Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 24 Feb 2025 11:55:24 +0330 Subject: [PATCH 22/61] fix the country amount --- .../V3/AccidentReceipt/CountryReport.php | 26 +++++++++--------- .../V3/AccidentReceipt/ProvinceReport.php | 27 ++++++++++--------- .../Cartables/AccidentReceiptTableService.php | 4 +-- .../AccidentReceipt/CountryReport.blade.php | 13 ++++----- .../AccidentReceipt/DataTableReport.blade.php | 10 +++---- .../AccidentReceipt/ProvinceReport.blade.php | 11 ++++---- 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/app/Exports/V3/AccidentReceipt/CountryReport.php b/app/Exports/V3/AccidentReceipt/CountryReport.php index e37c0386..e05bdb64 100644 --- a/app/Exports/V3/AccidentReceipt/CountryReport.php +++ b/app/Exports/V3/AccidentReceipt/CountryReport.php @@ -23,6 +23,20 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing { $data = $this->data; + $country = array_search(-1, array_column($data['data'], 'province_id')); + + $activities[] = [ + 'name' => 'کل کشور', + 'tedade' => $data['data'][$country]->tedade, + 'police_rah' => $data['data'][$country]->police_rah, + 'gozaresh_gasht' => $data['data'][$country]->gozaresh_gasht, + 'kol_sabt_shode' => $data['data'][$country]->kol_sabt_shode, + 'vasel_shode' => $data['data'][$country]->vasel_shode ?? 0, + 'vasel_shode_bimeh' => $data['data'][$country]->vasel_shode_bimeh ?? 0, + 'vasel_shode_daghi' => $data['data'][$country]->vasel_shode_daghi ?? 0, + 'vasel_shode_final' => $data['data'][$country]->vasel_shode_final ?? 0, + ]; + foreach (Province::all() as $province) { $existingProvince = array_search($province->id, array_column($data['data'], 'province_id')); @@ -54,18 +68,6 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing } } - $activities[] = [ - 'name' => 'کشوری', - 'tedade' => $data['data'][-1]->tedade, - 'police_rah' => $data['data'][-1]->police_rah, - 'gozaresh_gasht' => $data['data'][-1]->gozaresh_gasht, - 'kol_sabt_shode' => $data['data'][-1]->kol_sabt_shode, - 'vasel_shode' => $data['data'][-1]->vasel_shode ?? 0, - 'vasel_shode_bimeh' => $data['data'][-1]->vasel_shode_bimeh ?? 0, - 'vasel_shode_daghi' => $data['data'][-1]->vasel_shode_daghi ?? 0, - 'vasel_shode_final' => $data['data'][-1]->vasel_shode_final ?? 0, - ]; - return view('v3.Reports.AccidentReceipt.CountryReport', [ 'data' => $activities, 'fromDate' => $data['fromDate'], diff --git a/app/Exports/V3/AccidentReceipt/ProvinceReport.php b/app/Exports/V3/AccidentReceipt/ProvinceReport.php index 9339384b..7c37cbf5 100644 --- a/app/Exports/V3/AccidentReceipt/ProvinceReport.php +++ b/app/Exports/V3/AccidentReceipt/ProvinceReport.php @@ -23,6 +23,20 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin $inputData = $this->data; $reportData =$inputData['report']; + $province = array_search(-1, array_column($reportData, 'province_id')); + + $activities[] = [ + 'name' => 'کل استان', + 'tedade' => $reportData['data'][$province]->tedade, + 'police_rah' => $reportData['data'][$province]->police_rah, + 'gozaresh_gasht' => $reportData['data'][$province]->gozaresh_gasht, + 'kol_sabt_shode' => $reportData['data'][$province]->kol_sabt_shode, + 'vasel_shode' => $reportData['data'][$province]->vasel_shode ?? 0, + 'vasel_shode_bimeh' => $reportData['data'][$province]->vasel_shode_bimeh ?? 0, + 'vasel_shode_daghi' => $reportData['data'][$province]->vasel_shode_daghi ?? 0, + 'vasel_shode_final' => $reportData['data'][$province]->vasel_shode_final ?? 0, + ]; + foreach ($inputData['cities'] as $city) { $existingCity = array_search($city->id, array_column($inputData['data'], 'city_id')); @@ -54,19 +68,6 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin } } - $activities[] = [ - 'name' => 'استانی', - 'tedade' => $reportData['data'][-1]->tedade, - 'police_rah' => $reportData['data'][-1]->police_rah, - 'gozaresh_gasht' => $reportData['data'][-1]->gozaresh_gasht, - 'kol_sabt_shode' => $reportData['data'][-1]->kol_sabt_shode, - 'vasel_shode' => $reportData['data'][-1]->vasel_shode ?? 0, - 'vasel_shode_bimeh' => $reportData['data'][-1]->vasel_shode_bimeh ?? 0, - 'vasel_shode_daghi' => $reportData['data'][-1]->vasel_shode_daghi ?? 0, - 'vasel_shode_final' => $reportData['data'][-1]->vasel_shode_final ?? 0, - ]; - - return view('v3.Reports.AccidentReceipt.ProvinceReport', [ 'data' => $activities, 'fromDate' => $reportData['fromDate'], diff --git a/app/Services/Cartables/AccidentReceiptTableService.php b/app/Services/Cartables/AccidentReceiptTableService.php index e757516f..4f251709 100644 --- a/app/Services/Cartables/AccidentReceiptTableService.php +++ b/app/Services/Cartables/AccidentReceiptTableService.php @@ -74,7 +74,7 @@ class AccidentReceiptTableService ); return [ - 'data' => collect($data), + 'data' => $data, 'fromDate' => $request->from_date, 'toDate' => $request->date_to, ]; @@ -115,7 +115,7 @@ class AccidentReceiptTableService ); return [ - 'data' => collect($data), + 'data' => $data, 'fromDate' => $request->from_date, 'toDate' => $request->date_to, ]; diff --git a/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php index 9ba1263b..c5745eb6 100644 --- a/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php @@ -32,7 +32,7 @@ {{ verta($fromDate)->format('Y/n/j') }} تا تاریخ - {{ verta($ToDate)->format('Y/n/j') }} + {{ verta($toDate)->format('Y/n/j') }} @@ -66,15 +66,16 @@ گزارش گشت راهداری + + فیش + بیمه کسر داغی - - شخص - + @@ -94,12 +95,12 @@ {{ $road['kol_sabt_shode'] }} {{ $road['vasel_shode'] }} + + {{ $road['vasel_shode_final'] }} {{ $road['vasel_shode_bimeh'] }} {{ $road['vasel_shode_daghi'] }} - - {{ $road['vasel_shode_final'] }} @endforeach diff --git a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php index beb27f54..5d0a85fd 100644 --- a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php @@ -4,7 +4,7 @@ - خسارات وارده به تفکیک استان + خسارات وارده به ابنیه فنی @@ -46,14 +46,14 @@ - + - - - + + + @endforeach diff --git a/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php index ae8d4da5..1817487d 100644 --- a/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php @@ -67,15 +67,16 @@ + - + @@ -95,12 +96,12 @@ {{ $road['kol_sabt_shode'] }} + - @endforeach From 89d119767a142ac3a6e15b41bf40b1da90a00c5b Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 24 Feb 2025 12:03:33 +0330 Subject: [PATCH 23/61] province blade --- app/Exports/V3/AccidentReceipt/ProvinceReport.php | 2 +- .../views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Exports/V3/AccidentReceipt/ProvinceReport.php b/app/Exports/V3/AccidentReceipt/ProvinceReport.php index 7c37cbf5..ab63e7f6 100644 --- a/app/Exports/V3/AccidentReceipt/ProvinceReport.php +++ b/app/Exports/V3/AccidentReceipt/ProvinceReport.php @@ -39,7 +39,7 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin foreach ($inputData['cities'] as $city) { - $existingCity = array_search($city->id, array_column($inputData['data'], 'city_id')); + $existingCity = array_search($city->id, array_column($reportData['data'], 'city_id')); if ($existingCity) { $activities[] = [ diff --git a/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php index 1817487d..501f8ce4 100644 --- a/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php @@ -47,7 +47,7 @@ تعداد کل From 21c1e0c580f22a169ea21ff5d4ec4b6500b01d28 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 25 Feb 2025 11:03:13 +0330 Subject: [PATCH 24/61] create api for register road observation --- .../Dashboard/AccidentReceiptController.php | 2 +- .../Dashboard/RoadObservationController.php | 96 ++++++++++++++++++- .../V3/AccidentReceipt/UpdateRequest.php | 6 +- .../V3/RoadObservation/ReferRequest.php | 29 ++++++ app/Models/RoadObserved.php | 16 ++++ .../Cartables/RoadObservationTableService.php | 42 ++++++++ routes/v3.php | 7 +- 7 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 app/Http/Requests/V3/RoadObservation/ReferRequest.php diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php index 530b4add..5368e931 100644 --- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php @@ -156,7 +156,7 @@ class AccidentReceiptController extends Controller FileFacade::delete($accident->police_file, true); } - if (!$request->report_base) { + if (!$request->report_base && $request->has('police_file')) { FileFacade::delete($accident->police_file, true); $accidentData['police_file'] = FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/"); } diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 1000a9ce..937cdb3b 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -3,14 +3,24 @@ namespace App\Http\Controllers\V3\Dashboard; use App\Exports\V3\RoadObservation\OperatorCartableReport; use App\Exports\V3\RoadObservation\SupervisorCartableReport; +use App\Facades\File\FileFacade; +use App\Facades\Sms\Sms; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\RoadObservation\ReferRequest; use App\Http\Requests\V3\RoadObservation\VerifyBySupervisorRequest; use App\Http\Traits\ApiResponse; +use App\Models\RoadObservationHistory; use App\Models\RoadObserved; +use App\Services\NikarayanService; +use Carbon\Carbon; +use Hekmatinasser\Verta\Verta; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Services\Cartables\RoadObservationTableservice; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Str; use Maatwebsite\Excel\Facades\Excel; +use SoapFault; use Symfony\Component\HttpFoundation\BinaryFileResponse; class RoadObservationController extends Controller @@ -59,10 +69,94 @@ class RoadObservationController extends Controller public function operatorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { - $name = 'گزارش از کارتابل ارزیابی واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; + $name = 'گزارش از کارتابل عملیات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->operatorCartableIndex($request); return Excel::download(new OperatorCartableReport($data['data']), $name); } + public function complaintsIndex(Request $request, RoadObservationTableservice $roadObservationTableservice): JsonResponse + { + return response()->json($roadObservationTableservice->complaintsIndex($request)); + } + + public function register(Request $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse + { + $roadObservedData = [ + 'status' => 0, + 'status_fa' => 'در حال بررسی', + 'rms_status' => $request->rms_status ?? $roadObserved->rms_status, + 'rms_description' => $request->description?? $roadObserved->rms_description, + ]; + + $roadObservedHistoryData = [ + 'user_id' => auth()->user()->id, + 'previous_rms_status' => $roadObserved->rms_status, + 'previous_rms_start_latlng' => $roadObserved->rms_start_latlng, + 'previous_rms_end_latlng' => $roadObserved->rms_end_latlng, + 'previous_rms_description' => $roadObserved->rms_description, + 'new_files' => [] + ]; + + if ($request->rms_status == 1) { + + $files_path = []; + + $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}/"); + + $files_path[0]['path'] = $image_before; + $files_path[1]['path'] = $image_after; + + $files = json_encode($files_path); + $now_date_time = Carbon::now(); + + $roadObservedData['image_before'] = $image_before; + $roadObservedData['image_after'] = $image_after; + $roadObservedData['rms_start_latlng'] = explode(',', $request->start_point); + $roadObservedData['updated_at_fa'] = Verta::instance($now_date_time); + $roadObservedData['rms_last_activity_fa'] = Verta::instance($now_date_time); + $roadObservedData['rms_last_activity'] = $now_date_time; + $roadObservedHistoryData['new_files'] = $files; + } + + $roadObserved->problemHistories()->create($roadObservedHistoryData); + $roadObserved->update($roadObservedData); + + auth()->user()->addActivityComplete(1142); + + try { + $result = $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(); + } + + public function refer(ReferRequest $request, RoadObserved $roadObserved): JsonResponse + { + $roadObserved->problemHistories()->create([ + 'user_id' => auth()->user()->id, + 'action' => 'refer', + 'description' => $request->refer_description, + 'from_edareh' => $roadObserved->edarate_shahri_id, + 'to_edareh' => $request->edarate_shahri_id + ]); + + $roadObserved->update([ + 'edarate_shahri_id' => $request->edarate_shahri_id, + ]); + + auth()->user()->addActivityComplete(1037); + + return $this->successResponse(); + } } diff --git a/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php b/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php index 3b50bdf5..3160896d 100644 --- a/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php +++ b/app/Http/Requests/V3/AccidentReceipt/UpdateRequest.php @@ -35,11 +35,11 @@ class UpdateRequest extends FormRequest 'accident_date' => 'required|date', 'accident_time' => 'required|string', 'report_base' => 'required|in:0,1', - 'police_file' => 'required_if:report_base,0|file|mimes:pdf,jpg,jpeg,png', + 'police_file' => 'file|mimes:pdf,jpg,jpeg,png', 'police_serial' => 'required_if:report_base,0|string', 'police_file_date' => 'required_if:report_base,0|date', - 'damage_picture1' => 'required|file|mimes:pdf,jpg,jpeg,png', - 'damage_picture2' => 'required|file|mimes:pdf,jpg,jpeg,png', + 'damage_picture1' => 'file|mimes:pdf,jpg,jpeg,png', + 'damage_picture2' => 'file|mimes:pdf,jpg,jpeg,png', 'damage_items' => 'required|array', 'damage_items.*.value' => 'required', 'damage_items.*.amount' => 'required', diff --git a/app/Http/Requests/V3/RoadObservation/ReferRequest.php b/app/Http/Requests/V3/RoadObservation/ReferRequest.php new file mode 100644 index 00000000..4db948c2 --- /dev/null +++ b/app/Http/Requests/V3/RoadObservation/ReferRequest.php @@ -0,0 +1,29 @@ +roadObserved->rms_status == 0; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'edarate_shahri_id' => 'required|exists:edarate_shahri,id', + 'refer_description' => 'required|string', + ]; + } +} diff --git a/app/Models/RoadObserved.php b/app/Models/RoadObserved.php index 54fd8c29..60131fd0 100644 --- a/app/Models/RoadObserved.php +++ b/app/Models/RoadObserved.php @@ -2,8 +2,10 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Storage; class RoadObserved extends Model { @@ -99,4 +101,18 @@ class RoadObserved extends Model { return $this->belongsTo('App\Models\EdarateShahri', 'edarate_shahri_id'); } + + protected function imageAfter(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } + + protected function imageBefore(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } } diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index 9b8bbafd..eac2e585 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -88,4 +88,46 @@ class RoadObservationTableService allowedFilters: ['*'], allowedSortings: ['*']); } + + public function complaintsIndex(Request $request) + { + $user = auth()->user(); + + if ($user->hasPermissionTo('show-fast-react')) { + $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('rms_status', '=', 0) + ->whereNotNull('edarate_shahri_id'); + } + elseif ($user->hasPermissionTo('show-fast-react-province')) { + + if (is_null($user->province_id)) { + return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); + } + + $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('rms_status', '=', 0) + ->whereNotNull('edarate_shahri_id') + ->where('road_observeds.province_id', '=', $user->province_id); + + } + elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { + + if (is_null($user->edarate_shahri_id)) { + return $this->errorResponse('اداره ای برای شما در سامانه ثبت نشده است!'); + } + + $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('rms_status', '=', 0) + ->whereNotNull('edarate_shahri_id') + ->where('edarate_shahri_id', '=', $user->edarate_shahri_id); + + } + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'] + ); + } } \ No newline at end of file diff --git a/routes/v3.php b/routes/v3.php index 793ea143..fe623242 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -285,5 +285,10 @@ Route::prefix('road_observations') Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); Route::get('/supervisor_report', 'supervisorCartableReport')->name('report'); Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('permission:show-fast-react|show-fast-react-province'); - Route::get('/operator_report', 'operatorCartableReport')->name('operatorExcelReport'); + Route::get('/complaints_index', 'complaintsIndex') + ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') + ->name('complaintsIndex'); + Route::post('/register/{roadObserved}', 'register') + ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') + ->name('register'); }); From 320efee4c763e1c98e01608bf12400925eda4c07 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Tue, 25 Feb 2025 12:59:26 +0330 Subject: [PATCH 25/61] inprove my view foe Road observation --- .../OperatorCartableReport.php | 10 ++- .../SupervisorCartableReport.php | 8 +- .../OpratorCartableReport.blade.php | 75 +++++++++++++++++ .../SupervisorCartableReport.blade.php | 84 +++++++++++++++++++ 4 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php create mode 100644 resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php diff --git a/app/Exports/V3/RoadObservation/OperatorCartableReport.php b/app/Exports/V3/RoadObservation/OperatorCartableReport.php index 18e0ef18..4cad7e54 100644 --- a/app/Exports/V3/RoadObservation/OperatorCartableReport.php +++ b/app/Exports/V3/RoadObservation/OperatorCartableReport.php @@ -17,15 +17,17 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; class OperatorCartableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawings { - public function __construct(private ?Collection $data){} + public function __construct(private Collection $data){} public function view(): View { - return view ("test", [ - 'data' => $this->data, - ]); + $data = $this->data; + return view('v3.Reports.RoadItems.RoadObservation.OperatorCartableReport', [ + 'data' => $data['activities']['data'], + ]); } + public function registerEvents(): array { return [ diff --git a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php index 224be733..ea3170f4 100644 --- a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php +++ b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php @@ -15,12 +15,14 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; class SupervisorCartableReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings { - public function __construct(private ?Collection $data){} + public function __construct(private Collection $data){} public function view(): View { - return view ("test", [ - 'data' => $this->data, + $data = $this->data; + + return view('v3.Reports.RoadItems.RoadObservation.supervisorCartableReport', [ + 'data' => $data['activities']['data'], ]); } diff --git a/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php new file mode 100644 index 00000000..da390bb1 --- /dev/null +++ b/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php @@ -0,0 +1,75 @@ + + + + + + + + گزارش واکنش سریع + + + + + + +
{{$item->city_fa}} {{$item->axis_name}} {{$item->accident_type_fa}}{{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j') ($item->accident_time)}}{{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}} {{$item->accident_time}} {{$item->sum ?? 0}} {{$item->plaque}} {{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}} {{$item->status_fa}}{{$item->final_amount}}{{$item->deposit_insurance_amount}}{{$item->deposit_daghi_amount}}{{$item->final_amount ?? 0}}{{$item->deposit_insurance_amount ?? 0}}{{$item->deposit_daghi_amount ?? 0}}
گزارش گشت راهداری + فیش + بیمه کسر داغی - شخص -
{{ $road['vasel_shode'] }} + {{ $road['vasel_shode_final'] }} {{ $road['vasel_shode_bimeh'] }} {{ $road['vasel_shode_daghi'] }} - {{ $road['vasel_shode_final'] }}
- نحوه شناسایی خسارت + تعداد نحوه شناسایی خسارت مبلغ کل خسارت ثبت شده (ریال) @@ -74,7 +74,7 @@ بیمه - کسر داغی + داغی
+ + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش کارتابل ارزیابی واکنش سریع +
کد یکتاکد سوانحاستانادارات شهریموضوع گزارشنوع گزارششماره تماس گیرندهوضعیتتاریخ اقدامتوضیحاتتوضیحات کارشناس
{{ $item['id'] ?? '-' }}{{ $item['fk_RegisteredEventMessage'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }}{{ $item['Title'] ?? '-' }}{{ $item['FeatureTypeTitle'] ?? '-' }}{{ $item['MobileForSendEventSms'] ?? '-' }}{{ $item['status_fa'] ?? '-' }}{{ $item['rms_last_activity_fa'] ?? '-' }}{{ $item['rms_description'] ?? '-' }}{{ $item['supervisor_description'] ?? '-' }}
+ + + diff --git a/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php new file mode 100644 index 00000000..4c04abfd --- /dev/null +++ b/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php @@ -0,0 +1,84 @@ + + + + + + + + گزارش واکنش سریع + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ @if ($fromDate == null) + گزارش کارتابل ارزیابی واکنش سریع + @else + گزارش کارتابل ارزیابی واکنش سریع از تاریخ + {{ verta($fromDate)->format('Y/n/j') }} + تا + تاریخ + {{ verta($toDate)->format('Y/n/j') }} + @endif + +
کد یکتاکد پیگیریاستانادارات شهریموضوع گزارشنوع گزارششماره تماس گیرندهوضعیتتاریخ اقدامتوضیحاتتوضیحات کارشناس
{{ $item['id'] ?? '-' }}{{ $item['fk_RegisteredEventMessage'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }}{{ $item['Title'] ?? '-' }}{{ $item['FeatureTypeTitle'] ?? '-' }}{{ $item['MobileForSendEventSms'] ?? '-' }}{{ $item['status_fa'] ?? '-' }}{{ $item['rms_last_activity_fa'] ?? '-' }}{{ $item['rms_description'] ?? '-' }}{{ $item['supervisor_description'] ?? '-' }}
+ + + From 2adf091f7d01bc5661c55162bcd95a24593e532e Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 25 Feb 2025 13:24:14 +0330 Subject: [PATCH 26/61] add column to road observation histories --- .../Dashboard/RoadObservationController.php | 78 +++++++++++++++---- .../V3/RoadObservation/ReferRequest.php | 1 + .../V3/RoadObservation/RestoreRequest.php | 28 +++++++ ...mn_to_road_observation_histories_table.php | 30 +++++++ routes/v3.php | 9 ++- 5 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 app/Http/Requests/V3/RoadObservation/RestoreRequest.php create mode 100644 database/migrations/2025_02_25_114351_add_column_to_road_observation_histories_table.php diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 937cdb3b..77e53de6 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -7,17 +7,21 @@ use App\Facades\File\FileFacade; use App\Facades\Sms\Sms; use App\Http\Controllers\Controller; use App\Http\Requests\V3\RoadObservation\ReferRequest; +use App\Http\Requests\V3\RoadObservation\RestoreRequest; use App\Http\Requests\V3\RoadObservation\VerifyBySupervisorRequest; use App\Http\Traits\ApiResponse; +use App\Models\EdarateShahri; use App\Models\RoadObservationHistory; use App\Models\RoadObserved; +use App\Models\User; use App\Services\NikarayanService; use Carbon\Carbon; use Hekmatinasser\Verta\Verta; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use App\Services\Cartables\RoadObservationTableservice; +use App\Services\Cartables\RoadObservationTableService; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Maatwebsite\Excel\Facades\Excel; use SoapFault; @@ -27,10 +31,9 @@ class RoadObservationController extends Controller { use ApiResponse; - public function supervisorIndex (Request $request,RoadObservationTableservice $roadObservationTableservice ): JsonResponse + public function supervisorIndex (Request $request,RoadObservationTableService $roadObservationTableService ): JsonResponse { - $data = $roadObservationTableservice->supervisorCartableIndex($request); - return response()->json($data); + return response()->json($roadObservationTableService->supervisorCartableIndex($request)); } public function verifyBySupervisor (VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse @@ -49,11 +52,9 @@ class RoadObservationController extends Controller auth()->user()->addActivityComplete(1138); return $this->successResponse(); - } public function supervisorCartableReport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse - { $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->supervisorCartableIndex($request, true); @@ -63,8 +64,7 @@ class RoadObservationController extends Controller public function operatorIndex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse { - $data = $roadObservationTableService->operatorCartableIndex($request); - return response()->json($data); + return response()->json($roadObservationTableService->operatorCartableIndex($request)); } public function operatorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse @@ -74,7 +74,7 @@ class RoadObservationController extends Controller return Excel::download(new OperatorCartableReport($data['data']), $name); } - public function complaintsIndex(Request $request, RoadObservationTableservice $roadObservationTableservice): JsonResponse + public function complaintsIndex(Request $request, RoadObservationTableService $roadObservationTableservice): JsonResponse { return response()->json($roadObservationTableservice->complaintsIndex($request)); } @@ -128,7 +128,7 @@ class RoadObservationController extends Controller auth()->user()->addActivityComplete(1142); try { - $result = $nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, json_encode($roadObservedHistoryData['new_files'])); + $nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, json_encode($roadObservedHistoryData['new_files'])); } catch (SoapFault $e) { @@ -142,21 +142,73 @@ class RoadObservationController extends Controller public function refer(ReferRequest $request, RoadObserved $roadObserved): JsonResponse { - $roadObserved->problemHistories()->create([ + RoadObservationHistory::query()->create([ + 'id' => $roadObserved->id, 'user_id' => auth()->user()->id, 'action' => 'refer', 'description' => $request->refer_description, 'from_edareh' => $roadObserved->edarate_shahri_id, - 'to_edareh' => $request->edarate_shahri_id + 'to_edareh' => $request->edarate_shahri_id, + 'from_province' => $roadObserved->province_id, + 'to_province' => $request->province_id ]); $roadObserved->update([ 'edarate_shahri_id' => $request->edarate_shahri_id, + 'province_id' => $request->province_id, ]); auth()->user()->addActivityComplete(1037); return $this->successResponse(); } -} + public function referList(Request $request, RoadObserved $roadObserved): JsonResponse + { + $data = RoadObservationHistory::query() + ->where('id', '=', $roadObserved->id) + ->where('action', '=', 'refer') + ->get(); + foreach ($data as $key => $value) { + $data[$key]->from_edareh = EdarateShahri::find($value->from_edareh)->name_fa; + $data[$key]->to_edareh = EdarateShahri::find($value->to_edareh)->name_fa; + $user = User::find($value->user_id); + $data[$key]->user = $user->first_name . ' ' . $user->last_name; + } + return $this->successResponse($data); + } + + public function restore(RestoreRequest $request, RoadObserved $roadObserved): JsonResponse + { + if ($roadObserved->image_before) { + FileFacade::delete($roadObserved->image_before); + } + + if ($roadObserved->image_after) { + FileFacade::delete($roadObserved->image_after); + } + + $roadObserved->update([ + 'image_before' => null, + 'image_after' => null, + 'rms_last_activity' => null, + 'rms_last_activity_fa' => null, + 'updated_at_fa' => null, + 'updated_at' => null, + 'rms_status' => 0, + 'status' => null, + 'status_fa' => null, + ]); + + RoadObservationHistory::query()->create([ + 'id' => $roadObserved->id, + 'user_id' => auth()->user()->id, + 'action' => 'restore', + 'description' => $request->restore_description, + ]); + + auth()->user()->addActivityComplete(1141); + + return $this->successResponse(); + } +} diff --git a/app/Http/Requests/V3/RoadObservation/ReferRequest.php b/app/Http/Requests/V3/RoadObservation/ReferRequest.php index 4db948c2..33e2bc83 100644 --- a/app/Http/Requests/V3/RoadObservation/ReferRequest.php +++ b/app/Http/Requests/V3/RoadObservation/ReferRequest.php @@ -23,6 +23,7 @@ class ReferRequest extends FormRequest { return [ 'edarate_shahri_id' => 'required|exists:edarate_shahri,id', + 'province_id' => 'required|exists:provinces,id', 'refer_description' => 'required|string', ]; } diff --git a/app/Http/Requests/V3/RoadObservation/RestoreRequest.php b/app/Http/Requests/V3/RoadObservation/RestoreRequest.php new file mode 100644 index 00000000..651de88a --- /dev/null +++ b/app/Http/Requests/V3/RoadObservation/RestoreRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'restore_description' => 'required|string', + ]; + } +} diff --git a/database/migrations/2025_02_25_114351_add_column_to_road_observation_histories_table.php b/database/migrations/2025_02_25_114351_add_column_to_road_observation_histories_table.php new file mode 100644 index 00000000..9e0037c8 --- /dev/null +++ b/database/migrations/2025_02_25_114351_add_column_to_road_observation_histories_table.php @@ -0,0 +1,30 @@ +string('from_province')->nullable(); + $table->string('to_province')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('road_observation_histories', function (Blueprint $table) { + $table->dropColumn('from_province'); + $table->dropColumn('to_province'); + }); + } +}; diff --git a/routes/v3.php b/routes/v3.php index fe623242..86e0c5fc 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -283,12 +283,19 @@ Route::prefix('road_observations') ->group(function () { Route::get('/supervisor_index', 'supervisorIndex')->name('supervisorIndex')->middleware('permission:supervise-fast-react-province|supervise-fast-react'); Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); - Route::get('/supervisor_report', 'supervisorCartableReport')->name('report'); + Route::get('/supervisor_report', 'supervisorCartableReport')->name('supervisorCartableReport'); Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('permission:show-fast-react|show-fast-react-province'); + Route::get('/operator_report','operatorCartableReport')->name('operatorCartableReport'); Route::get('/complaints_index', 'complaintsIndex') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('complaintsIndex'); Route::post('/register/{roadObserved}', 'register') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('register'); + Route::post('/refer/{roadObserved}', 'refer') + ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') + ->name('refer'); + Route::post('/restore/{roadObserved}', 'restore') + ->middleware('permission:restore-fast-react') + ->name('restore'); }); From d0c9908e6ca90cc6ff6808296d94c0cff30ccab4 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 25 Feb 2025 15:03:30 +0330 Subject: [PATCH 27/61] create complaints blade --- .../V3/RoadObservation/ComplaintsReport.php | 67 +++++++++++++ .../Dashboard/RoadObservationController.php | 38 +++++--- .../Cartables/RoadObservationTableService.php | 23 +++-- .../Cartables/RoadPatrolTableService.php | 6 +- .../ComplaintsReport.blade.php | 93 +++++++++++++++++++ routes/v3.php | 1 + 6 files changed, 204 insertions(+), 24 deletions(-) create mode 100644 app/Exports/V3/RoadObservation/ComplaintsReport.php create mode 100644 resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php diff --git a/app/Exports/V3/RoadObservation/ComplaintsReport.php b/app/Exports/V3/RoadObservation/ComplaintsReport.php new file mode 100644 index 00000000..e8012634 --- /dev/null +++ b/app/Exports/V3/RoadObservation/ComplaintsReport.php @@ -0,0 +1,67 @@ + $this->data, + ]); + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + $event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial'); + $event->sheet->getDelegate()->getStyle('A:U') + ->getAlignment() + ->setHorizontal(Alignment::HORIZONTAL_CENTER); + + $event->sheet->getDelegate()->getStyle('A:U') + ->getAlignment() + ->setVertical(Alignment::VERTICAL_CENTER); + } + ]; + } + + 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('q1'); + return [$drawing, $drawing2]; + } +} diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 77e53de6..457f3d75 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -1,6 +1,7 @@ json($roadObservationTableservice->complaintsIndex($request)); + return response()->json($roadObservationTableService->complaintsIndex($request)); + } + + public function complaintsReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + { + $name = 'گزارش از رسیدگی به شکایات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; + $data = $roadObservationTableService->complaintsIndex($request); + return Excel::download(new ComplaintsReport($data['data']), $name); } public function register(Request $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse @@ -142,8 +151,7 @@ class RoadObservationController extends Controller public function refer(ReferRequest $request, RoadObserved $roadObserved): JsonResponse { - RoadObservationHistory::query()->create([ - 'id' => $roadObserved->id, + $roadObserved->problemHistories()->create([ 'user_id' => auth()->user()->id, 'action' => 'refer', 'description' => $request->refer_description, @@ -165,17 +173,18 @@ class RoadObservationController extends Controller public function referList(Request $request, RoadObserved $roadObserved): JsonResponse { - $data = RoadObservationHistory::query() - ->where('id', '=', $roadObserved->id) - ->where('action', '=', 'refer') - ->get(); + $referList = []; + $data = $roadObserved->problemHistories()->where('action', '=', 'refer')->get(); + foreach ($data as $key => $value) { - $data[$key]->from_edareh = EdarateShahri::find($value->from_edareh)->name_fa; - $data[$key]->to_edareh = EdarateShahri::find($value->to_edareh)->name_fa; - $user = User::find($value->user_id); - $data[$key]->user = $user->first_name . ' ' . $user->last_name; + $referList[$key]['from_edareh'] = EdarateShahri::query()->find($value->from_edareh)->name_fa; + $referList[$key]['to_edareh'] = EdarateShahri::query()->find($value->to_edareh)->name_fa; + $referList[$key]['from_province'] = Province::query()->find($value->from_province)->name_fa; + $referList[$key]['to_province'] = Province::query()->find($value->to_province)->name_fa; + $user = User::query()->find($value->user_id); + $referList[$key]['user'] = $user->first_name . ' ' . $user->last_name; } - return $this->successResponse($data); + return $this->successResponse($referList); } public function restore(RestoreRequest $request, RoadObserved $roadObserved): JsonResponse @@ -200,8 +209,7 @@ class RoadObservationController extends Controller 'status_fa' => null, ]); - RoadObservationHistory::query()->create([ - 'id' => $roadObserved->id, + $roadObserved->problemHistories()->create([ 'user_id' => auth()->user()->id, 'action' => 'restore', 'description' => $request->restore_description, diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index eac2e585..0f733d94 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -26,7 +26,8 @@ class RoadObservationTableService if ($user->hasPermissionTo('supervise-fast-react')) { $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') - ->whereNotNull('road_observeds.status'); + ->whereNotNull('road_observeds.status') + ->select($fields); } elseif ($user->hasPermissionTo('supervise-fast-react-province')) { @@ -37,7 +38,8 @@ class RoadObservationTableService $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('road_observeds.province_id', $user->province_id) - ->whereNotNull('road_observeds.status'); + ->whereNotNull('road_observeds.status') + ->select($fields); } return DataTableFacade::run( @@ -96,7 +98,10 @@ class RoadObservationTableService if ($user->hasPermissionTo('show-fast-react')) { $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) - ->whereNotNull('edarate_shahri_id'); + ->whereNotNull('edarate_shahri_id') + ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, + status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'); } elseif ($user->hasPermissionTo('show-fast-react-province')) { @@ -106,8 +111,11 @@ class RoadObservationTableService $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) - ->whereNotNull('edarate_shahri_id') - ->where('road_observeds.province_id', '=', $user->province_id); + ->whereNotNull('road_observeds.province_id') + ->where('road_observeds.province_id', '=', $user->province_id) + ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, + status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'); } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { @@ -119,7 +127,10 @@ class RoadObservationTableService $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) ->whereNotNull('edarate_shahri_id') - ->where('edarate_shahri_id', '=', $user->edarate_shahri_id); + ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) + ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, + status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'); } diff --git a/app/Services/Cartables/RoadPatrolTableService.php b/app/Services/Cartables/RoadPatrolTableService.php index c6f38395..d43a45d7 100644 --- a/app/Services/Cartables/RoadPatrolTableService.php +++ b/app/Services/Cartables/RoadPatrolTableService.php @@ -21,7 +21,7 @@ class RoadPatrolTableService $query = RoadPatrol::query() ->select([ 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', - 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points,' + 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points' ]) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } @@ -32,7 +32,7 @@ class RoadPatrolTableService $query = RoadPatrol::query() ->select([ 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', - 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points,' + 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points' ]) ->where('province_id', '=', $user->province_id) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); @@ -55,7 +55,7 @@ class RoadPatrolTableService $query = RoadPatrol::query() ->select([ 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', - 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points,' + 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points' ]) ->where('operator_id', '=', auth()->user()->id) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); diff --git a/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php b/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php new file mode 100644 index 00000000..e2d061ba --- /dev/null +++ b/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php @@ -0,0 +1,93 @@ + + + + + + + + گزارش واکنش سریع + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش رسیدگی به شکایات واکنش سریع +
کد + سوانح + استان + + ادارات شهری + + موضوع گزارش + + نوع گزارش + توضیح گزارش + موقعیت مکانی + شماره تماس گیرنده + تاریخ ثبت گزارش
{{ $item['fk_RegisteredEventMessage'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }}{{ $item['Title'] ?? '-' }}{{ $item['FeatureTypeTitle'] ?? '-' }}{{ $item['Description'] ?? '-' }}{{ isset($item['lat']) && isset($item['lng']) ? $item['lat'] . ' ' . $item['lng'] : '-' }}{{ $item['MobileForSendEventSms'] ?? '-' }}{{ $item['created_at'] ? verta($item['created_at'])->format('Y/n/j H:i:s') : '-' }}
+ + diff --git a/routes/v3.php b/routes/v3.php index 86e0c5fc..b498fc9b 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -298,4 +298,5 @@ Route::prefix('road_observations') Route::post('/restore/{roadObserved}', 'restore') ->middleware('permission:restore-fast-react') ->name('restore'); + Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport'); }); From a47f4cac4891f517e699ea1d9c202a1f163095ec Mon Sep 17 00:00:00 2001 From: joddyabott Date: Tue, 25 Feb 2025 15:55:11 +0330 Subject: [PATCH 28/61] debug my code --- app/Exports/V3/RoadObservation/OperatorCartableReport.php | 4 ++-- app/Exports/V3/RoadObservation/SupervisorCartableReport.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Exports/V3/RoadObservation/OperatorCartableReport.php b/app/Exports/V3/RoadObservation/OperatorCartableReport.php index 4cad7e54..fbf560f3 100644 --- a/app/Exports/V3/RoadObservation/OperatorCartableReport.php +++ b/app/Exports/V3/RoadObservation/OperatorCartableReport.php @@ -23,8 +23,8 @@ class OperatorCartableReport implements FromView, ShouldAutoSize, WithEvents, Wi { $data = $this->data; - return view('v3.Reports.RoadItems.RoadObservation.OperatorCartableReport', [ - 'data' => $data['activities']['data'], + return view('v3.Reports.RoadObservation.OperatorCartableReport', [ + 'data' => $data, ]); } diff --git a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php index ea3170f4..036edb76 100644 --- a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php +++ b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php @@ -21,8 +21,8 @@ class SupervisorCartableReport implements FromView, WithEvents, ShouldAutoSize, { $data = $this->data; - return view('v3.Reports.RoadItems.RoadObservation.supervisorCartableReport', [ - 'data' => $data['activities']['data'], + return view('v3.Reports.RoadObservation.SupervisorCartableReport', [ + 'data' => $data, ]); } From c4a50de162b76f8d36e667c65453ad7eba9afcaf Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 25 Feb 2025 15:58:46 +0330 Subject: [PATCH 29/61] debug --- .../V3/Dashboard/RoadObservationController.php | 10 +++++----- app/Services/Cartables/RoadItemTableService.php | 6 +++--- .../Cartables/RoadObservationTableService.php | 15 +++++++-------- routes/v3.php | 3 +++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 457f3d75..1182a8fb 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -33,19 +33,19 @@ class RoadObservationController extends Controller { use ApiResponse; - public function supervisorIndex (Request $request,RoadObservationTableService $roadObservationTableService ): JsonResponse + public function supervisorIndex(Request $request,RoadObservationTableService $roadObservationTableService ): JsonResponse { return response()->json($roadObservationTableService->supervisorCartableIndex($request)); } - public function verifyBySupervisor (VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse + public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse { $statusFa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید'; $roadObserved->update([ 'status' => $request->verify, 'status_fa' => $statusFa, - 'supervisor_id' => auth()->user()->id(), + 'supervisor_id' => auth()->user()->id, 'supervisor_name' => auth()->user()->name, 'supervisor_description' => $request->description, 'supervising_time' => now(), @@ -56,7 +56,7 @@ class RoadObservationController extends Controller return $this->successResponse(); } - public function supervisorCartableReport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + public function supervisorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->supervisorCartableIndex($request, true); @@ -171,7 +171,7 @@ class RoadObservationController extends Controller return $this->successResponse(); } - public function referList(Request $request, RoadObserved $roadObserved): JsonResponse + public function referList(RoadObserved $roadObserved): JsonResponse { $referList = []; $data = $roadObserved->problemHistories()->where('action', '=', 'refer')->get(); diff --git a/app/Services/Cartables/RoadItemTableService.php b/app/Services/Cartables/RoadItemTableService.php index c0a929fd..0ff0a29f 100644 --- a/app/Services/Cartables/RoadItemTableService.php +++ b/app/Services/Cartables/RoadItemTableService.php @@ -21,7 +21,7 @@ class RoadItemTableService if ($user->hasPermissionTo('show-road-item-supervise-cartable')) { $query = RoadItemsProject::query() - ->select(['id', 'province_fa', 'edarat_name', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', 'province_fa', 'edarat_name', 'item_id', 'item_fa', 'sub_item_id', '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) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); @@ -31,7 +31,7 @@ class RoadItemTableService return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } $query = RoadItemsProject::query() - ->select(['id', 'province_fa', 'edarat_name', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', 'province_fa', 'edarat_name', 'item_id', 'item_fa', 'sub_item_id', '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('province_id', auth()->user()->province_id) @@ -53,7 +53,7 @@ class RoadItemTableService $allowedSortings = ['*']; $query = RoadItemsProject::query() - ->select(['id', 'supervisor_description', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', 'supervisor_description', 'item_id', 'item_fa', 'sub_item_id', '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/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index 0f733d94..a245656a 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -66,11 +66,7 @@ class RoadObservationTableService ->whereNotNull('road_observeds.province_id') ->whereNotNull('status') ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') - ->select($fields) - ->addSelect([ - DB::raw("CONCAT('https://rms.rmto.ir/', image_before) as image_before"), - DB::raw("CONCAT('https://rms.rmto.ir/', image_after) as image_after") - ]); + ->select($fields); if ($user->hasPermissionTo('show-fast-react-province')) { if (is_null($user->province_id)) { @@ -101,7 +97,8 @@ class RoadObservationTableService ->whereNotNull('edarate_shahri_id') ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, - status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'); + status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' + ); } elseif ($user->hasPermissionTo('show-fast-react-province')) { @@ -115,7 +112,8 @@ class RoadObservationTableService ->where('road_observeds.province_id', '=', $user->province_id) ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, - status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'); + status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' + ); } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { @@ -130,7 +128,8 @@ class RoadObservationTableService ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, - status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'); + status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' + ); } diff --git a/routes/v3.php b/routes/v3.php index b498fc9b..d38b556f 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -295,6 +295,9 @@ Route::prefix('road_observations') Route::post('/refer/{roadObserved}', 'refer') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('refer'); + + Route::get('/refer_list/{roadObserved}', 'referList')->name('referList'); + Route::post('/restore/{roadObserved}', 'restore') ->middleware('permission:restore-fast-react') ->name('restore'); From f2ca87d6aa4385b191ae40f677dd74272e139e7e Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 25 Feb 2025 16:30:05 +0330 Subject: [PATCH 30/61] remove the redundant relation --- .../V3/Dashboard/RoadObservationController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 1182a8fb..ff534f53 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -22,9 +22,6 @@ use Hekmatinasser\Verta\Verta; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Services\Cartables\RoadObservationTableService; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; use Maatwebsite\Excel\Facades\Excel; use SoapFault; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -151,7 +148,8 @@ class RoadObservationController extends Controller public function refer(ReferRequest $request, RoadObserved $roadObserved): JsonResponse { - $roadObserved->problemHistories()->create([ + RoadObservationHistory::query()->create([ + 'id' => $roadObserved->id, 'user_id' => auth()->user()->id, 'action' => 'refer', 'description' => $request->refer_description, @@ -174,7 +172,9 @@ class RoadObservationController extends Controller public function referList(RoadObserved $roadObserved): JsonResponse { $referList = []; - $data = $roadObserved->problemHistories()->where('action', '=', 'refer')->get(); + $data = RoadObservationHistory::query() + ->where('road_observation_histories.id', $roadObserved->id) + ->where('action', '=', 'refer')->get(); foreach ($data as $key => $value) { $referList[$key]['from_edareh'] = EdarateShahri::query()->find($value->from_edareh)->name_fa; @@ -209,7 +209,8 @@ class RoadObservationController extends Controller 'status_fa' => null, ]); - $roadObserved->problemHistories()->create([ + RoadObservationHistory::query()->create([ + 'id' => $roadObserved->id, 'user_id' => auth()->user()->id, 'action' => 'restore', 'description' => $request->restore_description, From b5b799ee904528e05cdec0a50de14c410127d2ee Mon Sep 17 00:00:00 2001 From: joddyabott Date: Tue, 25 Feb 2025 16:40:35 +0330 Subject: [PATCH 31/61] debug code for 3 item --- app/Exports/V3/RoadObservation/OperatorCartableReport.php | 4 +++- app/Exports/V3/RoadObservation/SupervisorCartableReport.php | 4 +++- .../Reports/RoadObservation/OpratorCartableReport.blade.php | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Exports/V3/RoadObservation/OperatorCartableReport.php b/app/Exports/V3/RoadObservation/OperatorCartableReport.php index fbf560f3..7dca86d8 100644 --- a/app/Exports/V3/RoadObservation/OperatorCartableReport.php +++ b/app/Exports/V3/RoadObservation/OperatorCartableReport.php @@ -24,7 +24,9 @@ class OperatorCartableReport implements FromView, ShouldAutoSize, WithEvents, Wi $data = $this->data; return view('v3.Reports.RoadObservation.OperatorCartableReport', [ - 'data' => $data, + 'data' => $this->data, + 'fromDate' => $this->data['fromDate'] ?? null, + 'toDate' => $this->data['toDate'] ?? null ]); } diff --git a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php index 036edb76..3ecc88f8 100644 --- a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php +++ b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php @@ -22,7 +22,9 @@ class SupervisorCartableReport implements FromView, WithEvents, ShouldAutoSize, $data = $this->data; return view('v3.Reports.RoadObservation.SupervisorCartableReport', [ - 'data' => $data, + 'data' => $this->data, + 'fromDate' => $this->data['fromDate'] ?? null, + 'toDate' => $this->data['toDate'] ?? null ]); } diff --git a/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php index da390bb1..4c308f98 100644 --- a/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php @@ -21,18 +21,18 @@ - - - From 8c2491d38084535aca3749a8a26c72539b8756b7 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Wed, 26 Feb 2025 10:24:53 +0330 Subject: [PATCH 32/61] fix code for blade and report --- .../RoadObservation/OperatorCartableReport.php | 8 ++------ .../RoadObservation/SupervisorCartableReport.php | 4 +--- .../V3/Dashboard/RoadObservationController.php | 2 +- .../OpratorCartableReport.blade.php | 8 ++++---- .../SupervisorCartableReport.blade.php | 16 ++++------------ 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/app/Exports/V3/RoadObservation/OperatorCartableReport.php b/app/Exports/V3/RoadObservation/OperatorCartableReport.php index 7dca86d8..6285c700 100644 --- a/app/Exports/V3/RoadObservation/OperatorCartableReport.php +++ b/app/Exports/V3/RoadObservation/OperatorCartableReport.php @@ -21,13 +21,9 @@ class OperatorCartableReport implements FromView, ShouldAutoSize, WithEvents, Wi public function view(): View { - $data = $this->data; - return view('v3.Reports.RoadObservation.OperatorCartableReport', [ 'data' => $this->data, - 'fromDate' => $this->data['fromDate'] ?? null, - 'toDate' => $this->data['toDate'] ?? null - ]); + ]); } public function registerEvents(): array @@ -67,7 +63,7 @@ class OperatorCartableReport implements FromView, ShouldAutoSize, WithEvents, Wi $drawing2->setHeight(50); $drawing2->setOffsetX(5); $drawing2->setOffsetY(5); - $drawing2->setCoordinates('q1'); + $drawing2->setCoordinates('K1'); return [$drawing, $drawing2]; } diff --git a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php index 3ecc88f8..4aa2b072 100644 --- a/app/Exports/V3/RoadObservation/SupervisorCartableReport.php +++ b/app/Exports/V3/RoadObservation/SupervisorCartableReport.php @@ -23,8 +23,6 @@ class SupervisorCartableReport implements FromView, WithEvents, ShouldAutoSize, return view('v3.Reports.RoadObservation.SupervisorCartableReport', [ 'data' => $this->data, - 'fromDate' => $this->data['fromDate'] ?? null, - 'toDate' => $this->data['toDate'] ?? null ]); } @@ -65,7 +63,7 @@ class SupervisorCartableReport implements FromView, WithEvents, ShouldAutoSize, $drawing2->setHeight(50); $drawing2->setOffsetX(5); $drawing2->setOffsetY(5); - $drawing2->setCoordinates('q1'); + $drawing2->setCoordinates('K1'); return [$drawing, $drawing2]; } } diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index ff534f53..c8a52bdc 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -56,7 +56,7 @@ class RoadObservationController extends Controller public function supervisorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { $name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d H:i') . '.xlsx'; - $data = $roadObservationTableService->supervisorCartableIndex($request, true); + $data = $roadObservationTableService->supervisorCartableIndex($request); return Excel::download(new SupervisorCartableReport($data['data']), $name); } diff --git a/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php index 4c308f98..e15d1d53 100644 --- a/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php @@ -21,20 +21,20 @@
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
گزارش کارتابل ارزیابی واکنش سریع
- - - diff --git a/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php index 4c04abfd..2ebaab38 100644 --- a/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php @@ -21,28 +21,20 @@
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
- گزارش کارتابل ارزیابی واکنش سریع + گزارش کارتابل عملیات واکنش سریع
- - - From 2b132959d348c349c37084dc957763a609bfe6bd Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 26 Feb 2025 10:56:08 +0330 Subject: [PATCH 33/61] create report cartable --- .../RoadObservationReportController.php | 28 +++++++++ .../Cartables/RoadItemTableService.php | 6 +- .../Cartables/RoadObservationTableService.php | 59 ++++++++++++++++--- 3 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 app/Http/Controllers/V3/Dashboard/Reports/RoadObservationReportController.php diff --git a/app/Http/Controllers/V3/Dashboard/Reports/RoadObservationReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/RoadObservationReportController.php new file mode 100644 index 00000000..eb20abf8 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Reports/RoadObservationReportController.php @@ -0,0 +1,28 @@ +reportIndex($request); + return response()->json($data['data']); + } + + public function excelReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse + { + $name = 'گزارش رسیدگی به شکایات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; + $data = $roadObservationTableService->reportIndex($request); + return Excel::download(new ReportComplaintsExport($data), $name); + } +} diff --git a/app/Services/Cartables/RoadItemTableService.php b/app/Services/Cartables/RoadItemTableService.php index 0ff0a29f..0b64e741 100644 --- a/app/Services/Cartables/RoadItemTableService.php +++ b/app/Services/Cartables/RoadItemTableService.php @@ -21,7 +21,7 @@ class RoadItemTableService if ($user->hasPermissionTo('show-road-item-supervise-cartable')) { $query = RoadItemsProject::query() - ->select(['id', 'province_fa', 'edarat_name', 'item_id', 'item_fa', 'sub_item_id', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', 'province_fa', 'edarat_name', '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) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); @@ -31,7 +31,7 @@ class RoadItemTableService return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } $query = RoadItemsProject::query() - ->select(['id', 'province_fa', 'edarat_name', 'item_id', 'item_fa', 'sub_item_id', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', 'province_fa', 'edarat_name', '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('province_id', auth()->user()->province_id) @@ -53,7 +53,7 @@ class RoadItemTableService $allowedSortings = ['*']; $query = RoadItemsProject::query() - ->select(['id', 'supervisor_description', 'item_id', 'item_fa', 'sub_item_id', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', + ->select(['id', '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/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index a245656a..e70bf2b9 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -19,8 +19,8 @@ class RoadObservationTableService 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', - 'road_observeds.province_id', 'province_fa', 'city_fa', 'edarate_shahri.name_fa', - 'status', 'status_fa', 'supervisor_description', 'supervising_time' + 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa', + 'status', 'status_fa', 'supervisor_description', 'supervising_time', 'image_after', 'image_before' ]; @@ -56,13 +56,13 @@ class RoadObservationTableService $fields = [ 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', - 'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa', - 'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_fa', + 'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa', 'image_after', 'image_before', + 'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time' ]; $query = RoadObserved::query() - ->where('rms_status', '!=', 0) + ->where('rms_status', '<>', 0) ->whereNotNull('road_observeds.province_id') ->whereNotNull('status') ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') @@ -97,7 +97,7 @@ class RoadObservationTableService ->whereNotNull('edarate_shahri_id') ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, - status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' + status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' ); } elseif ($user->hasPermissionTo('show-fast-react-province')) { @@ -112,7 +112,7 @@ class RoadObservationTableService ->where('road_observeds.province_id', '=', $user->province_id) ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, - status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' + status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' ); } @@ -128,7 +128,7 @@ class RoadObservationTableService ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, - status_fa, supervisor_description, rms_description, province_fa, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' + status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' ); } @@ -140,4 +140,47 @@ class RoadObservationTableService allowedSortings: ['*'] ); } + + public function reportIndex(Request $request) + { + $fromDate = $request->from_date . ' 00:00:00'; + $toDate = $request->date_to . ' 23:59:59'; + + $fields = [ + 'fk_RegisteredEventMessage', + 'road_observeds.id', + 'Title', + 'road_observeds.created_at', + 'lat', + 'lng', + 'FeatureTypeTitle', + 'Description', + 'MobileForSendEventSms', + 'road_observeds.province_id', + 'province_fa', + 'city_fa', + 'edarate_shahri.name_fa', + 'rms_last_activity_fa', + 'rms_description' + ]; + + $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('rms_status', "<>", 0) + ->whereNotNull('edarate_shahri_id') + ->whereBetween('road_observeds.created_at', [$fromDate, $toDate]) + ->select($fields); + + $data = DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'] + ); + + return [ + 'data' => $data, + 'fromDate' => $fromDate, + 'toDate' => $toDate, + ]; + } } \ No newline at end of file From 98b3351842cfc4a865c68f3b4afad515a3dcacad Mon Sep 17 00:00:00 2001 From: joddyabott Date: Wed, 26 Feb 2025 13:39:54 +0330 Subject: [PATCH 34/61] fix code for routs and service --- .../VerifyBySupervisorRequest.php | 3 ++- .../Cartables/RoadObservationTableService.php | 21 +++++++------------ routes/v3.php | 18 +++++++++------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php b/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php index e2154f30..db1450cd 100644 --- a/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php +++ b/app/Http/Requests/V3/RoadObservation/VerifyBySupervisorRequest.php @@ -9,10 +9,11 @@ class VerifyBySupervisorRequest extends FormRequest { /** * Determine if the user is authorized to make this request. + * @return bool */ public function authorize(): bool { - return Gate::allows('gate-supervise-road-observed'); + return Gate::allows('gate-supervise-road-observed',$this->roadObserved); } /** diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index e70bf2b9..504ea8e6 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -24,12 +24,12 @@ class RoadObservationTableService ]; - if ($user->hasPermissionTo('supervise-fast-react')) { + if ($user->hasPermissionTo('show-fast-react')) { $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->whereNotNull('road_observeds.status') ->select($fields); } - elseif ($user->hasPermissionTo('supervise-fast-react-province')) + elseif ($user->hasPermissionTo('show-fast-react-province')) { if (is_null($user->province_id)) { @@ -53,6 +53,10 @@ class RoadObservationTableService { $user = auth()->user(); + if (is_null($user->edarate_shahri_id)) { + return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); + } + $fields = [ 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', @@ -66,20 +70,9 @@ class RoadObservationTableService ->whereNotNull('road_observeds.province_id') ->whereNotNull('status') ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') + ->where('edarate_shahri_id', $user->edarate_shahri_id) ->select($fields); - if ($user->hasPermissionTo('show-fast-react-province')) { - if (is_null($user->province_id)) { - return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); - } - $query->where('rms_province_id', $user->province_id); - } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { - if (is_null($user->edarate_shahri_id)) { - return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); - } - $query->where('edarate_shahri_id', $user->edarate_shahri_id); - } - return DataTableFacade::run( $query, $request, diff --git a/routes/v3.php b/routes/v3.php index d38b556f..f4e235f0 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -281,25 +281,29 @@ Route::prefix('road_observations') ->name('roadObservations.') ->controller(RoadObservationController::class) ->group(function () { - Route::get('/supervisor_index', 'supervisorIndex')->name('supervisorIndex')->middleware('permission:supervise-fast-react-province|supervise-fast-react'); + Route::get('/supervisor_index', 'supervisorIndex')->name('supervisorIndex')->middleware('permission:show-fast-react-province|show-fast-react'); Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); - Route::get('/supervisor_report', 'supervisorCartableReport')->name('supervisorCartableReport'); - Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('permission:show-fast-react|show-fast-react-province'); - Route::get('/operator_report','operatorCartableReport')->name('operatorCartableReport'); + Route::get('/supervisor_report', 'supervisorCartableReport')->name('supervisorCartableReport')->middleware('permission:show-fast-react-province|show-fast-react'); + Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('permission:show-fast-react-edarate-shahri'); + Route::get('/operator_report','operatorCartableReport')->name('operatorCartableReport')->middleware('permission:show-fast-react-edarate-shahri'); Route::get('/complaints_index', 'complaintsIndex') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('complaintsIndex'); Route::post('/register/{roadObserved}', 'register') - ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') + ->middleware('permission:show-fast-react-edarate-shahri') ->name('register'); Route::post('/refer/{roadObserved}', 'refer') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('refer'); - Route::get('/refer_list/{roadObserved}', 'referList')->name('referList'); + Route::get('/refer_list/{roadObserved}', 'referList') + ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') + ->name('referList'); Route::post('/restore/{roadObserved}', 'restore') ->middleware('permission:restore-fast-react') ->name('restore'); - Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport'); + + Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport') + ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react'); }); From 3028d6a3ee23cfaa250ac434e62dc61421f6e277 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 26 Feb 2025 16:02:16 +0330 Subject: [PATCH 35/61] debug intern mistakes --- .../Dashboard/RoadObservationController.php | 3 +- .../V3/RoadObservation/RegisterRequest.php | 32 +++++++++++++++++++ app/Services/DataTable/Filter/ApplyFilter.php | 2 +- .../AccidentReceipt/DataTableReport.blade.php | 18 +++++++---- ...e.php => OperatorCartableReport.blade.php} | 0 routes/v3.php | 2 +- 6 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 app/Http/Requests/V3/RoadObservation/RegisterRequest.php rename resources/views/v3/Reports/RoadObservation/{OpratorCartableReport.blade.php => OperatorCartableReport.blade.php} (100%) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index c8a52bdc..00b39cab 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -8,6 +8,7 @@ use App\Facades\File\FileFacade; use App\Facades\Sms\Sms; use App\Http\Controllers\Controller; use App\Http\Requests\V3\RoadObservation\ReferRequest; +use App\Http\Requests\V3\RoadObservation\RegisterRequest; use App\Http\Requests\V3\RoadObservation\RestoreRequest; use App\Http\Requests\V3\RoadObservation\VerifyBySupervisorRequest; use App\Http\Traits\ApiResponse; @@ -85,7 +86,7 @@ class RoadObservationController extends Controller return Excel::download(new ComplaintsReport($data['data']), $name); } - public function register(Request $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse + public function register(RegisterRequest $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse { $roadObservedData = [ 'status' => 0, diff --git a/app/Http/Requests/V3/RoadObservation/RegisterRequest.php b/app/Http/Requests/V3/RoadObservation/RegisterRequest.php new file mode 100644 index 00000000..68f93dae --- /dev/null +++ b/app/Http/Requests/V3/RoadObservation/RegisterRequest.php @@ -0,0 +1,32 @@ +|string> + */ + public function rules(): array + { + return [ + 'rms_status' => 'required|in:1,2', + 'rms_description' => 'required_if:rms_status,1|string', + 'image_before' => 'required_if:rms_status,1|file|mimes:jpg,jpeg,png', + 'image_after' => 'required_if:rms_status,1|file|mimes:jpg,jpeg,png', + 'start_point' => 'required_if:rms_status,1|string', + ]; + } +} diff --git a/app/Services/DataTable/Filter/ApplyFilter.php b/app/Services/DataTable/Filter/ApplyFilter.php index 971abccb..60ac88ea 100644 --- a/app/Services/DataTable/Filter/ApplyFilter.php +++ b/app/Services/DataTable/Filter/ApplyFilter.php @@ -66,7 +66,7 @@ class ApplyFilter } $relation = $this->filter->getRelation(); - return $relation ? $this->applyFilterToRelation($relation) : $this->searchFilter->apply(); + return method_exists($this->query->getModel(), $relation) ? $this->applyFilterToRelation($relation) : $this->searchFilter->apply(); } protected function applyFilterToRelation(string $relation): Builder diff --git a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php index 5d0a85fd..134166b1 100644 --- a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php @@ -26,15 +26,18 @@ + + + + - - - + + @@ -45,15 +48,18 @@ + + + + - - - + + @endforeach diff --git a/resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/OperatorCartableReport.blade.php similarity index 100% rename from resources/views/v3/Reports/RoadObservation/OpratorCartableReport.blade.php rename to resources/views/v3/Reports/RoadObservation/OperatorCartableReport.blade.php diff --git a/routes/v3.php b/routes/v3.php index f4e235f0..f03cfe2e 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -282,7 +282,7 @@ Route::prefix('road_observations') ->controller(RoadObservationController::class) ->group(function () { Route::get('/supervisor_index', 'supervisorIndex')->name('supervisorIndex')->middleware('permission:show-fast-react-province|show-fast-react'); - Route::post('/verify/{road_observed}', 'verifyBySupervisor')->name('verifyBySupervisor'); + Route::post('/verify/{roadObserved}', 'verifyBySupervisor')->name('verifyBySupervisor'); Route::get('/supervisor_report', 'supervisorCartableReport')->name('supervisorCartableReport')->middleware('permission:show-fast-react-province|show-fast-react'); Route::get('/operator_index','operatorIndex')->name('operatorIndex')->middleware('permission:show-fast-react-edarate-shahri'); Route::get('/operator_report','operatorCartableReport')->name('operatorCartableReport')->middleware('permission:show-fast-react-edarate-shahri'); From 10344816d5b08a7e633c94280d415f145b46d154 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Wed, 26 Feb 2025 16:33:47 +0330 Subject: [PATCH 36/61] create route and controller for loglist --- app/Http/Controllers/V3/LogListController.php | 18 ++++++++++++++++++ routes/v3.php | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/Http/Controllers/V3/LogListController.php diff --git a/app/Http/Controllers/V3/LogListController.php b/app/Http/Controllers/V3/LogListController.php new file mode 100644 index 00000000..b383924e --- /dev/null +++ b/app/Http/Controllers/V3/LogListController.php @@ -0,0 +1,18 @@ +successResponse(LogList::all('description','log_unique_code')); + } +} diff --git a/routes/v3.php b/routes/v3.php index f4e235f0..2df8a967 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -16,6 +16,7 @@ use App\Http\Controllers\V3\Dashboard\RoadObservationController; use App\Http\Controllers\V3\Dashboard\RoadPatrolProjectController; use App\Http\Controllers\V3\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; +use App\Http\Controllers\V3\LogListController; use App\Http\Controllers\V3\ProfileController; use App\Http\Controllers\V3\RahdaranController; use Illuminate\Support\Facades\Route; @@ -307,3 +308,10 @@ Route::prefix('road_observations') Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react'); }); + +Route::prefix('log_list') + ->name('logList.') + ->controller(LogListController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + }); From 3fb6c61835584d7e27ee503e3a45fc9b6adbe440 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 26 Feb 2025 17:09:44 +0330 Subject: [PATCH 37/61] debuge refer list --- .../V3/Dashboard/RoadObservationController.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 00b39cab..8fc65f1f 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -172,20 +172,22 @@ class RoadObservationController extends Controller public function referList(RoadObserved $roadObserved): JsonResponse { - $referList = []; $data = RoadObservationHistory::query() ->where('road_observation_histories.id', $roadObserved->id) - ->where('action', '=', 'refer')->get(); + ->where('action', '=', 'refer')->get([ + 'created_at', 'description', 'from_edareh', 'to_edareh', + 'from_province', 'to_province', 'user_id' + ]); foreach ($data as $key => $value) { - $referList[$key]['from_edareh'] = EdarateShahri::query()->find($value->from_edareh)->name_fa; - $referList[$key]['to_edareh'] = EdarateShahri::query()->find($value->to_edareh)->name_fa; - $referList[$key]['from_province'] = Province::query()->find($value->from_province)->name_fa; - $referList[$key]['to_province'] = Province::query()->find($value->to_province)->name_fa; + $data[$key]->from_edareh = EdarateShahri::query()->find($value->from_edareh)->name_fa; + $data[$key]->to_edareh = EdarateShahri::query()->find($value->to_edareh)->name_fa; + $data[$key]->from_province = EdarateShahri::query()->find($value->from_province)->name_fa; + $data[$key]->to_province = EdarateShahri::query()->find($value->to_province)->name_fa; $user = User::query()->find($value->user_id); - $referList[$key]['user'] = $user->first_name . ' ' . $user->last_name; + $data[$key]->user = $user->first_name . ' ' . $user->last_name; } - return $this->successResponse($referList); + return $this->successResponse($data); } public function restore(RestoreRequest $request, RoadObserved $roadObserved): JsonResponse From fc747ae68bca4a0ec815b4b875e741b4dd52a673 Mon Sep 17 00:00:00 2001 From: Witel Group Date: Sat, 1 Mar 2025 06:40:53 +0000 Subject: [PATCH 38/61] debug the operator cartable logic --- .../Dashboard/RoadObservationController.php | 50 +++++++++----- .../V3/RoadObservation/RegisterRequest.php | 6 +- .../V3/RoadObservation/RestoreRequest.php | 2 +- app/Models/RoadObserved.php | 3 + .../Cartables/RoadObservationTableService.php | 67 ++++++++++++++----- routes/v3.php | 2 + 6 files changed, 93 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 8fc65f1f..278333c7 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -64,11 +64,19 @@ class RoadObservationController extends Controller public function operatorIndex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse { + if (is_null(auth()->user()->edarate_shahri_id)) { + return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); + } + return response()->json($roadObservationTableService->operatorCartableIndex($request)); } public function operatorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { + if (is_null(auth()->user()->edarate_shahri_id)) { + return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); + } + $name = 'گزارش از کارتابل عملیات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->operatorCartableIndex($request); return Excel::download(new OperatorCartableReport($data['data']), $name); @@ -86,13 +94,18 @@ class RoadObservationController extends Controller return Excel::download(new ComplaintsReport($data['data']), $name); } + public function show(RoadObserved $roadObserved): JsonResponse + { + return $this->successResponse($roadObserved); + } + public function register(RegisterRequest $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse { $roadObservedData = [ 'status' => 0, 'status_fa' => 'در حال بررسی', 'rms_status' => $request->rms_status ?? $roadObserved->rms_status, - 'rms_description' => $request->description?? $roadObserved->rms_description, + 'rms_description' => $request->rms_description ?? $roadObserved->rms_description, ]; $roadObservedHistoryData = [ @@ -101,7 +114,7 @@ class RoadObservationController extends Controller 'previous_rms_start_latlng' => $roadObserved->rms_start_latlng, 'previous_rms_end_latlng' => $roadObserved->rms_end_latlng, 'previous_rms_description' => $roadObserved->rms_description, - 'new_files' => [] + 'new_files' => json_encode([]) ]; if ($request->rms_status == 1) { @@ -111,17 +124,21 @@ 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}/"); + if ($request->has('image_before')) { + $image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}/"); + $roadObservedData['image_before'] = $image_before; + $files_path[0]['path'] = $image_before; + } - $files_path[0]['path'] = $image_before; - $files_path[1]['path'] = $image_after; + if ($request->has('image_after')) { + $image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}/"); + $roadObservedData['image_after'] = $image_after; + $files_path[1]['path'] = $image_after; + } $files = json_encode($files_path); $now_date_time = Carbon::now(); - $roadObservedData['image_before'] = $image_before; - $roadObservedData['image_after'] = $image_after; $roadObservedData['rms_start_latlng'] = explode(',', $request->start_point); $roadObservedData['updated_at_fa'] = Verta::instance($now_date_time); $roadObservedData['rms_last_activity_fa'] = Verta::instance($now_date_time); @@ -149,6 +166,8 @@ class RoadObservationController extends Controller public function refer(ReferRequest $request, RoadObserved $roadObserved): JsonResponse { + $province = Province::query()->find($request->province_id); + RoadObservationHistory::query()->create([ 'id' => $roadObserved->id, 'user_id' => auth()->user()->id, @@ -157,12 +176,13 @@ class RoadObservationController extends Controller 'from_edareh' => $roadObserved->edarate_shahri_id, 'to_edareh' => $request->edarate_shahri_id, 'from_province' => $roadObserved->province_id, - 'to_province' => $request->province_id + 'to_province' => $province->id ]); $roadObserved->update([ 'edarate_shahri_id' => $request->edarate_shahri_id, - 'province_id' => $request->province_id, + 'province_id' => $province->id, + 'province_fa' => $province->name_fa, ]); auth()->user()->addActivityComplete(1037); @@ -173,17 +193,17 @@ class RoadObservationController extends Controller public function referList(RoadObserved $roadObserved): JsonResponse { $data = RoadObservationHistory::query() - ->where('road_observation_histories.id', $roadObserved->id) + ->where('id', '=', $roadObserved->id) ->where('action', '=', 'refer')->get([ 'created_at', 'description', 'from_edareh', 'to_edareh', 'from_province', 'to_province', 'user_id' ]); foreach ($data as $key => $value) { - $data[$key]->from_edareh = EdarateShahri::query()->find($value->from_edareh)->name_fa; - $data[$key]->to_edareh = EdarateShahri::query()->find($value->to_edareh)->name_fa; - $data[$key]->from_province = EdarateShahri::query()->find($value->from_province)->name_fa; - $data[$key]->to_province = EdarateShahri::query()->find($value->to_province)->name_fa; + $data[$key]->from_edareh = EdarateShahri::query()->find($value->from_edareh)->name_fa ?? null; + $data[$key]->to_edareh = EdarateShahri::query()->find($value->to_edareh)->name_fa ?? null; + $data[$key]->from_province = Province::query()->find($value->from_province)->name_fa ?? null; + $data[$key]->to_province = Province::query()->find($value->to_province)->name_fa ?? null; $user = User::query()->find($value->user_id); $data[$key]->user = $user->first_name . ' ' . $user->last_name; } diff --git a/app/Http/Requests/V3/RoadObservation/RegisterRequest.php b/app/Http/Requests/V3/RoadObservation/RegisterRequest.php index 68f93dae..f2522339 100644 --- a/app/Http/Requests/V3/RoadObservation/RegisterRequest.php +++ b/app/Http/Requests/V3/RoadObservation/RegisterRequest.php @@ -24,9 +24,9 @@ class RegisterRequest extends FormRequest return [ 'rms_status' => 'required|in:1,2', 'rms_description' => 'required_if:rms_status,1|string', - 'image_before' => 'required_if:rms_status,1|file|mimes:jpg,jpeg,png', - 'image_after' => 'required_if:rms_status,1|file|mimes:jpg,jpeg,png', - 'start_point' => 'required_if:rms_status,1|string', + 'image_before' => 'file|mimes:jpg,jpeg,png', + 'image_after' => 'file|mimes:jpg,jpeg,png', + 'start_point' => 'string', ]; } } diff --git a/app/Http/Requests/V3/RoadObservation/RestoreRequest.php b/app/Http/Requests/V3/RoadObservation/RestoreRequest.php index 651de88a..1c02a650 100644 --- a/app/Http/Requests/V3/RoadObservation/RestoreRequest.php +++ b/app/Http/Requests/V3/RoadObservation/RestoreRequest.php @@ -22,7 +22,7 @@ class RestoreRequest extends FormRequest public function rules(): array { return [ - 'restore_description' => 'required|string', + 'restore_description' => 'string', ]; } } diff --git a/app/Models/RoadObserved.php b/app/Models/RoadObserved.php index 60131fd0..18c4c9af 100644 --- a/app/Models/RoadObserved.php +++ b/app/Models/RoadObserved.php @@ -62,6 +62,9 @@ class RoadObserved extends Model 'supervisor_description', 'supervising_time', 'supervisor_name', + 'rms_start_latlng', + 'rms_end_latlng', + 'rms_description', ]; /** diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index 504ea8e6..a9b326a7 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -17,13 +17,12 @@ class RoadObservationTableService $fields = [ 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', - 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', - 'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', + 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'rms_start_latlng', + 'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', 'edarate_shahri_id', 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time', 'image_after', 'image_before' ]; - if ($user->hasPermissionTo('show-fast-react')) { $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->whereNotNull('road_observeds.status') @@ -53,25 +52,57 @@ class RoadObservationTableService { $user = auth()->user(); - if (is_null($user->edarate_shahri_id)) { - return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); - } - $fields = [ 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', - 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', + 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'edarate_shahri_id', 'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa', 'image_after', 'image_before', 'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time' ]; - $query = RoadObserved::query() - ->where('rms_status', '<>', 0) - ->whereNotNull('road_observeds.province_id') - ->whereNotNull('status') - ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') - ->where('edarate_shahri_id', $user->edarate_shahri_id) - ->select($fields); + if (auth()->user()->hasPermissionTo('show-fast-react')) { + $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('rms_status', '!=', 0) + ->whereNotNull('road_observeds.province_id') + ->whereNotNull('status') + ->select($fields); + } + elseif (auth()->user()->hasPermissionTo('show-fast-react-province')) { + if (is_null(auth()->user()->province_id)) { + return response()->json([ + 'message' => 'استانی برای شما در سامانه ثبت نشده است!' + ], 400); + } + + $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('rms_province_id', auth()->user()->province_id) + ->where('rms_status', '!=', 0) + ->whereNotNull('road_observeds.province_id') + ->whereNotNull('status') + ->select($fields); + } + elseif (auth()->user()->hasPermissionTo('show-fast-react-edarate-shahri')) { + if (is_null(auth()->user()->edarate_shahri_id)) { + return response()->json([ + 'message' => 'اداره ای برای شما در سامانه ثبت نشده است!' + ], 400); + } + + $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') + ->where('edarate_shahri_id', auth()->user()->edarate_shahri_id) + ->where('rms_status', '!=', 0) + ->whereNotNull('road_observeds.province_id') + ->whereNotNull('status') + ->select($fields); + } + + // $query = RoadObserved::query() + // ->where('rms_status', '!=', 0) + // ->whereNotNull('road_observeds.province_id') + // ->whereNotNull('status') + // ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') + // ->where('edarate_shahri_id', $user->edarate_shahri_id) + // ->select($fields); return DataTableFacade::run( $query, @@ -89,7 +120,7 @@ class RoadObservationTableService ->where('rms_status', '=', 0) ->whereNotNull('edarate_shahri_id') ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, - road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' ); } @@ -104,7 +135,7 @@ class RoadObservationTableService ->whereNotNull('road_observeds.province_id') ->where('road_observeds.province_id', '=', $user->province_id) ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, - road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' ); @@ -120,7 +151,7 @@ class RoadObservationTableService ->whereNotNull('edarate_shahri_id') ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, - road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' ); diff --git a/routes/v3.php b/routes/v3.php index 19385474..9ae94585 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -293,6 +293,8 @@ Route::prefix('road_observations') Route::post('/register/{roadObserved}', 'register') ->middleware('permission:show-fast-react-edarate-shahri') ->name('register'); + + Route::get('/{roadObserved}', 'show')->name('show'); Route::post('/refer/{roadObserved}', 'refer') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('refer'); From 9dfcc96fc7f15fc6d3383ca554b0b590e30fb8e6 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 1 Mar 2025 13:10:07 +0330 Subject: [PATCH 39/61] modify the blades --- .../Dashboard/RoadObservationController.php | 76 +++++++++++++++++-- .../ModifyRegisterationRequest.php | 32 ++++++++ .../V3/RoadObservation/RegisterRequest.php | 4 +- .../Cartables/RoadObservationTableService.php | 50 ++---------- .../ComplaintsReport.blade.php | 46 ++++------- .../OperatorCartableReport.blade.php | 16 ++-- .../SupervisorCartableReport.blade.php | 22 +++--- 7 files changed, 143 insertions(+), 103 deletions(-) create mode 100644 app/Http/Requests/V3/RoadObservation/ModifyRegisterationRequest.php diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 278333c7..c2d9d0b6 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -7,6 +7,7 @@ use App\Exports\V3\RoadObservation\SupervisorCartableReport; use App\Facades\File\FileFacade; use App\Facades\Sms\Sms; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\RoadObservation\ModifyRegisterationRequest; use App\Http\Requests\V3\RoadObservation\ReferRequest; use App\Http\Requests\V3\RoadObservation\RegisterRequest; use App\Http\Requests\V3\RoadObservation\RestoreRequest; @@ -64,19 +65,11 @@ class RoadObservationController extends Controller public function operatorIndex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse { - if (is_null(auth()->user()->edarate_shahri_id)) { - return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); - } - return response()->json($roadObservationTableService->operatorCartableIndex($request)); } public function operatorCartableReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse { - if (is_null(auth()->user()->edarate_shahri_id)) { - return $this->errorResponse('اداره‌ای برای شما در سامانه ثبت نشده است!'); - } - $name = 'گزارش از کارتابل عملیات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx'; $data = $roadObservationTableService->operatorCartableIndex($request); return Excel::download(new OperatorCartableReport($data['data']), $name); @@ -117,6 +110,67 @@ class RoadObservationController extends Controller 'new_files' => json_encode([]) ]; + if ($request->rms_status == 1) { + + $files_path = []; + + $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}/"); + + $files_path[0]['path'] = $image_before; + $files_path[1]['path'] = $image_after; + + $files = json_encode($files_path); + $now_date_time = Carbon::now(); + + $roadObservedData['image_after'] = $image_after; + $roadObservedData['image_before'] = $image_before; + $roadObservedData['rms_start_latlng'] = explode(',', $request->start_point); + $roadObservedData['updated_at_fa'] = Verta::instance($now_date_time); + $roadObservedData['rms_last_activity_fa'] = Verta::instance($now_date_time); + $roadObservedData['rms_last_activity'] = $now_date_time; + $roadObservedHistoryData['new_files'] = $files; + } + + $roadObserved->problemHistories()->create($roadObservedHistoryData); + $roadObserved->update($roadObservedData); + + 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(); + } + + public function modifyRegistration(ModifyRegisterationRequest $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse + { + $roadObservedData = [ + 'status' => 0, + 'status_fa' => 'در حال بررسی', + 'rms_status' => $request->rms_status ?? $roadObserved->rms_status, + 'rms_description' => $request->rms_description ?? $roadObserved->rms_description, + ]; + + $roadObservedHistoryData = [ + 'user_id' => auth()->user()->id, + 'previous_rms_status' => $roadObserved->rms_status, + 'previous_rms_start_latlng' => $roadObserved->rms_start_latlng, + 'previous_rms_end_latlng' => $roadObserved->rms_end_latlng, + 'previous_rms_description' => $roadObserved->rms_description, + 'new_files' => json_encode([]) + ]; + if ($request->rms_status == 1) { $files_path = []; @@ -125,12 +179,18 @@ class RoadObservationController extends Controller $roadObserved->files()->where('path', 'like', '%_image_after%')->delete(); if ($request->has('image_before')) { + if ($roadObserved->image_before) { + FileFacade::delete($roadObserved->image_before, true); + } $image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}/"); $roadObservedData['image_before'] = $image_before; $files_path[0]['path'] = $image_before; } if ($request->has('image_after')) { + if ($roadObserved->image_after) { + FileFacade::delete($roadObserved->image_after, true); + } $image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}/"); $roadObservedData['image_after'] = $image_after; $files_path[1]['path'] = $image_after; diff --git a/app/Http/Requests/V3/RoadObservation/ModifyRegisterationRequest.php b/app/Http/Requests/V3/RoadObservation/ModifyRegisterationRequest.php new file mode 100644 index 00000000..288ea697 --- /dev/null +++ b/app/Http/Requests/V3/RoadObservation/ModifyRegisterationRequest.php @@ -0,0 +1,32 @@ +|string> + */ + public function rules(): array + { + return [ + 'rms_status' => 'required|in:1,2', + 'rms_description' => 'required_if:rms_status,1|string', + 'image_before' => 'file|mimes:jpg,jpeg,png', + 'image_after' => 'file|mimes:jpg,jpeg,png', + 'start_point' => 'string', + ]; + } +} diff --git a/app/Http/Requests/V3/RoadObservation/RegisterRequest.php b/app/Http/Requests/V3/RoadObservation/RegisterRequest.php index f2522339..c3f59834 100644 --- a/app/Http/Requests/V3/RoadObservation/RegisterRequest.php +++ b/app/Http/Requests/V3/RoadObservation/RegisterRequest.php @@ -24,8 +24,8 @@ class RegisterRequest extends FormRequest return [ 'rms_status' => 'required|in:1,2', 'rms_description' => 'required_if:rms_status,1|string', - 'image_before' => 'file|mimes:jpg,jpeg,png', - 'image_after' => 'file|mimes:jpg,jpeg,png', + 'image_before' => 'required_if:rms_status,1|file|mimes:jpg,jpeg,png', + 'image_after' => 'required_if:rms_status,1|file|mimes:jpg,jpeg,png', 'start_point' => 'string', ]; } diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index a9b326a7..15d5dcce 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -60,49 +60,13 @@ class RoadObservationTableService 'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time' ]; - if (auth()->user()->hasPermissionTo('show-fast-react')) { - $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') - ->where('rms_status', '!=', 0) - ->whereNotNull('road_observeds.province_id') - ->whereNotNull('status') - ->select($fields); - } - elseif (auth()->user()->hasPermissionTo('show-fast-react-province')) { - if (is_null(auth()->user()->province_id)) { - return response()->json([ - 'message' => 'استانی برای شما در سامانه ثبت نشده است!' - ], 400); - } - - $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') - ->where('rms_province_id', auth()->user()->province_id) - ->where('rms_status', '!=', 0) - ->whereNotNull('road_observeds.province_id') - ->whereNotNull('status') - ->select($fields); - } - elseif (auth()->user()->hasPermissionTo('show-fast-react-edarate-shahri')) { - if (is_null(auth()->user()->edarate_shahri_id)) { - return response()->json([ - 'message' => 'اداره ای برای شما در سامانه ثبت نشده است!' - ], 400); - } - - $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') - ->where('edarate_shahri_id', auth()->user()->edarate_shahri_id) - ->where('rms_status', '!=', 0) - ->whereNotNull('road_observeds.province_id') - ->whereNotNull('status') - ->select($fields); - } - - // $query = RoadObserved::query() - // ->where('rms_status', '!=', 0) - // ->whereNotNull('road_observeds.province_id') - // ->whereNotNull('status') - // ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') - // ->where('edarate_shahri_id', $user->edarate_shahri_id) - // ->select($fields); + $query = RoadObserved::query() + ->where('rms_status', '!=', 0) + ->whereNotNull('road_observeds.province_id') + ->whereNotNull('status') + ->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id') + ->where('edarate_shahri_id', $user->edarate_shahri_id) + ->select($fields); return DataTableFacade::run( $query, diff --git a/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php b/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php index e2d061ba..9c40fa2b 100644 --- a/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php @@ -38,37 +38,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -76,9 +55,10 @@ @foreach ($data as $item) + - - + + diff --git a/resources/views/v3/Reports/RoadObservation/OperatorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/OperatorCartableReport.blade.php index e15d1d53..6dd7d746 100644 --- a/resources/views/v3/Reports/RoadObservation/OperatorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/OperatorCartableReport.blade.php @@ -40,15 +40,15 @@ - - + - + - - + + + @@ -57,15 +57,15 @@ - - + - + + @endforeach diff --git a/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php b/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php index 2ebaab38..fa412f98 100644 --- a/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/SupervisorCartableReport.blade.php @@ -33,23 +33,24 @@ - + - + + - + - - + + + @@ -59,14 +60,17 @@ - + + - + + + @endforeach From 6542f7832ae86c753b5fa2c441dbead11e8d78d4 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 1 Mar 2025 13:30:12 +0330 Subject: [PATCH 40/61] add modify route --- .../V3/Dashboard/RoadObservationController.php | 2 +- .../v3/Reports/RoadObservation/ComplaintsReport.blade.php | 8 ++++---- routes/v3.php | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index c2d9d0b6..6cb292b6 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -89,7 +89,7 @@ class RoadObservationController extends Controller public function show(RoadObserved $roadObserved): JsonResponse { - return $this->successResponse($roadObserved); + return $this->successResponse($roadObserved->only(['rms_status', 'rms_description', 'image_before', 'image_after', 'rms_start_latlng'])); } public function register(RegisterRequest $request, RoadObserved $roadObserved, NikarayanService $nikarayanService): JsonResponse diff --git a/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php b/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php index 9c40fa2b..fb9c6b08 100644 --- a/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php +++ b/resources/views/v3/Reports/RoadObservation/ComplaintsReport.blade.php @@ -21,18 +21,18 @@
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
- @if ($fromDate == null) - گزارش کارتابل ارزیابی واکنش سریع - @else - گزارش کارتابل ارزیابی واکنش سریع از تاریخ - {{ verta($fromDate)->format('Y/n/j') }} - تا - تاریخ - {{ verta($toDate)->format('Y/n/j') }} - @endif + گزارش کارتابل ارزیابی واکنش سریع
استان شهرستان نام محورنام رانندهکد ملی رانندهشماره موبایل رانندهپلاک نوع تصادف تاریخ تصادف مبلغ کل خسارتپلاکتاریخ ثبتآخرین وضعیت مبلغ فیش مبلغ بیمه مبلغ داغیتاریخ ثبتوضعیت
{{$item->province_fa}} {{$item->city_fa}} {{$item->axis_name}}{{$item->driver_name}}{{$item->driver_national_code}}{{$item->driver_phone_number}}{{$item->plaque}} {{$item->accident_type_fa}} {{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}} {{$item->accident_time}} {{$item->sum ?? 0}}{{$item->plaque}}{{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}}{{$item->status_fa}} {{$item->final_amount ?? 0}} {{$item->deposit_insurance_amount ?? 0}} {{$item->deposit_daghi_amount ?? 0}}{{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}}{{$item->status_fa}}
کد - سوانح - استان - - ادارات شهری - - موضوع گزارش - - نوع گزارش - توضیح گزارش - موقعیت مکانی - شماره تماس گیرنده - تاریخ ثبت گزارشکد یکتاکد سوانحاستانادارهموضوع گزارشنوع گزارشتوضیح گزارشموقعیت مکانیشماره تماس گیرندهتاریخ ثبت
{{ $item['id'] ?? '-' }} {{ $item['fk_RegisteredEventMessage'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['name_fa'] ?? '-' }} {{ $item['Title'] ?? '-' }} {{ $item['FeatureTypeTitle'] ?? '-' }} {{ $item['Description'] ?? '-' }}
کد یکتا کد سوانحاستانادارات شهری موضوع گزارش نوع گزارشتوضیح گزارش شماره تماس گیرندهوضعیتتاریخ ثبت تاریخ اقدامتوضیحاتتوضیحات کارشناستوضیح مامورتوضیح کارشناسوضعیت
{{ $item['id'] ?? '-' }} {{ $item['fk_RegisteredEventMessage'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }} {{ $item['Title'] ?? '-' }} {{ $item['FeatureTypeTitle'] ?? '-' }}{{ $item['Description'] ?? '-' }} {{ $item['MobileForSendEventSms'] ?? '-' }}{{ $item['status_fa'] ?? '-' }}{{ verta($item['created_at'])->format('Y/n/j') ?? '-' }} {{ $item['rms_last_activity_fa'] ?? '-' }} {{ $item['rms_description'] ?? '-' }} {{ $item['supervisor_description'] ?? '-' }}{{ $item['status_fa'] ?? '-' }}
+ style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;"> گزارش کارتابل ارزیابی واکنش سریع -
کد یکتاکد پیگیریکد سوانح استانادارات شهریاداره موضوع گزارش نوع گزارشتوضیح گزارش شماره تماس گیرندهوضعیتتاریخ ثبت تاریخ اقدامتوضیحاتتوضیحات کارشناستوضیح مامورتوضیح کارشناسوضعیت
{{ $item['id'] ?? '-' }} {{ $item['fk_RegisteredEventMessage'] ?? '-' }} {{ $item['province_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }}{{ $item['name_fa'] ?? '-' }} {{ $item['Title'] ?? '-' }} {{ $item['FeatureTypeTitle'] ?? '-' }}{{ $item['Description'] ?? '-' }} {{ $item['MobileForSendEventSms'] ?? '-' }}{{ $item['status_fa'] ?? '-' }}{{ verta($item['created_at'])->format('Y/n/j') ?? '-' }} {{ $item['rms_last_activity_fa'] ?? '-' }} {{ $item['rms_description'] ?? '-' }} {{ $item['supervisor_description'] ?? '-' }}{{ $item['status_fa'] ?? '-' }}{{ $item['rms_last_activity_fa'] ?? '-' }}
- - - @@ -58,7 +58,7 @@ - + diff --git a/routes/v3.php b/routes/v3.php index 9ae94585..3b8b1a9a 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -290,9 +290,14 @@ Route::prefix('road_observations') Route::get('/complaints_index', 'complaintsIndex') ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react') ->name('complaintsIndex'); + Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport') + ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react'); Route::post('/register/{roadObserved}', 'register') ->middleware('permission:show-fast-react-edarate-shahri') ->name('register'); + Route::post('/modify_registration/{roadObserved}', 'modifyRegistration') + ->middleware('permission:show-fast-react-edarate-shahri') + ->name('modifyRegistration'); Route::get('/{roadObserved}', 'show')->name('show'); Route::post('/refer/{roadObserved}', 'refer') @@ -306,9 +311,6 @@ Route::prefix('road_observations') Route::post('/restore/{roadObserved}', 'restore') ->middleware('permission:restore-fast-react') ->name('restore'); - - Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport') - ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react'); }); Route::prefix('log_list') From cb91f469f8bc28fa63d373f86f775359d4cf9ab9 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 1 Mar 2025 16:02:33 +0330 Subject: [PATCH 41/61] create safety and privacy controller --- .../Dashboard/SafetyAndPrivacyController.php | 149 ++++++++++++++++++ .../FirstStepStoreRequest.php | 40 +++++ .../SecondStepStoreRequest.php | 29 ++++ .../ThirdStepStoreRequest.php | 28 ++++ .../Cartables/RoadObservationTableService.php | 23 ++- .../SafetyAndPrivacyTableService.php | 49 ++++++ routes/v3.php | 13 ++ 7 files changed, 317 insertions(+), 14 deletions(-) create mode 100644 app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php create mode 100644 app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php create mode 100644 app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php create mode 100644 app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php create mode 100644 app/Services/Cartables/SafetyAndPrivacyTableService.php diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php new file mode 100644 index 00000000..2191e2c4 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -0,0 +1,149 @@ +json($safetyAndPrivacyTableService->datatable($request)); + } + + public function firstStepStore(FirstStepStoreRequest $request, NominatimService $nominatimService): JsonResponse + { + $user = auth()->user(); + + if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) { + return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); + } + + if (is_null(auth()->user()->edarate_shahri_id)) { + return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); + } + + $coordinates = explode(',', $request->point); + $item = InfoItem::query() + ->where('id', $request->info_id) + ->where('item', 17) + ->firstOrFail(); + + DB::transaction(function () use ($request, $coordinates, $item, $nominatimService) + { + $safety_and_privacy = SafetyAndPrivacy::query()->create([ + 'lat' => $coordinates[0], + 'lon' => $coordinates[1], + 'operator_id' => auth()->user()->id, + 'operator_name' => auth()->user()->name, + 'province_id' => auth()->user()->province_id, + 'province_fa' => auth()->user()->province_fa, + 'info_id' => $item->id, + 'info_fa' => $item->sub_item_str, + 'city_id' => auth()->user()->city_id, + 'city_fa' => auth()->user()->city_fa, + 'activity_date_time' => $request->activity_date." ".$request->activity_time, + 'edare_shahri_id' => auth()->user()->edarate_shahri_id, + 'edare_shahri_name' => auth()->user()->edarate_shahri_name, + 'way_id' => $nominatimService->get_way_id_from_nominatim($coordinates[0], $coordinates[1]), + 'recognize_picture' => $request->has('recognize_picture') ? FileFacade::save($request->recognize_picture, 'safety_and_privacy') : null, + 'step' => 1, + 'step_fa' => 'گام اول (شناسایی)' + ]); + + auth()->user()->addActivityComplete(1134); + }); + + return $this->successResponse(); + } + + public function secondStepStore(SecondStepStoreRequest $safety_and_privacy, Request $request): JsonResponse + { + $user = auth()->user(); + + if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) { + return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); + } + + if (is_null(auth()->user()->edarate_shahri_id)) { + return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); + } + + DB::transaction(function () use ($request, $safety_and_privacy) + { + $judiciary_document = []; + foreach ($request->judiciary_document as $index => $item) { + $judiciary_document[] = $item->store('safety_and_privacy/'.$safety_and_privacy->id.'/judiciary_document', 'public'); + } + $safety_and_privacy->judiciary_document = serialize($judiciary_document); + $safety_and_privacy->judiciary_document_upload_date = now(); + + $safety_and_privacy->goToSecondStep(); + $safety_and_privacy->save(); + + auth()->user()->addActivityComplete(1135); + }); + + return $this->successResponse(); + } + + public function thirdStepStore(ThirdStepStoreRequest $safety_and_privacy, Request $request): JsonResponse + { + $user = auth()->user(); + + if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) { + return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); + } + + if (is_null(auth()->user()->edarate_shahri_id)) { + return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); + } + + DB::transaction(function () use ($request, $safety_and_privacy) { + $action_picture = $request->file('action_picture')->store('safety_and_privacy/'.$safety_and_privacy->id.'/action_picture', 'public'); + $safety_and_privacy->action_picture = Storage::disk('public')->url($action_picture); + $safety_and_privacy->action_picture_document_upload_date = now(); + + $safety_and_privacy->goToThirdStep(); + $safety_and_privacy->save(); + auth()->user()->addActivityComplete(1136); + }); + + return $this->successResponse(); + } + + public function show(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + return $this->successResponse($safetyAndPrivacy); + } + + public function destroy(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + Storage::deleteDirectory('public/' . 'safety_and_privacy/' . $safetyAndPrivacy->id); + + DB::transaction(function () use ($safetyAndPrivacy) + { + auth()->user()->addActivityComplete(1155); + $safetyAndPrivacy->delete(); + }); + + return $this->successResponse(); + } +} diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php new file mode 100644 index 00000000..a307f87e --- /dev/null +++ b/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php @@ -0,0 +1,40 @@ +|string> + */ + public function rules(): array + { + return [ + 'point' => 'required', + 'info_id' => 'required', + 'activity_date' => 'required|date_format:Y-m-d', + 'activity_time' => 'required|date_format:H:i', + 'recognize_picture' => 'required|image', + ]; + } + + public function attributes(): array + { + return [ + 'activity_date' => 'تاریخ فعالیت', + 'activity_time' => 'ساعت فعالیت', + ]; + } +} diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php new file mode 100644 index 00000000..5d130d51 --- /dev/null +++ b/app/Http/Requests/V3/SafetyAndPrivacy/SecondStepStoreRequest.php @@ -0,0 +1,29 @@ +|string> + */ + public function rules(): array + { + return [ + 'judiciary_document' => 'required|array', + 'judiciary_document.*' => 'file', + ]; + } +} diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php new file mode 100644 index 00000000..652ea3a4 --- /dev/null +++ b/app/Http/Requests/V3/SafetyAndPrivacy/ThirdStepStoreRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'action_picture' => 'required|image', + ]; + } +} diff --git a/app/Services/Cartables/RoadObservationTableService.php b/app/Services/Cartables/RoadObservationTableService.php index 15d5dcce..810d4b88 100644 --- a/app/Services/Cartables/RoadObservationTableService.php +++ b/app/Services/Cartables/RoadObservationTableService.php @@ -16,7 +16,7 @@ class RoadObservationTableService $user = auth()->user(); $fields = [ - 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', + 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'StartTime_DateTime', 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'rms_start_latlng', 'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', 'edarate_shahri_id', 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa', @@ -53,7 +53,7 @@ class RoadObservationTableService $user = auth()->user(); $fields = [ - 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', + 'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'StartTime_DateTime', 'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'edarate_shahri_id', 'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa', 'image_after', 'image_before', 'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', @@ -79,14 +79,15 @@ class RoadObservationTableService { $user = auth()->user(); + $fields = 'fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, StartTime_DateTime, + road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, + status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'; + if ($user->hasPermissionTo('show-fast-react')) { $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) ->whereNotNull('edarate_shahri_id') - ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, - road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, - status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' - ); + ->selectRaw($fields); } elseif ($user->hasPermissionTo('show-fast-react-province')) { @@ -98,10 +99,7 @@ class RoadObservationTableService ->where('rms_status', '=', 0) ->whereNotNull('road_observeds.province_id') ->where('road_observeds.province_id', '=', $user->province_id) - ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, - road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, - status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' - ); + ->selectRaw($fields); } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { @@ -114,10 +112,7 @@ class RoadObservationTableService ->where('rms_status', '=', 0) ->whereNotNull('edarate_shahri_id') ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) - ->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, - road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id, - status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng' - ); + ->selectRaw($fields); } diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php new file mode 100644 index 00000000..56eae8f1 --- /dev/null +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -0,0 +1,49 @@ +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','judiciary_document', + 'judiciary_document_upload_date','info_id','info_fa','activity_date_time','judiciary_document_upload_date','action_picture_document_upload_date', + 'step_fa' + ]; + + 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('استانی برای شما در سامانه ثبت نشده است!'); + } + + $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); + } + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'] + ); + } +} diff --git a/routes/v3.php b/routes/v3.php index 3b8b1a9a..91969d31 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -14,6 +14,7 @@ use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController; 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\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; use App\Http\Controllers\V3\LogListController; @@ -319,3 +320,15 @@ Route::prefix('log_list') ->group(function () { Route::get('/', 'index')->name('index'); }); + +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('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy'); + Route::get('/second_step_store', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy'); + Route::get('/third_step_store', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy'); + Route::get('/{safetyAndPrivacy}', 'show')->name('show'); + Route::get('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); + }); From a65ec5e2bde91be27eb752525dce1cc94d0688c7 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 2 Mar 2025 10:11:13 +0330 Subject: [PATCH 42/61] create blade file for report --- .../V3/SafetyAndPrivacy/CartableReport.php | 69 ++++++++++++ .../Dashboard/SafetyAndPrivacyController.php | 88 +++++++++------ app/Models/SafetyAndPrivacy.php | 21 ++++ .../SafetyAndPrivacy/CartableReport.blade.php | 104 ++++++++++++++++++ 4 files changed, 246 insertions(+), 36 deletions(-) create mode 100644 app/Exports/V3/SafetyAndPrivacy/CartableReport.php create mode 100644 resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php diff --git a/app/Exports/V3/SafetyAndPrivacy/CartableReport.php b/app/Exports/V3/SafetyAndPrivacy/CartableReport.php new file mode 100644 index 00000000..6c066aa1 --- /dev/null +++ b/app/Exports/V3/SafetyAndPrivacy/CartableReport.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/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index 2191e2c4..85024011 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\V3\Dashboard; +use App\Exports\V3\SafetyAndPrivacy\CartableReport; use App\Facades\File\FileFacade; use App\Http\Controllers\Controller; use App\Http\Requests\V3\SafetyAndPrivacy\FirstStepStoreRequest; @@ -18,6 +19,8 @@ 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; class SafetyAndPrivacyController extends Controller { @@ -28,15 +31,22 @@ class SafetyAndPrivacyController extends Controller return response()->json($safetyAndPrivacyTableService->datatable($request)); } + public function excelReport(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); + } + public function firstStepStore(FirstStepStoreRequest $request, NominatimService $nominatimService): JsonResponse { $user = auth()->user(); - if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) { + if ($user->edarate_ostani_id || is_null($user->city_id)) { return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); } - if (is_null(auth()->user()->edarate_shahri_id)) { + if (is_null($user->edarate_shahri_id)) { return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); } @@ -46,84 +56,90 @@ class SafetyAndPrivacyController extends Controller ->where('item', 17) ->firstOrFail(); - DB::transaction(function () use ($request, $coordinates, $item, $nominatimService) + DB::transaction(function () use ($request, $coordinates, $item, $nominatimService, $user) { $safety_and_privacy = SafetyAndPrivacy::query()->create([ 'lat' => $coordinates[0], 'lon' => $coordinates[1], - 'operator_id' => auth()->user()->id, - 'operator_name' => auth()->user()->name, - 'province_id' => auth()->user()->province_id, - 'province_fa' => auth()->user()->province_fa, + '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' => auth()->user()->city_id, - 'city_fa' => auth()->user()->city_fa, + 'city_id' => $user->city_id, + 'city_fa' => $user->city_fa, 'activity_date_time' => $request->activity_date." ".$request->activity_time, - 'edare_shahri_id' => auth()->user()->edarate_shahri_id, - 'edare_shahri_name' => auth()->user()->edarate_shahri_name, + '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]), - 'recognize_picture' => $request->has('recognize_picture') ? FileFacade::save($request->recognize_picture, 'safety_and_privacy') : null, 'step' => 1, 'step_fa' => 'گام اول (شناسایی)' ]); - auth()->user()->addActivityComplete(1134); + $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(SecondStepStoreRequest $safety_and_privacy, Request $request): JsonResponse + public function secondStepStore(SafetyAndPrivacy $safety_and_privacy, SecondStepStoreRequest $request): JsonResponse { $user = auth()->user(); - if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) { + if ($user->edarate_ostani_id || is_null($user->city_id)) { return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); } - if (is_null(auth()->user()->edarate_shahri_id)) { + if (is_null($user->edarate_shahri_id)) { return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); } - DB::transaction(function () use ($request, $safety_and_privacy) + DB::transaction(function () use ($request, $safety_and_privacy, $user) { $judiciary_document = []; - foreach ($request->judiciary_document as $index => $item) { - $judiciary_document[] = $item->store('safety_and_privacy/'.$safety_and_privacy->id.'/judiciary_document', 'public'); + foreach ($request->judiciary_document as $index => $file) { + $judiciary_document[] = FileFacade::save($file, "safety_and_privacy/{$safety_and_privacy->id}/judiciary_document"); } - $safety_and_privacy->judiciary_document = serialize($judiciary_document); - $safety_and_privacy->judiciary_document_upload_date = now(); + $safety_and_privacy->update([ + 'judiciary_document' => serialize($judiciary_document), + 'judiciary_document_upload_date' => now(), + 'step' => 2, + 'step_fa' => 'گام دوم (مستندات قضایی)' + ]); - $safety_and_privacy->goToSecondStep(); - $safety_and_privacy->save(); - - auth()->user()->addActivityComplete(1135); + $user->addActivityComplete(1135); }); return $this->successResponse(); } - public function thirdStepStore(ThirdStepStoreRequest $safety_and_privacy, Request $request): JsonResponse + public function thirdStepStore(SafetyAndPrivacy $safety_and_privacy, ThirdStepStoreRequest $request): JsonResponse { $user = auth()->user(); - if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) { + if ($user->edarate_ostani_id || is_null($user->city_id)) { return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'); } - if (is_null(auth()->user()->edarate_shahri_id)) { + if (is_null($user->edarate_shahri_id)) { return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); } - DB::transaction(function () use ($request, $safety_and_privacy) { - $action_picture = $request->file('action_picture')->store('safety_and_privacy/'.$safety_and_privacy->id.'/action_picture', 'public'); - $safety_and_privacy->action_picture = Storage::disk('public')->url($action_picture); - $safety_and_privacy->action_picture_document_upload_date = now(); + DB::transaction(function () use ($request, $safety_and_privacy, $user) { + $safety_and_privacy->update([ + 'step' => 3, + 'step_fa' => 'گام سوم (برخورد)', + 'action_picture' => FileFacade::save($request->action_picture, "safety_and_privacy/{$safety_and_privacy->id}/action_picture"), + 'action_picture_document_upload_date' => now(), + ]); - $safety_and_privacy->goToThirdStep(); - $safety_and_privacy->save(); - auth()->user()->addActivityComplete(1136); + $user->addActivityComplete(1136); }); return $this->successResponse(); @@ -136,7 +152,7 @@ class SafetyAndPrivacyController extends Controller public function destroy(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse { - Storage::deleteDirectory('public/' . 'safety_and_privacy/' . $safetyAndPrivacy->id); + Storage::deleteDirectory("public/safety_and_privacy/{$safetyAndPrivacy->id}"); DB::transaction(function () use ($safetyAndPrivacy) { diff --git a/app/Models/SafetyAndPrivacy.php b/app/Models/SafetyAndPrivacy.php index 7df8202d..8d1fc29c 100644 --- a/app/Models/SafetyAndPrivacy.php +++ b/app/Models/SafetyAndPrivacy.php @@ -2,9 +2,11 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Traits\SafetyAndPrivacyReportAble; +use Illuminate\Support\Facades\Storage; class SafetyAndPrivacy extends Model { @@ -60,4 +62,23 @@ class SafetyAndPrivacy extends Model } } + protected function recognizePicture(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : + (filter_var($value, FILTER_VALIDATE_URL) + ? $value + : Storage::disk('public')->url($value)) + ); + } + + protected function actionPicture(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : + (filter_var($value, FILTER_VALIDATE_URL) + ? $value + : Storage::disk('public')->url($value)) + ); + } } diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php new file mode 100644 index 00000000..48fb08bf --- /dev/null +++ b/resources/views/v3/Reports/SafetyAndPrivacy/CartableReport.blade.php @@ -0,0 +1,104 @@ + + + + + + + + فعالیت های نگهداری حریم راه + + + + + + +
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
گزارش رسیدگی به شکایات واکنش سریع {{ $item['id'] ?? '-' }} {{ $item['fk_RegisteredEventMessage'] ?? '-' }} {{ $item['province_fa'] ?? '-' }}{{ $item['name_fa'] ?? '-' }}{{ $item['edarate_shahri_name_fa'] ?? '-' }} {{ $item['Title'] ?? '-' }} {{ $item['FeatureTypeTitle'] ?? '-' }} {{ $item['Description'] ?? '-' }}
+ + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش فعالیت های نگهداری حریم راه +
+ کد یکتا + + استان + + اداره + + مورد + + تاریخ بازدید + + تاریخ ثبت مستندات قضایی + + تاریخ اقدام + + وضعیت + + تاریخ ثبت +
{{ $item['id'] ?? '-' }}{{ $item['province_fa'] ?? '-' }}{{ $item['edare_shahri_name'] ?? '-' }}{{ $item['info_fa'] ?? '-' }}{{ $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_picture_document_upload_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') : '-' }}
+ + From b31ea8bba24fd921c5bc2eb9a09db504bf04c616 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 2 Mar 2025 10:55:03 +0330 Subject: [PATCH 43/61] add country activity report --- .../Dashboard/SafetyAndPrivacyController.php | 13 ++++ .../SafetyAndPrivacyTableService.php | 77 ++++++++++++++++++- routes/v3.php | 1 + 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index 85024011..ff596cff 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -162,4 +162,17 @@ class SafetyAndPrivacyController extends Controller return $this->successResponse(); } + + public function deserialize(SafetyAndPrivacy $safety_and_privacy): JsonResponse + { + $judiciaries = isset($safety_and_privacy->judiciary_document) ? unserialize($safety_and_privacy->judiciary_document) : []; + + $result = []; + + foreach ($judiciaries as $judiciary) { + $result[] = Storage::disk('public')->url($judiciary); + } + + return $this->successResponse($result); + } } diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index 56eae8f1..35904a97 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -6,6 +6,7 @@ use App\Facades\DataTable\DataTableFacade; use App\Http\Traits\ApiResponse; use App\Models\SafetyAndPrivacy; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class SafetyAndPrivacyTableService { @@ -16,8 +17,8 @@ class SafetyAndPrivacyTableService $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','judiciary_document', - 'judiciary_document_upload_date','info_id','info_fa','activity_date_time','judiciary_document_upload_date','action_picture_document_upload_date', + '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', 'step_fa' ]; @@ -46,4 +47,76 @@ class SafetyAndPrivacyTableService allowedSortings: ['*'] ); } + + public function countryActivity(Request $request) + { + $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(); + + $country_name = "کشوری"; + $all[0]["info-89"]["step-1"] = 0; + $all[0]["info-89"]["step-2"] = 0; + $all[0]["info-89"]["step-3"] = 0; + + $all[0]["info-90"]["step-1"] = 0; + $all[0]["info-90"]["step-2"] = 0; + $all[0]["info-90"]["step-3"] = 0; + + $all[0]["info-91"]["step-1"] = 0; + $all[0]["info-91"]["step-2"] = 0; + $all[0]["info-91"]["step-3"] = 0; + + $all[0]["sum"] = 0; + $all[0]["name_fa"] = $country_name; + $all[0]["id"] = -1; + + foreach (\App\Models\Province::all() as $key => $value) { + $all[$value->id]["info-89"]["step-1"] = 0; + $all[$value->id]["info-89"]["step-2"] = 0; + $all[$value->id]["info-89"]["step-3"] = 0; + + $all[$value->id]["info-90"]["step-1"] = 0; + $all[$value->id]["info-90"]["step-2"] = 0; + $all[$value->id]["info-90"]["step-3"] = 0; + + $all[$value->id]["info-91"]["step-1"] = 0; + $all[$value->id]["info-91"]["step-2"] = 0; + $all[$value->id]["info-91"]["step-3"] = 0; + + $all[$value->id]["sum"] = 0; + $all[$value->id]["name_fa"] = $value->name_fa; + $all[$value->id]["id"] = $value->id; + } + + $temp = DB::select("SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step"); + + $sum = 0; + foreach ($temp as $key => $value) { + $sum += $value->qty; + $all[0]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $all[0]["sum"] = $sum; + } + + $temp = DB::select("SELECT province_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id order by province_id"); + $province_id_flag = ""; + $sum = 0; + + foreach ($temp as $key => $value) { + + if ($province_id_flag !== $value->province_id) { + + $province_id_flag = $value->province_id; + $sum = $value->qty ; + + }else { + + $sum += $value->qty; + + } + + $all[$value->province_id]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $all[$value->province_id]["sum"] = $sum; + } + return $all; + } } diff --git a/routes/v3.php b/routes/v3.php index 91969d31..8cf70f84 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -331,4 +331,5 @@ Route::prefix('safety_and_privacy') Route::get('/third_step_store', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy'); Route::get('/{safetyAndPrivacy}', 'show')->name('show'); Route::get('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); + Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize'); }); From 945fa0792b7d5b567264a8a7d6ddbbf0db10b2a0 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 2 Mar 2025 14:38:59 +0330 Subject: [PATCH 44/61] create report controller --- .../SafetyAndPrivacyReportController.php | 20 ++++ .../Dashboard/SafetyAndPrivacyController.php | 12 ++- .../SafetyAndPrivacyTableService.php | 100 ++++++++---------- routes/v3.php | 10 +- 4 files changed, 81 insertions(+), 61 deletions(-) create mode 100644 app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php diff --git a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php new file mode 100644 index 00000000..19151055 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php @@ -0,0 +1,20 @@ +successResponse(); } - public function deserialize(SafetyAndPrivacy $safety_and_privacy): JsonResponse + public function deserialize(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse { - $judiciaries = isset($safety_and_privacy->judiciary_document) ? unserialize($safety_and_privacy->judiciary_document) : []; + $judiciaries = isset($safetyAndPrivacy->judiciary_document) ? unserialize($safetyAndPrivacy->judiciary_document) : []; $result = []; @@ -175,4 +175,12 @@ class SafetyAndPrivacyController extends Controller return $this->successResponse($result); } + + public function subItem(): 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()); + } } diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index 35904a97..e646367c 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -4,6 +4,7 @@ namespace App\Services\Cartables; 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; @@ -48,75 +49,58 @@ class SafetyAndPrivacyTableService ); } - public function countryActivity(Request $request) + 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(); - $country_name = "کشوری"; - $all[0]["info-89"]["step-1"] = 0; - $all[0]["info-89"]["step-2"] = 0; - $all[0]["info-89"]["step-3"] = 0; + $activities = []; - $all[0]["info-90"]["step-1"] = 0; - $all[0]["info-90"]["step-2"] = 0; - $all[0]["info-90"]["step-3"] = 0; + $country = DB::select( + "SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step" + ); + $provinces = DB::select( + "SELECT province_id, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa" + ); - $all[0]["info-91"]["step-1"] = 0; - $all[0]["info-91"]["step-2"] = 0; - $all[0]["info-91"]["step-3"] = 0; - - $all[0]["sum"] = 0; - $all[0]["name_fa"] = $country_name; - $all[0]["id"] = -1; - - foreach (\App\Models\Province::all() as $key => $value) { - $all[$value->id]["info-89"]["step-1"] = 0; - $all[$value->id]["info-89"]["step-2"] = 0; - $all[$value->id]["info-89"]["step-3"] = 0; - - $all[$value->id]["info-90"]["step-1"] = 0; - $all[$value->id]["info-90"]["step-2"] = 0; - $all[$value->id]["info-90"]["step-3"] = 0; - - $all[$value->id]["info-91"]["step-1"] = 0; - $all[$value->id]["info-91"]["step-2"] = 0; - $all[$value->id]["info-91"]["step-3"] = 0; - - $all[$value->id]["sum"] = 0; - $all[$value->id]["name_fa"] = $value->name_fa; - $all[$value->id]["id"] = $value->id; + $countryTotalSum = 0; + foreach ($country as $key => $value) { + $countryTotalSum += $value->qty; + $activities[-1]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $activities[-1]["sum"] = $countryTotalSum; } - $temp = DB::select("SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step"); - $sum = 0; - foreach ($temp as $key => $value) { - $sum += $value->qty; - $all[0]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $all[0]["sum"] = $sum; + foreach (Province::all() as $key => $value) { + $activities[$value->id]["info-89"]["step-1"] = 0; + $activities[$value->id]["info-89"]["step-2"] = 0; + $activities[$value->id]["info-89"]["step-3"] = 0; + + $activities[$value->id]["info-90"]["step-1"] = 0; + $activities[$value->id]["info-90"]["step-2"] = 0; + $activities[$value->id]["info-90"]["step-3"] = 0; + + $activities[$value->id]["info-91"]["step-1"] = 0; + $activities[$value->id]["info-91"]["step-2"] = 0; + $activities[$value->id]["info-91"]["step-3"] = 0; + + $activities[$value->id]["sum"] = 0; + $activities[$value->id]["name_fa"] = $value->name_fa; + $activities[$value->id]["id"] = $value->id; } - $temp = DB::select("SELECT province_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id order by province_id"); - $province_id_flag = ""; - $sum = 0; - - foreach ($temp as $key => $value) { - - if ($province_id_flag !== $value->province_id) { - - $province_id_flag = $value->province_id; - $sum = $value->qty ; - - }else { - - $sum += $value->qty; - - } - - $all[$value->province_id]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $all[$value->province_id]["sum"] = $sum; + $provinceTotalSum = 0; + foreach ($provinces as $key => $value) { + $provinceTotalSum += $value->qty; + $activities[$value->province_id]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $activities[$value->province_id]["sum"] = $provinceTotalSum; + $activities[$value->province_id]["province_fa"] = $value->province_fa; } - return $all; + + return [ + 'activities' => $activities, + 'fromDate' => $fromDate, + 'toDate' => $toDate, + ]; } } diff --git a/routes/v3.php b/routes/v3.php index 8cf70f84..62781fe6 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -11,6 +11,7 @@ use App\Http\Controllers\V3\Dashboard\AccidentReceiptController; use App\Http\Controllers\V3\Dashboard\Reports\AccidentReceiptReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController; +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; @@ -24,7 +25,7 @@ use Illuminate\Support\Facades\Route; Route::get('admin/permissions', function () { if (auth()->user()->username == 'witel') { - auth()->user()->syncPermissions(\App\Models\Permission::all()->pluck('id')->toArray()); + auth()->user()->syncPermissions(\App\Models\Permission::all()); return response('done'); } abort(404); @@ -333,3 +334,10 @@ Route::prefix('safety_and_privacy') Route::get('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize'); }); + +Route::prefix('safety_and_privacy_report') + ->name('SafetyAndPrivacyReport.') + ->controller(SafetyAndPrivacyReportController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + }); From f2258c3521da547200dea24593c4e79691575f21 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 3 Mar 2025 10:39:38 +0330 Subject: [PATCH 45/61] create blade files for report --- .../CountryActivityReport.php | 62 ++++++++ .../ProvinceActivityReport.php | 62 ++++++++ .../SafetyAndPrivacyReportController.php | 30 +++- .../Dashboard/SafetyAndPrivacyController.php | 4 +- .../SafetyAndPrivacyTableService.php | 63 ++++++++- .../CountryActivityReport.blade.php | 107 ++++++++++++++ .../ProvinceActivityReport.blade.php | 133 ++++++++++++++++++ routes/v3.php | 14 +- 8 files changed, 461 insertions(+), 14 deletions(-) create mode 100644 app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php create mode 100644 app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php create mode 100644 resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php create mode 100644 resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php diff --git a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php new file mode 100644 index 00000000..99a9fb7d --- /dev/null +++ b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php @@ -0,0 +1,62 @@ +data; + + return view('v3.Reports.SafetyAndPrivacy.CountryActivityReport', [ + 'data' => $data['activities'], + 'fromDate' => $data['fromDate'], + 'toDate' => $data['toDate'], + ]); + } + + 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('K1'); + return [$drawing, $drawing2]; + } +} \ No newline at end of file diff --git a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php new file mode 100644 index 00000000..c5ffa6ab --- /dev/null +++ b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php @@ -0,0 +1,62 @@ +data; + + return view('v3.Reports.SafetyAndPrivacy.ProvinceActivityReport', [ + 'data' => $data['activities'], + 'fromDate' => $data['fromDate'], + 'toDate' => $data['toDate'], + ]); + } + + 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('K1'); + return [$drawing, $drawing2]; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php index 19151055..cc4291f8 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php @@ -2,19 +2,43 @@ namespace App\Http\Controllers\V3\Dashboard\Reports; +use App\Exports\V3\SafetyAndPrivacy\CountryActivityReport; +use App\Exports\V3\SafetyAndPrivacy\ProvinceActivityReport; use App\Http\Controllers\Controller; +use App\Http\Traits\ApiResponse; use App\Services\Cartables\SafetyAndPrivacyTableService; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Maatwebsite\Excel\Facades\Excel; +use Symfony\Component\HttpFoundation\BinaryFileResponse; class SafetyAndPrivacyReportController extends Controller { - public function countryActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService) - { + use ApiResponse; + public function countryActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + { + $data = $safetyAndPrivacyTableService->countryActivity($request); + return $this->successResponse($data['activities']); } - public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService) + public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse { + $data = $safetyAndPrivacyTableService->provinceActivity($request); + return $this->successResponse($data['activities']); + } + 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), $name); } } diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index 5c67f6a4..425a203e 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -176,10 +176,10 @@ class SafetyAndPrivacyController extends Controller return $this->successResponse($result); } - public function subItem(): JsonResponse + public function subItems(): JsonResponse { return $this->successResponse(InfoItem::query() - ->where('item', 17) + ->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()); } diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index e646367c..65a1dc3f 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -59,9 +59,6 @@ class SafetyAndPrivacyTableService $country = DB::select( "SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step" ); - $provinces = DB::select( - "SELECT province_id, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa" - ); $countryTotalSum = 0; foreach ($country as $key => $value) { @@ -86,9 +83,12 @@ class SafetyAndPrivacyTableService $activities[$value->id]["sum"] = 0; $activities[$value->id]["name_fa"] = $value->name_fa; - $activities[$value->id]["id"] = $value->id; } + $provinces = DB::select( + "SELECT province_id, province_fa, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa" + ); + $provinceTotalSum = 0; foreach ($provinces as $key => $value) { $provinceTotalSum += $value->qty; @@ -103,4 +103,59 @@ class SafetyAndPrivacyTableService 'toDate' => $toDate, ]; } + + 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; + $activities = []; + + $province = DB::select(' + SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step + '); + + $provinceTotalSum = 0; + foreach ($province as $key => $value) { + $provinceTotalSum += $value->qty; + $activities[-1]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $activities[-1]["sum"] = $provinceTotalSum; + } + + foreach (\App\Models\EdarateShahri::query()->where('province_id', $provinceId)->get() as $key => $value) { + $activities[$value->id]["info-89"]["step-1"] = 0; + $activities[$value->id]["info-89"]["step-2"] = 0; + $activities[$value->id]["info-89"]["step-3"] = 0; + + $activities[$value->id]["info-90"]["step-1"] = 0; + $activities[$value->id]["info-90"]["step-2"] = 0; + $activities[$value->id]["info-90"]["step-3"] = 0; + + $activities[$value->id]["info-91"]["step-1"] = 0; + $activities[$value->id]["info-91"]["step-2"] = 0; + $activities[$value->id]["info-91"]["step-3"] = 0; + + $activities[$value->id]["sum"] = 0; + $activities[$value->id]["name_fa"] = $value->name_fa; + } + + + $cities = DB::select(' + SELECT edare_shahri_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id + '); + + $cityTotalSum = 0; + foreach ($cities as $key => $value) { + $cityTotalSum += $value->qty; + $activities[$value->edare_shahri_id]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $activities[$value->edare_shahri_id][""] = $value; + $activities[$value->edare_shahri_id]["sum"] = $cityTotalSum; + } + + return [ + 'activities' => $activities, + 'fromDate' => $fromDate, + 'toDate' => $toDate, + ]; + } } diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php new file mode 100644 index 00000000..2959afed --- /dev/null +++ b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php @@ -0,0 +1,107 @@ + + + + + + + + کشوری + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + + + + + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش نگهداری حریم راه از تاریخ + {{ verta($fromDate)->format('Y/n/j') }} + تا + تاریخ + {{ verta($toDate)->format('Y/n/j') }} + +
+ اداره کل + + تعداد کل + + ساخت و ساز غیر مجاز + + راه دسترسی غیر مجاز + + عبور تاسیسات زیربنایی غیر مجاز +
+ گام اول (شناسایی) + + گام دوم (مستندات قضایی) + + گام سوم (برخورد) + + گام اول (شناسایی) + + گام دوم (مستندات قضایی) + + گام سوم (برخورد) + + گام اول (شناسایی) + + گام دوم (مستندات قضایی) + + گام سوم (برخورد) +
{{ $item['name_fa'] }}{{ $item['sum'] }}{{ $item['info-89']['step-1'] }}{{ $item['info-89']['step-2'] }}{{ $item['info-89']['step-3'] }}{{ $item['info-90']['step-1'] }}{{ $item['info-90']['step-2'] }}{{ $item['info-90']['step-3'] }}{{ $item['info-91']['step-1'] }}{{ $item['info-91']['step-2'] }}{{ $item['info-91']['step-3'] }}
+ + diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php new file mode 100644 index 00000000..ffe68f28 --- /dev/null +++ b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php @@ -0,0 +1,133 @@ + + + + + + + + استانی + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($data as $item) + @if ($item['is_province'] == '1') + + + + + + + + + + + + + + @else + + + + + + + + + + + + + + @endif + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش نگهداری حریم راه از تاریخ + {{ verta($fromDate)->format('Y/n/j') }} + تا + تاریخ + {{ verta($toDate)->format('Y/n/j') }} + +
+ اداره کل + + تعداد کل + + ساخت و ساز غیر مجاز + + راه دسترسی غیر مجاز + + عبور تاسیسات زیربنایی غیر مجاز +
+ گام اول (شناسایی) + + گام دوم (مستندات قضایی) + + گام سوم (برخورد) + + گام اول (شناسایی) + + گام دوم (مستندات قضایی) + + گام سوم (برخورد) + + گام اول (شناسایی) + + گام دوم (مستندات قضایی) + + گام سوم (برخورد) +
+ {{ $item['name_fa'] }} + {{ $item['sum'] }} + {{ $item['info-89']['step-1'] }} + {{ $item['info-89']['step-2'] }} + {{ $item['info-89']['step-3'] }} + {{ $item['info-90']['step-1'] }} + {{ $item['info-90']['step-2'] }} + {{ $item['info-90']['step-3'] }} + {{ $item['info-91']['step-1'] }} + {{ $item['info-91']['step-2'] }} + {{ $item['info-91']['step-3'] }}
{{ $item['name_fa'] }}{{ $item['sum'] }}{{ $item['info-89']['step-1'] }}{{ $item['info-89']['step-2'] }}{{ $item['info-89']['step-3'] }}{{ $item['info-90']['step-1'] }}{{ $item['info-90']['step-2'] }}{{ $item['info-90']['step-3'] }}{{ $item['info-91']['step-1'] }}{{ $item['info-91']['step-2'] }}{{ $item['info-91']['step-3'] }}
+ + diff --git a/routes/v3.php b/routes/v3.php index 62781fe6..199f7d56 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -327,11 +327,12 @@ Route::prefix('safety_and_privacy') ->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('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy'); - Route::get('/second_step_store', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy'); - Route::get('/third_step_store', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy'); + Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy'); + Route::post('/second_step_store', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy'); + Route::post('/third_step_store', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy'); + Route::get('/sub_items', 'subItems')->name('subItems'); Route::get('/{safetyAndPrivacy}', 'show')->name('show'); - Route::get('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); + Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize'); }); @@ -339,5 +340,8 @@ Route::prefix('safety_and_privacy_report') ->name('SafetyAndPrivacyReport.') ->controller(SafetyAndPrivacyReportController::class) ->group(function () { - Route::get('/', 'index')->name('index'); + 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'); }); From cc8175a15ee0c0542b002fbcb75eb9fbdb527d86 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 3 Mar 2025 11:28:19 +0330 Subject: [PATCH 46/61] refactor blade files --- .../Dashboard/SafetyAndPrivacyController.php | 16 ++--- .../SafetyAndPrivacyTableService.php | 62 +++++-------------- .../CountryActivityReport.blade.php | 18 +++--- .../ProvinceActivityReport.blade.php | 51 ++++++--------- routes/v3.php | 4 +- 5 files changed, 55 insertions(+), 96 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index 425a203e..36fa1928 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -88,7 +88,7 @@ class SafetyAndPrivacyController extends Controller return $this->successResponse(); } - public function secondStepStore(SafetyAndPrivacy $safety_and_privacy, SecondStepStoreRequest $request): JsonResponse + public function secondStepStore(SafetyAndPrivacy $safetyAndPrivacy, SecondStepStoreRequest $request): JsonResponse { $user = auth()->user(); @@ -100,13 +100,13 @@ class SafetyAndPrivacyController extends Controller return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); } - DB::transaction(function () use ($request, $safety_and_privacy, $user) + DB::transaction(function () use ($request, $safetyAndPrivacy, $user) { $judiciary_document = []; foreach ($request->judiciary_document as $index => $file) { - $judiciary_document[] = FileFacade::save($file, "safety_and_privacy/{$safety_and_privacy->id}/judiciary_document"); + $judiciary_document[] = FileFacade::save($file, "safety_and_privacy/{$safetyAndPrivacy->id}/judiciary_document"); } - $safety_and_privacy->update([ + $safetyAndPrivacy->update([ 'judiciary_document' => serialize($judiciary_document), 'judiciary_document_upload_date' => now(), 'step' => 2, @@ -119,7 +119,7 @@ class SafetyAndPrivacyController extends Controller return $this->successResponse(); } - public function thirdStepStore(SafetyAndPrivacy $safety_and_privacy, ThirdStepStoreRequest $request): JsonResponse + public function thirdStepStore(SafetyAndPrivacy $safetyAndPrivacy, ThirdStepStoreRequest $request): JsonResponse { $user = auth()->user(); @@ -131,11 +131,11 @@ class SafetyAndPrivacyController extends Controller return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!'); } - DB::transaction(function () use ($request, $safety_and_privacy, $user) { - $safety_and_privacy->update([ + DB::transaction(function () use ($request, $safetyAndPrivacy, $user) { + $safetyAndPrivacy->update([ 'step' => 3, 'step_fa' => 'گام سوم (برخورد)', - 'action_picture' => FileFacade::save($request->action_picture, "safety_and_privacy/{$safety_and_privacy->id}/action_picture"), + 'action_picture' => FileFacade::save($request->action_picture, "safety_and_privacy/{$safetyAndPrivacy->id}/action_picture"), 'action_picture_document_upload_date' => now(), ]); diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index 65a1dc3f..7093dbae 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -61,28 +61,12 @@ class SafetyAndPrivacyTableService ); $countryTotalSum = 0; + $activities[]["name_fa"] = 'کشوری'; + $activities[]["province_id"] = -1; foreach ($country as $key => $value) { $countryTotalSum += $value->qty; - $activities[-1]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $activities[-1]["sum"] = $countryTotalSum; - } - - - foreach (Province::all() as $key => $value) { - $activities[$value->id]["info-89"]["step-1"] = 0; - $activities[$value->id]["info-89"]["step-2"] = 0; - $activities[$value->id]["info-89"]["step-3"] = 0; - - $activities[$value->id]["info-90"]["step-1"] = 0; - $activities[$value->id]["info-90"]["step-2"] = 0; - $activities[$value->id]["info-90"]["step-3"] = 0; - - $activities[$value->id]["info-91"]["step-1"] = 0; - $activities[$value->id]["info-91"]["step-2"] = 0; - $activities[$value->id]["info-91"]["step-3"] = 0; - - $activities[$value->id]["sum"] = 0; - $activities[$value->id]["name_fa"] = $value->name_fa; + $activities[][$value->info_id][$value->step] = $value->qty; + $activities[]["sum"] = $countryTotalSum; } $provinces = DB::select( @@ -92,9 +76,10 @@ class SafetyAndPrivacyTableService $provinceTotalSum = 0; foreach ($provinces as $key => $value) { $provinceTotalSum += $value->qty; - $activities[$value->province_id]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $activities[$value->province_id]["sum"] = $provinceTotalSum; - $activities[$value->province_id]["province_fa"] = $value->province_fa; + $activities[][$value->info_id][$value->step] = $value->qty; + $activities[]["sum"] = $provinceTotalSum; + $activities[]["province_fa"] = $value->province_fa; + $activities[]["province_id"] = $value->province_id; } return [ @@ -116,30 +101,14 @@ class SafetyAndPrivacyTableService '); $provinceTotalSum = 0; + $activities[]["name_fa"] = 'استانی'; + $activities[]["edare_shahri_id"] = -1; foreach ($province as $key => $value) { $provinceTotalSum += $value->qty; - $activities[-1]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $activities[-1]["sum"] = $provinceTotalSum; + $activities[]["info-".$value->info_id]["step-".$value->step] = $value->qty; + $activities[]["sum"] = $provinceTotalSum; } - foreach (\App\Models\EdarateShahri::query()->where('province_id', $provinceId)->get() as $key => $value) { - $activities[$value->id]["info-89"]["step-1"] = 0; - $activities[$value->id]["info-89"]["step-2"] = 0; - $activities[$value->id]["info-89"]["step-3"] = 0; - - $activities[$value->id]["info-90"]["step-1"] = 0; - $activities[$value->id]["info-90"]["step-2"] = 0; - $activities[$value->id]["info-90"]["step-3"] = 0; - - $activities[$value->id]["info-91"]["step-1"] = 0; - $activities[$value->id]["info-91"]["step-2"] = 0; - $activities[$value->id]["info-91"]["step-3"] = 0; - - $activities[$value->id]["sum"] = 0; - $activities[$value->id]["name_fa"] = $value->name_fa; - } - - $cities = DB::select(' SELECT edare_shahri_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id '); @@ -147,9 +116,10 @@ class SafetyAndPrivacyTableService $cityTotalSum = 0; foreach ($cities as $key => $value) { $cityTotalSum += $value->qty; - $activities[$value->edare_shahri_id]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $activities[$value->edare_shahri_id][""] = $value; - $activities[$value->edare_shahri_id]["sum"] = $cityTotalSum; + $activities[][$value->info_id][$value->step] = $value->qty; + $activities[]["name_fa"] = \App\Models\EdarateShahri::query()->find($value->edare_shahri_id)->name_fa; + $activities[]["edare_shahri_id"] = $value->edare_shahri_id; + $activities[]["sum"] = $cityTotalSum; } return [ diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php index 2959afed..cdd69930 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php @@ -90,15 +90,15 @@ {{ $item['name_fa'] }} {{ $item['sum'] }} - {{ $item['info-89']['step-1'] }} - {{ $item['info-89']['step-2'] }} - {{ $item['info-89']['step-3'] }} - {{ $item['info-90']['step-1'] }} - {{ $item['info-90']['step-2'] }} - {{ $item['info-90']['step-3'] }} - {{ $item['info-91']['step-1'] }} - {{ $item['info-91']['step-2'] }} - {{ $item['info-91']['step-3'] }} + {{ $item[89][1] }} + {{ $item[89][2] }} + {{ $item[89][3] }} + {{ $item[90][1] }} + {{ $item[90][2] }} + {{ $item[90][3] }} + {{ $item[91][1] }} + {{ $item[91][2] }} + {{ $item[91][3] }} @endforeach diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php index ffe68f28..7faf68c3 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php @@ -88,42 +88,31 @@ @foreach ($data as $item) @if ($item['is_province'] == '1') - - {{ $item['name_fa'] }} - - {{ $item['sum'] }} - - {{ $item['info-89']['step-1'] }} - - {{ $item['info-89']['step-2'] }} - - {{ $item['info-89']['step-3'] }} - - {{ $item['info-90']['step-1'] }} - - {{ $item['info-90']['step-2'] }} - - {{ $item['info-90']['step-3'] }} - - {{ $item['info-91']['step-1'] }} - - {{ $item['info-91']['step-2'] }} - - {{ $item['info-91']['step-3'] }} + {{ $item['name_fa'] }} + {{ $item['sum'] }} + {{ $item[89][1] }} + {{ $item[89][2] }} + {{ $item[89][3] }} + {{ $item[90][1] }} + {{ $item[90][2] }} + {{ $item[90][3] }} + {{ $item[91][1] }} + {{ $item[91][2] }} + {{ $item[91][3] }} @else {{ $item['name_fa'] }} {{ $item['sum'] }} - {{ $item['info-89']['step-1'] }} - {{ $item['info-89']['step-2'] }} - {{ $item['info-89']['step-3'] }} - {{ $item['info-90']['step-1'] }} - {{ $item['info-90']['step-2'] }} - {{ $item['info-90']['step-3'] }} - {{ $item['info-91']['step-1'] }} - {{ $item['info-91']['step-2'] }} - {{ $item['info-91']['step-3'] }} + {{ $item[89][1] }} + {{ $item[89][2] }} + {{ $item[89][3] }} + {{ $item[90][1] }} + {{ $item[90][2] }} + {{ $item[90][3] }} + {{ $item[91][1] }} + {{ $item[91][2] }} + {{ $item[91][3] }} @endif @endforeach diff --git a/routes/v3.php b/routes/v3.php index 199f7d56..d312cf24 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -328,8 +328,8 @@ Route::prefix('safety_and_privacy') ->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::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy'); - Route::post('/second_step_store', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy'); - Route::post('/third_step_store', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy'); + 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('/sub_items', 'subItems')->name('subItems'); Route::get('/{safetyAndPrivacy}', 'show')->name('show'); Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy'); From 3326ab326ece04e0d16c5e6bcff91e69da4e9d10 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 3 Mar 2025 11:59:29 +0330 Subject: [PATCH 47/61] add more detail to api --- .../SafetyAndPrivacyReportController.php | 12 +- .../Dashboard/SafetyAndPrivacyController.php | 2 +- .../SafetyAndPrivacyTableService.php | 104 +++++++++++++++--- 3 files changed, 99 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php index cc4291f8..0b0b5a84 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php @@ -6,6 +6,8 @@ use App\Exports\V3\SafetyAndPrivacy\CountryActivityReport; use App\Exports\V3\SafetyAndPrivacy\ProvinceActivityReport; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; +use App\Models\EdarateShahri; +use App\Models\Province; use App\Services\Cartables\SafetyAndPrivacyTableService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -19,13 +21,19 @@ class SafetyAndPrivacyReportController extends Controller public function countryActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse { $data = $safetyAndPrivacyTableService->countryActivity($request); - return $this->successResponse($data['activities']); + return $this->successResponse([ + 'activities' => $data['activities'], + 'provinces' => Province::all(['id', 'name_fa']) + ]); } public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse { $data = $safetyAndPrivacyTableService->provinceActivity($request); - return $this->successResponse($data['activities']); + return $this->successResponse([ + 'activities' => $data['activities'], + 'edarateShahri' => EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']), + ]); } public function countryExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index 36fa1928..f1562b5d 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -165,7 +165,7 @@ class SafetyAndPrivacyController extends Controller public function deserialize(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse { - $judiciaries = isset($safetyAndPrivacy->judiciary_document) ? unserialize($safetyAndPrivacy->judiciary_document) : []; + $judiciaries = $safetyAndPrivacy->judiciary_document ? unserialize($safetyAndPrivacy->judiciary_document) : []; $result = []; diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index 7093dbae..bd2c253a 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -61,25 +61,61 @@ class SafetyAndPrivacyTableService ); $countryTotalSum = 0; - $activities[]["name_fa"] = 'کشوری'; - $activities[]["province_id"] = -1; + $countryData = [ + 'name_fa' => 'کشوری', + 'province_id' => -1, + '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) { $countryTotalSum += $value->qty; - $activities[][$value->info_id][$value->step] = $value->qty; - $activities[]["sum"] = $countryTotalSum; + $countryData[$value->info_id][$value->step] = $value->qty; + $countryData["sum"] = $countryTotalSum; } + $activities[] = $countryData; $provinces = DB::select( "SELECT province_id, province_fa, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa" ); $provinceTotalSum = 0; + $provinceData = [ + '89' => [ + '1' => 0, + '2' => 0, + '3' => 0, + ], + '90' => [ + '1' => 0, + '2' => 0, + '3' => 0, + ], + '91' => [ + '1' => 0, + '2' => 0, + '3' => 0, + ], + ]; foreach ($provinces as $key => $value) { $provinceTotalSum += $value->qty; - $activities[][$value->info_id][$value->step] = $value->qty; - $activities[]["sum"] = $provinceTotalSum; - $activities[]["province_fa"] = $value->province_fa; - $activities[]["province_id"] = $value->province_id; + $provinceData[$value->info_id][$value->step] = $value->qty; + $provinceData["sum"] = $provinceTotalSum; + $provinceData["province_fa"] = $value->province_fa; + $provinceData["province_id"] = $value->province_id; + $activities[] = $provinceData; } return [ @@ -101,25 +137,61 @@ class SafetyAndPrivacyTableService '); $provinceTotalSum = 0; - $activities[]["name_fa"] = 'استانی'; - $activities[]["edare_shahri_id"] = -1; + $provinceData = [ + 'name_fa' => 'استانی', + 'edare_shahri_id' => -1, + '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) { $provinceTotalSum += $value->qty; - $activities[]["info-".$value->info_id]["step-".$value->step] = $value->qty; - $activities[]["sum"] = $provinceTotalSum; + $provinceData["info-".$value->info_id]["step-".$value->step] = $value->qty; + $provinceData["sum"] = $provinceTotalSum; } + $activities[] = $provinceData; $cities = DB::select(' SELECT edare_shahri_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id '); $cityTotalSum = 0; + $cityData = [ + '89' => [ + '1' => 0, + '2' => 0, + '3' => 0, + ], + '90' => [ + '1' => 0, + '2' => 0, + '3' => 0, + ], + '91' => [ + '1' => 0, + '2' => 0, + '3' => 0, + ], + ]; foreach ($cities as $key => $value) { $cityTotalSum += $value->qty; - $activities[][$value->info_id][$value->step] = $value->qty; - $activities[]["name_fa"] = \App\Models\EdarateShahri::query()->find($value->edare_shahri_id)->name_fa; - $activities[]["edare_shahri_id"] = $value->edare_shahri_id; - $activities[]["sum"] = $cityTotalSum; + $cityData[$value->info_id][$value->step] = $value->qty; + $cityData["name_fa"] = \App\Models\EdarateShahri::query()->find($value->edare_shahri_id)->name_fa; + $cityData["edare_shahri_id"] = $value->edare_shahri_id; + $cityData["sum"] = $cityTotalSum; + $activities[] = $cityData; } return [ From 9f08804454cc61bf106adb21a39cf5bb5b7235ee Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 3 Mar 2025 15:38:06 +0330 Subject: [PATCH 48/61] debug the report tables --- app/Enums/AxisTypes.php | 26 +++++ .../CountryActivityReport.php | 16 +++ .../ProvinceActivityReport.php | 21 +++- .../SafetyAndPrivacyReportController.php | 2 +- .../Dashboard/SafetyAndPrivacyController.php | 3 + .../FirstStepStoreRequest.php | 1 + app/Models/AxisType.php | 13 +++ app/Models/SafetyAndPrivacy.php | 9 +- .../SafetyAndPrivacyTableService.php | 97 ++++++++----------- database/factories/AxisTypeFactory.php | 23 +++++ ...5_03_03_152632_create_axis_types_table.php | 28 ++++++ ...add_column_to_safety_and_privacy_table.php | 30 ++++++ database/seeders/AxisTypeSeeder.php | 17 ++++ routes/v3.php | 1 + 14 files changed, 229 insertions(+), 58 deletions(-) create mode 100644 app/Enums/AxisTypes.php create mode 100644 app/Models/AxisType.php create mode 100644 database/factories/AxisTypeFactory.php create mode 100644 database/migrations/2025_03_03_152632_create_axis_types_table.php create mode 100644 database/migrations/2025_03_03_152816_add_column_to_safety_and_privacy_table.php create mode 100644 database/seeders/AxisTypeSeeder.php diff --git a/app/Enums/AxisTypes.php b/app/Enums/AxisTypes.php new file mode 100644 index 00000000..ae9ac691 --- /dev/null +++ b/app/Enums/AxisTypes.php @@ -0,0 +1,26 @@ + 'آزادراه', + 2 => 'بزرگراه', + 3 => 'اصلی', + 4 => 'فرعی', + 5 => 'روستایی', + ]; + + return $mapArray[$state]; + } +} \ No newline at end of file diff --git a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php index 99a9fb7d..b8c6b0e7 100644 --- a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php @@ -19,6 +19,22 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit public function view(): View { $data = $this->data; + $existedProvinces = array_keys($data['activities']); + + foreach (\App\Models\Province::all() as $value) { + $provinceId = $value->id; + + if (!array_key_exists($provinceId, $existedProvinces)) { + $data['activities'][] = [ + 'province_id' => $provinceId, + 'name_fa' => $value->name_fa, + 'sum' => 0, + '89' => ['1' => 0, '2' => 0, '3' => 0], + '90' => ['1' => 0, '2' => 0, '3' => 0], + '91' => ['1' => 0, '2' => 0, '3' => 0], + ]; + } + } return view('v3.Reports.SafetyAndPrivacy.CountryActivityReport', [ 'data' => $data['activities'], diff --git a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php index c5ffa6ab..78fe8ace 100644 --- a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php @@ -2,8 +2,10 @@ namespace App\Exports\V3\SafetyAndPrivacy; +use App\Models\EdarateShahri; use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Http\Request; use Maatwebsite\Excel\Concerns\FromView; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithDrawings; @@ -14,11 +16,28 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings { - public function __construct(private array $data){} + public function __construct(private array $data, Request $request){} public function view(): View { $data = $this->data; + $existedCities = array_keys($data['activities']); + $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'][] = [ + 'edare_shahri_id' => $edareId, + 'name_fa' => $value->name_fa, + 'sum' => 0, + '89' => ['1' => 0, '2' => 0, '3' => 0], + '90' => ['1' => 0, '2' => 0, '3' => 0], + '91' => ['1' => 0, '2' => 0, '3' => 0], + ]; + } + } return view('v3.Reports.SafetyAndPrivacy.ProvinceActivityReport', [ 'data' => $data['activities'], diff --git a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php index 0b0b5a84..cc3d5673 100644 --- a/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Reports/SafetyAndPrivacyReportController.php @@ -47,6 +47,6 @@ class SafetyAndPrivacyReportController extends Controller { $data = $safetyAndPrivacyTableService->provinceActivity($request); $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - return Excel::download(new ProvinceActivityReport($data), $name); + 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 f1562b5d..a36842d3 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\V3\Dashboard; +use App\Enums\AxisTypes; use App\Exports\V3\SafetyAndPrivacy\CartableReport; use App\Facades\File\FileFacade; use App\Http\Controllers\Controller; @@ -73,6 +74,8 @@ class SafetyAndPrivacyController extends Controller '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' => 1, 'step_fa' => 'گام اول (شناسایی)' ]); diff --git a/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php b/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php index a307f87e..b7b7cf82 100644 --- a/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php +++ b/app/Http/Requests/V3/SafetyAndPrivacy/FirstStepStoreRequest.php @@ -27,6 +27,7 @@ class FirstStepStoreRequest extends FormRequest 'activity_date' => 'required|date_format:Y-m-d', 'activity_time' => 'required|date_format:H:i', 'recognize_picture' => 'required|image', + 'axis_type_id' => 'required|integer|exists:axis_types,id', ]; } diff --git a/app/Models/AxisType.php b/app/Models/AxisType.php new file mode 100644 index 00000000..59fbeec1 --- /dev/null +++ b/app/Models/AxisType.php @@ -0,0 +1,13 @@ + [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '90' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '91' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - ]; - foreach ($provinces as $key => $value) { - $provinceTotalSum += $value->qty; - $provinceData[$value->info_id][$value->step] = $value->qty; - $provinceData["sum"] = $provinceTotalSum; - $provinceData["province_fa"] = $value->province_fa; - $provinceData["province_id"] = $value->province_id; - $activities[] = $provinceData; + foreach ($provinces 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, + 'name_fa' => $value->province_fa, + 'sum' => 0, + '89' => ['1' => 0, '2' => 0, '3' => 0], + '90' => ['1' => 0, '2' => 0, '3' => 0], + '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, @@ -133,7 +127,7 @@ class SafetyAndPrivacyTableService $activities = []; $province = DB::select(' - SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step + 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 '); $provinceTotalSum = 0; @@ -158,42 +152,35 @@ class SafetyAndPrivacyTableService ]; foreach ($province as $key => $value) { $provinceTotalSum += $value->qty; - $provinceData["info-".$value->info_id]["step-".$value->step] = $value->qty; + $provinceData[$value->info_id][$value->step] = $value->qty; $provinceData["sum"] = $provinceTotalSum; } $activities[] = $provinceData; $cities = DB::select(' - SELECT edare_shahri_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id + 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 '); - $cityTotalSum = 0; - $cityData = [ - '89' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '90' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - '91' => [ - '1' => 0, - '2' => 0, - '3' => 0, - ], - ]; - foreach ($cities as $key => $value) { - $cityTotalSum += $value->qty; - $cityData[$value->info_id][$value->step] = $value->qty; - $cityData["name_fa"] = \App\Models\EdarateShahri::query()->find($value->edare_shahri_id)->name_fa; - $cityData["edare_shahri_id"] = $value->edare_shahri_id; - $cityData["sum"] = $cityTotalSum; - $activities[] = $cityData; + foreach ($cities as $value) { + $cityId = $value->edare_shahri_id; + + // Initialize data for each unique city + if (!isset($activities[$cityId])) { + $activities[$cityId] = (object) [ + 'edare_shahri_id' => $cityId, + 'name_fa' => \App\Models\EdarateShahri::query()->find($cityId)->name_fa, + 'sum' => 0, + '89' => ['1' => 0, '2' => 0, '3' => 0], + '90' => ['1' => 0, '2' => 0, '3' => 0], + '91' => ['1' => 0, '2' => 0, '3' => 0], + ]; + } + $activities[$cityId]->{$value->info_id}[$value->step] = $value->qty; + $activities[$cityId]->sum += $value->qty; } + $activities = array_values($activities); + return [ 'activities' => $activities, 'fromDate' => $fromDate, diff --git a/database/factories/AxisTypeFactory.php b/database/factories/AxisTypeFactory.php new file mode 100644 index 00000000..78b69bdf --- /dev/null +++ b/database/factories/AxisTypeFactory.php @@ -0,0 +1,23 @@ + + */ +class AxisTypeFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2025_03_03_152632_create_axis_types_table.php b/database/migrations/2025_03_03_152632_create_axis_types_table.php new file mode 100644 index 00000000..ec264207 --- /dev/null +++ b/database/migrations/2025_03_03_152632_create_axis_types_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('axis_types'); + } +}; diff --git a/database/migrations/2025_03_03_152816_add_column_to_safety_and_privacy_table.php b/database/migrations/2025_03_03_152816_add_column_to_safety_and_privacy_table.php new file mode 100644 index 00000000..f591eba1 --- /dev/null +++ b/database/migrations/2025_03_03_152816_add_column_to_safety_and_privacy_table.php @@ -0,0 +1,30 @@ +foreignId('axis_type_id')->nullable()->constrained('axis_types'); + $table->string('axis_type_name')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('safety_and_privacy', function (Blueprint $table) { + $table->dropForeign('axis_type_id'); + $table->dropColumn('axis_type_name'); + }); + } +}; diff --git a/database/seeders/AxisTypeSeeder.php b/database/seeders/AxisTypeSeeder.php new file mode 100644 index 00000000..f8ae72bc --- /dev/null +++ b/database/seeders/AxisTypeSeeder.php @@ -0,0 +1,17 @@ +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::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'); From 1e933d83843435c1904891c09bbff534449a80cf Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 4 Mar 2025 11:10:35 +0330 Subject: [PATCH 49/61] debug the return types --- .../CountryActivityReport.php | 2 +- .../ProvinceActivityReport.php | 4 +- .../SafetyAndPrivacyTableService.php | 84 +++++++++++++++---- .../CountryActivityReport.blade.php | 22 ++--- .../ProvinceActivityReport.blade.php | 42 +++------- 5 files changed, 94 insertions(+), 60 deletions(-) diff --git a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php index b8c6b0e7..b6e6ccb2 100644 --- a/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php @@ -25,7 +25,7 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit $provinceId = $value->id; if (!array_key_exists($provinceId, $existedProvinces)) { - $data['activities'][] = [ + $data['activities'][] = (object) [ 'province_id' => $provinceId, 'name_fa' => $value->name_fa, 'sum' => 0, diff --git a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php index 78fe8ace..399b5bca 100644 --- a/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php +++ b/app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php @@ -16,7 +16,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings { - public function __construct(private array $data, Request $request){} + public function __construct(private array $data, public Request $request){} public function view(): View { @@ -28,7 +28,7 @@ class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, Wi $edareId = $value->id; if (!array_key_exists($edareId, $existedCities)) { - $data['activities'][] = [ + $data['activities'][] = (object) [ 'edare_shahri_id' => $edareId, 'name_fa' => $value->name_fa, 'sum' => 0, diff --git a/app/Services/Cartables/SafetyAndPrivacyTableService.php b/app/Services/Cartables/SafetyAndPrivacyTableService.php index d635dbe5..e7c9a85d 100644 --- a/app/Services/Cartables/SafetyAndPrivacyTableService.php +++ b/app/Services/Cartables/SafetyAndPrivacyTableService.php @@ -19,8 +19,8 @@ class SafetyAndPrivacyTableService $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', - 'step_fa' + 'info_id','info_fa','activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date', + 'step_fa', 'axis_type_id', 'axis_type_name' ]; if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) { @@ -53,17 +53,30 @@ class SafetyAndPrivacyTableService { $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 = []; - $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 = 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" +// ); $countryTotalSum = 0; $countryData = [ 'name_fa' => 'کشوری', 'province_id' => -1, + 'sum' => 0, '89' => [ '1' => 0, '2' => 0, @@ -85,11 +98,22 @@ class SafetyAndPrivacyTableService $countryData[$value->info_id][$value->step] = $value->qty; $countryData["sum"] = $countryTotalSum; } - $activities[] = $countryData; + $activities[] = (object) $countryData; - $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" - ); + $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) { $provinceId = $value->province_id; @@ -124,16 +148,30 @@ class SafetyAndPrivacyTableService $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 = 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 - '); + $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 +// '); $provinceTotalSum = 0; $provinceData = [ 'name_fa' => 'استانی', 'edare_shahri_id' => -1, + 'sum' => 0, '89' => [ '1' => 0, '2' => 0, @@ -152,14 +190,26 @@ class SafetyAndPrivacyTableService ]; foreach ($province as $key => $value) { $provinceTotalSum += $value->qty; - $provinceData[$value->info_id][$value->step] = $value->qty; $provinceData["sum"] = $provinceTotalSum; + $provinceData[$value->info_id][$value->step] = $value->qty; } - $activities[] = $provinceData; + $activities[] = (object) $provinceData; - $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 - '); + $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(); + +// $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) { $cityId = $value->edare_shahri_id; diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php index cdd69930..f7c5bd53 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/CountryActivityReport.blade.php @@ -88,17 +88,17 @@ @foreach ($data as $item) - {{ $item['name_fa'] }} - {{ $item['sum'] }} - {{ $item[89][1] }} - {{ $item[89][2] }} - {{ $item[89][3] }} - {{ $item[90][1] }} - {{ $item[90][2] }} - {{ $item[90][3] }} - {{ $item[91][1] }} - {{ $item[91][2] }} - {{ $item[91][3] }} + {{ $item->name_fa }} + {{ $item->sum }} + {{ $item->{'89'}[1] }} + {{ $item->{'89'}[2] }} + {{ $item->{'89'}[3] }} + {{ $item->{'90'}[1] }} + {{ $item->{'90'}[2] }} + {{ $item->{'90'}[3] }} + {{ $item->{'91'}[1] }} + {{ $item->{'91'}[2] }} + {{ $item->{'91'}[3] }} @endforeach diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php index 7faf68c3..6d45aca0 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php @@ -86,35 +86,19 @@ @foreach ($data as $item) - @if ($item['is_province'] == '1') - - {{ $item['name_fa'] }} - {{ $item['sum'] }} - {{ $item[89][1] }} - {{ $item[89][2] }} - {{ $item[89][3] }} - {{ $item[90][1] }} - {{ $item[90][2] }} - {{ $item[90][3] }} - {{ $item[91][1] }} - {{ $item[91][2] }} - {{ $item[91][3] }} - - @else - - {{ $item['name_fa'] }} - {{ $item['sum'] }} - {{ $item[89][1] }} - {{ $item[89][2] }} - {{ $item[89][3] }} - {{ $item[90][1] }} - {{ $item[90][2] }} - {{ $item[90][3] }} - {{ $item[91][1] }} - {{ $item[91][2] }} - {{ $item[91][3] }} - - @endif + + {{ $item['name_fa'] }} + {{ $item['sum'] }} + {{ $item->{'89'}[1] }} + {{ $item->{'89'}[2] }} + {{ $item->{'89'}[3] }} + {{ $item->{'90'}[1] }} + {{ $item->{'90'}[2] }} + {{ $item->{'90'}[3] }} + {{ $item->{'91'}[1] }} + {{ $item->{'91'}[2] }} + {{ $item->{'91'}[3] }} + @endforeach From 0813c1f258106087a1a61b06a965e5e7835df1da Mon Sep 17 00:00:00 2001 From: joddyabott Date: Tue, 4 Mar 2025 11:20:21 +0330 Subject: [PATCH 50/61] upgade code v2 to v3 --- .../Dashboard/ItemsManagementController.php | 34 ++++++++++++++++++ .../V3/Dashboard/OtpManagementController.php | 22 ++++++++++++ .../Requests/V3/Otp/GetOtpTokenRequest.php | 35 +++++++++++++++++++ resources/lang/fa/validation.php | 3 +- 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/V3/Dashboard/ItemsManagementController.php create mode 100644 app/Http/Controllers/V3/Dashboard/OtpManagementController.php create mode 100644 app/Http/Requests/V3/Otp/GetOtpTokenRequest.php diff --git a/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php b/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php new file mode 100644 index 00000000..ab52266b --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php @@ -0,0 +1,34 @@ +successResponse( + InfoItem::query() + ->select('item as id', 'item_str as name', 'icon') + ->where('type', '=', 'item') + ->groupby('item') + ->get() + ); + } + + public function getSubItems(InfoItem $item): JsonResponse + { + return $this->successResponse( + InfoItem::query() + ->where('item', '=', $item) + ->select('id', 'item', 'item_str', 'sub_item_str as name', 'sub_item_unit as unit', 'needs_image', 'needs_end_point', 'sub_item') + ->get() + ); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/OtpManagementController.php b/app/Http/Controllers/V3/Dashboard/OtpManagementController.php new file mode 100644 index 00000000..307dc05d --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/OtpManagementController.php @@ -0,0 +1,22 @@ +ip(), $request->phone_number, "کد تایید تلفن همراه سامانه جامع راهداری (RMS) : \n"); + + return $this->successResponse(); + } +} diff --git a/app/Http/Requests/V3/Otp/GetOtpTokenRequest.php b/app/Http/Requests/V3/Otp/GetOtpTokenRequest.php new file mode 100644 index 00000000..9dae8269 --- /dev/null +++ b/app/Http/Requests/V3/Otp/GetOtpTokenRequest.php @@ -0,0 +1,35 @@ +|string> + */ + public function rules(): array + { + return [ + 'phone_number' => 'required|digits:11|starts_with:09', + ]; + } + + public function messages(): array + { + return [ + 'starts_with' => ':attribute باید با :values شروع شود.' + ]; + } +} diff --git a/resources/lang/fa/validation.php b/resources/lang/fa/validation.php index 7f8bc492..5ef3f88f 100644 --- a/resources/lang/fa/validation.php +++ b/resources/lang/fa/validation.php @@ -203,6 +203,7 @@ return [ 'cmms_machine_id' => 'کد یکتا ماشین', 'contract_subitem_id' => 'کد یکتای پروژه', 'base_price' => 'قیمت پایه', - 'unit' => 'واحد' + 'unit' => 'واحد', + 'phone_number'=> 'شماره تلفن' ], ]; From e8fd051e47a2c2940bfb5e4b736e51d69569baa5 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 4 Mar 2025 11:41:23 +0330 Subject: [PATCH 51/61] add routes --- .../ProvinceActivityReport.blade.php | 4 ++-- routes/v3.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php index 6d45aca0..7e156b78 100644 --- a/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php +++ b/resources/views/v3/Reports/SafetyAndPrivacy/ProvinceActivityReport.blade.php @@ -87,8 +87,8 @@ @foreach ($data as $item) - {{ $item['name_fa'] }} - {{ $item['sum'] }} + {{ $item->name_fa }} + {{ $item->sum }} {{ $item->{'89'}[1] }} {{ $item->{'89'}[2] }} {{ $item->{'89'}[3] }} diff --git a/routes/v3.php b/routes/v3.php index 221e4867..75b34a64 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -346,3 +346,17 @@ Route::prefix('safety_and_privacy_report') Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity'); Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity'); }); + +Route::prefix('otp') + ->name('otp.') + ->controller(OtpManagementController::class) + ->group(function () { + Route::get('/get_token', 'getOtpToken')->name('getOtpToken'); + }); + +Route::name('items.') + ->controller(ItemsManagementController::class) + ->group(function () { + Route::get('/items', 'getItems')->name('list'); + Route::get('/sub_items/{item}', 'getSubItems')->name('subItems'); + }); From df8873882785425a41b73dec1362a836c8b537e2 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 4 Mar 2025 14:25:32 +0330 Subject: [PATCH 52/61] add namespace to v3 route --- .../Controllers/V3/Dashboard/ItemsManagementController.php | 2 +- .../Controllers/V3/Dashboard/RoadObservationController.php | 4 +++- routes/v3.php | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php b/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php index ab52266b..dcdf0094 100644 --- a/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/ItemsManagementController.php @@ -22,7 +22,7 @@ class ItemsManagementController extends Controller ); } - public function getSubItems(InfoItem $item): JsonResponse + public function getSubItems($item): JsonResponse { return $this->successResponse( InfoItem::query() diff --git a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php index 6cb292b6..a3b97c4c 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadObservationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadObservationController.php @@ -254,7 +254,9 @@ class RoadObservationController extends Controller { $data = RoadObservationHistory::query() ->where('id', '=', $roadObserved->id) - ->where('action', '=', 'refer')->get([ + ->where('action', '=', 'refer') + ->orderBy('created_at', 'desc') + ->get([ 'created_at', 'description', 'from_edareh', 'to_edareh', 'from_province', 'to_province', 'user_id' ]); diff --git a/routes/v3.php b/routes/v3.php index 75b34a64..43cc8367 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -6,8 +6,10 @@ use App\Http\Controllers\V3\DamageManagementController; use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshController; use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshSampleController; use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshTypeController; +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\Reports\AccidentReceiptReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController; use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController; @@ -351,7 +353,7 @@ Route::prefix('otp') ->name('otp.') ->controller(OtpManagementController::class) ->group(function () { - Route::get('/get_token', 'getOtpToken')->name('getOtpToken'); + Route::post('/get_token', 'getOtpToken')->name('getOtpToken'); }); Route::name('items.') From 67dbeee57b937d3a9e5a5ec1c4527993d95474fe Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 5 Mar 2025 09:51:16 +0330 Subject: [PATCH 53/61] create permission crud --- .../V3/PermissionManagementController.php | 82 +++++++++++++++++++ .../Requests/V3/Permission/StoreRequest.php | 34 ++++++++ .../Requests/V3/Permission/UpdateRequest.php | 34 ++++++++ routes/v3.php | 12 +++ 4 files changed, 162 insertions(+) create mode 100644 app/Http/Controllers/V3/PermissionManagementController.php create mode 100644 app/Http/Requests/V3/Permission/StoreRequest.php create mode 100644 app/Http/Requests/V3/Permission/UpdateRequest.php diff --git a/app/Http/Controllers/V3/PermissionManagementController.php b/app/Http/Controllers/V3/PermissionManagementController.php new file mode 100644 index 00000000..8950767f --- /dev/null +++ b/app/Http/Controllers/V3/PermissionManagementController.php @@ -0,0 +1,82 @@ +successResponse(DataTableFacade::run( + Permission::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'])); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + Permission::create([ + 'name' => $request->name, + 'guard_name' => 'web', + 'name_fa' => $request->name_fa, + 'description' => $request->description, + 'type' => $request->type, + 'type_fa' => $request->type_fa, + 'need_province' => $request->need_province, + 'need_edare_shahri' => $request->need_edare_shahri, + ]); + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(Permission $permission): JsonResponse + { + return $this->successResponse($permission); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, Permission $permission): JsonResponse + { + $permission->update([ + 'name' => $request->name, + 'name_fa' => $request->name_fa, + 'description' => $request->description, + 'type' => $request->type, + 'type_fa' => $request->type_fa, + 'need_province' => $request->need_province, + 'need_edare_shahri' => $request->need_edare_shahri, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Permission $permission): JsonResponse + { + $permission->delete(); + return $this->successResponse(); + } +} diff --git a/app/Http/Requests/V3/Permission/StoreRequest.php b/app/Http/Requests/V3/Permission/StoreRequest.php new file mode 100644 index 00000000..4c04b82b --- /dev/null +++ b/app/Http/Requests/V3/Permission/StoreRequest.php @@ -0,0 +1,34 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|unique:permissions,name', + 'name_fa' => 'required|string', + 'description' => 'required|string', + 'type' => 'required|string', + 'type_fa' => 'required|string', + 'need_province' => 'required|in:0,1', + 'need_edare_shahri' => 'required|in:0,1', + ]; + } +} diff --git a/app/Http/Requests/V3/Permission/UpdateRequest.php b/app/Http/Requests/V3/Permission/UpdateRequest.php new file mode 100644 index 00000000..3c16cab0 --- /dev/null +++ b/app/Http/Requests/V3/Permission/UpdateRequest.php @@ -0,0 +1,34 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => "required|string|unique:permissions,name,{$this->permission->id}", + 'name_fa' => 'required|string', + 'description' => 'required|string', + 'type' => 'required|string', + 'type_fa' => 'required|string', + 'need_province' => 'required|in:0,1', + 'need_edare_shahri' => 'required|in:0,1', + ]; + } +} diff --git a/routes/v3.php b/routes/v3.php index 43cc8367..14306eaf 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -21,6 +21,7 @@ use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacyController; use App\Http\Controllers\V3\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; use App\Http\Controllers\V3\LogListController; +use App\Http\Controllers\V3\PermissionManagementController; use App\Http\Controllers\V3\ProfileController; use App\Http\Controllers\V3\RahdaranController; use Illuminate\Support\Facades\Route; @@ -362,3 +363,14 @@ Route::name('items.') Route::get('/items', 'getItems')->name('list'); Route::get('/sub_items/{item}', 'getSubItems')->name('subItems'); }); + +Route::prefix('permissions') + ->name('permissions.') + ->controller(PermissionManagementController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/', 'store')->name('store'); + Route::get('/{permission}', 'show')->name('show'); + Route::post('/{permission}', 'update')->name('update'); + Route::delete('/{permission}', 'destroy')->name('destroy'); + }); From 01b037f727b3e8a10a67b9984d51f1b2c11ad02f Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 5 Mar 2025 09:56:13 +0330 Subject: [PATCH 54/61] debug the return statement --- app/Http/Controllers/V3/PermissionManagementController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/V3/PermissionManagementController.php b/app/Http/Controllers/V3/PermissionManagementController.php index 8950767f..8ac3eec6 100644 --- a/app/Http/Controllers/V3/PermissionManagementController.php +++ b/app/Http/Controllers/V3/PermissionManagementController.php @@ -19,11 +19,12 @@ class PermissionManagementController extends Controller */ public function index(Request $request): JsonResponse { - return $this->successResponse(DataTableFacade::run( + return response()->json(DataTableFacade::run( Permission::query(), $request, allowedFilters: ['*'], - allowedSortings: ['*'])); + allowedSortings: ['*']) + ); } /** From fa108b23d545a69cabc1ff584c87b275639671cb Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 5 Mar 2025 16:11:04 +0330 Subject: [PATCH 55/61] create notification controller --- app/Exceptions/ProhibitedAction.php | 26 +++ .../Controllers/V3/NotificationController.php | 208 ++++++++++++++++++ routes/v3.php | 5 + 3 files changed, 239 insertions(+) create mode 100644 app/Exceptions/ProhibitedAction.php create mode 100644 app/Http/Controllers/V3/NotificationController.php diff --git a/app/Exceptions/ProhibitedAction.php b/app/Exceptions/ProhibitedAction.php new file mode 100644 index 00000000..1117f997 --- /dev/null +++ b/app/Exceptions/ProhibitedAction.php @@ -0,0 +1,26 @@ +errorResponse($this->message); + } +} diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php new file mode 100644 index 00000000..b1d69c85 --- /dev/null +++ b/app/Http/Controllers/V3/NotificationController.php @@ -0,0 +1,208 @@ +successResponse([ + 'roadItemNotifications' => $this->roadItemNotifications(), + 'safetyAndPrivacyNotifications' => $this->safetyAndPrivacyNotifications(), + 'roadObservedNotifications' => $this->roadObservedNotifications(), + ]); + } + + /** + * @throws Throwable + */ + private function roadItemNotifications(): JsonResponse|array + { + $user = auth()->user(); + $road_items = [ + 'total' => 0 + ]; + + if ($user->hasPermissionTo('create-road-item')) { + $road_items['operation_cnt'] = RoadItemsProject::query() + ->where('is_new', '=', 1) + ->where('user_id', '=', $user->id) + ->where('status', '=', 2) + ->count(); + + $road_items['total'] += $road_items['operation_cnt']; + } + if ($user->hasPermissionTo('supervise-road-item')) { + $road_items['supervise_cnt'] = RoadItemsProject::query() + ->where('is_new', '=', 1) + ->where('status', '=', 0) + ->count(); + + $road_items['total'] += $road_items['supervise_cnt']; + } + elseif ($user->hasPermissionTo('supervise-road-item-province')) { + throw_if(is_null($user->province_id) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + + $road_items['supervise_cnt'] = RoadItemsProject::query() + ->where('is_new', '=', 1) + ->where('province_id', '=', $user->province_id) + ->where('status', '=', 0) + ->count(); + + $road_items['total'] += $road_items['supervise_cnt']; + } + elseif ($user->hasPermissionTo('supervise-road-item-by-edareostani')) { + throw_if(is_null($user->edarate_ostani_id) || !$user->edarate_ostani_id, new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); + + $confirmableItems = EdarateOstani::query()->where('id', '=', $user->edarate_ostani_id)->value('items_for_confirm'); + $road_items['supervise_cnt'] = RoadItemsProject::query() + ->where('is_new', '=', 1) + ->where('province_id', '=', $user->province_id) + ->whereIn('item', explode(",", $confirmableItems)) + ->where('status', '=', 0) + ->count(); + + $road_items['total'] += $road_items['supervise_cnt']; + } + return $road_items; + } + + /** + * @throws Throwable + */ + private function safetyAndPrivacyNotifications(): JsonResponse|array + { + $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(); + + } + elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) { + throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + + $activity = SafetyAndPrivacy::query() + ->where('province_id', '=', $user->province_id) + ->selectRaw('count(*) as cnt, step') + ->groupby('step') + ->orderBy('step') + ->get(); + + } + elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) { + throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); + + $activity = SafetyAndPrivacy::query() + ->where('edare_shahri_id', '=', $user->edarate_shahri_id) + ->selectRaw('count(*) as cnt, step') + ->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; + + return $safety_and_privacy; + } + + /** + * @throws Throwable + */ + private function roadObservedNotifications(): JsonResponse|array + { + $user = auth()->user(); + $road_observations = [ + 'total' => 0 + ]; + + if ($user->hasPermissionTo('show-fast-react')) { + $road_observations['operation_cnt'] = RoadObserved::query() + ->where('status', '=', 2) + ->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query() + ->where('status', '=', 0) + ->count(); + + $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); + } + elseif ($user->hasPermissionTo('show-fast-react-province')) { + throw_if(is_null($user->province_id) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + + $road_observations['operation_cnt'] = RoadObserved::query() + ->where('status', '=', 2) + ->where('rms_province_id', $user->province_id) + ->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query() + ->where('status', '=', 0) + ->count(); + + $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); + } + elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { + throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); + + $road_observations['operation_cnt'] = RoadObserved::query() + ->where('status', '=', 2) + ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) + ->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query() + ->where('status', '=', 0) + ->count(); + + $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); + } + if ($user->hasPermissionTo('supervise-fast-react')) { + $road_observations['supervise_cnt'] = RoadObserved::query() + ->where('status', '=', 0) + ->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query() + ->where('status', '=', 0) + ->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) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + + $road_observations['supervise_cnt'] = RoadObserved::query() + ->where('province_id', '=', $user->province_id) + ->where('status', '=', 0) + ->count(); + + $road_observations['complaint_cnt'] = RoadObserved::query() + ->where('status', '=', 0) + ->count(); + + $road_observations['total'] += ($road_observations['supervise_cnt'] + $road_observations['complaint_cnt']); + } + + return $road_observations; + } +} diff --git a/routes/v3.php b/routes/v3.php index 14306eaf..535b574f 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -21,6 +21,7 @@ use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacyController; use App\Http\Controllers\V3\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; use App\Http\Controllers\V3\LogListController; +use App\Http\Controllers\V3\NotificationController; use App\Http\Controllers\V3\PermissionManagementController; use App\Http\Controllers\V3\ProfileController; use App\Http\Controllers\V3\RahdaranController; @@ -374,3 +375,7 @@ Route::prefix('permissions') Route::post('/{permission}', 'update')->name('update'); Route::delete('/{permission}', 'destroy')->name('destroy'); }); + +Route::prefix('notifications') + ->name('notifications') + ->get('/', NotificationController::class); From 4a4a29cfad198960e0e9c49208d9b27a1b1e5d91 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 8 Mar 2025 09:39:28 +0330 Subject: [PATCH 56/61] rewrite the route name --- app/Http/Controllers/V3/NotificationController.php | 10 +++++----- routes/v3.php | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index b1d69c85..78fd9444 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -144,7 +144,7 @@ class NotificationController extends Controller ->count(); $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('status', '=', 0) + ->where('rms_status', '=', 0) ->count(); $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); @@ -158,7 +158,7 @@ class NotificationController extends Controller ->count(); $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('status', '=', 0) + ->where('rms_status', '=', 0) ->count(); $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); @@ -172,7 +172,7 @@ class NotificationController extends Controller ->count(); $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('status', '=', 0) + ->where('rms_status', '=', 0) ->count(); $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); @@ -183,7 +183,7 @@ class NotificationController extends Controller ->count(); $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('status', '=', 0) + ->where('rms_status', '=', 0) ->count(); $road_observations['total'] += ($road_observations['supervise_cnt'] + $road_observations['complaint_cnt']); @@ -197,7 +197,7 @@ class NotificationController extends Controller ->count(); $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('status', '=', 0) + ->where('rms_status', '=', 0) ->count(); $road_observations['total'] += ($road_observations['supervise_cnt'] + $road_observations['complaint_cnt']); diff --git a/routes/v3.php b/routes/v3.php index 535b574f..cb6a018c 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -376,6 +376,4 @@ Route::prefix('permissions') Route::delete('/{permission}', 'destroy')->name('destroy'); }); -Route::prefix('notifications') - ->name('notifications') - ->get('/', NotificationController::class); +Route::get('/notifications', NotificationController::class)->name('notifications'); From 03e2bcfdf93592131ae2120f33d70dcc3757f557 Mon Sep 17 00:00:00 2001 From: Witel Group Date: Sat, 8 Mar 2025 10:28:11 +0000 Subject: [PATCH 57/61] refactor the speed --- .../Controllers/V3/NotificationController.php | 101 ++++++++---------- 1 file changed, 45 insertions(+), 56 deletions(-) diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index 78fd9444..d322a95a 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -25,9 +25,9 @@ class NotificationController extends Controller public function __invoke(Request $request): JsonResponse { return $this->successResponse([ - 'roadItemNotifications' => $this->roadItemNotifications(), - 'safetyAndPrivacyNotifications' => $this->safetyAndPrivacyNotifications(), - 'roadObservedNotifications' => $this->roadObservedNotifications(), + 'roadItem' => $this->roadItemNotifications(), + 'safetyAndPrivacy' => $this->safetyAndPrivacyNotifications(), + 'roadObserved' => $this->roadObservedNotifications(), ]); } @@ -135,72 +135,61 @@ class NotificationController extends Controller { $user = auth()->user(); $road_observations = [ - 'total' => 0 + 'total' => 0, + 'operation_cnt' => 0, + 'complaint_cnt' => 0, + 'supervise_cnt' => 0 + ]; + + $conditions = []; + $complaintConditions = [ + ['rms_status', '=', 0], + ['edarate_shahri_id', '!=', null] ]; if ($user->hasPermissionTo('show-fast-react')) { - $road_observations['operation_cnt'] = RoadObserved::query() - ->where('status', '=', 2) - ->count(); - - $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('rms_status', '=', 0) - ->count(); - - $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); + $conditions[] = ['status', '=', 2]; } elseif ($user->hasPermissionTo('show-fast-react-province')) { - throw_if(is_null($user->province_id) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); - - $road_observations['operation_cnt'] = RoadObserved::query() - ->where('status', '=', 2) - ->where('rms_province_id', $user->province_id) - ->count(); - - $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('rms_status', '=', 0) - ->count(); - - $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); + throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + $conditions = [ + ['status', '=', 2], + ['rms_province_id', '=', $user->province_id] + ]; + $complaintConditions[] = ['province_id', '=', $user->province_id]; } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); - - $road_observations['operation_cnt'] = RoadObserved::query() - ->where('status', '=', 2) - ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) - ->count(); - - $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('rms_status', '=', 0) - ->count(); - - $road_observations['total'] += ($road_observations['operation_cnt'] + $road_observations['complaint_cnt']); + $conditions = [ + ['status', '=', 2], + ['edarate_shahri_id', '=', $user->edarate_shahri_id] + ]; + $complaintConditions[] = ['edarate_shahri_id', '=', $user->edarate_shahri_id]; } + + 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('status', '=', 0) - ->count(); - - $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('rms_status', '=', 0) - ->count(); - - $road_observations['total'] += ($road_observations['supervise_cnt'] + $road_observations['complaint_cnt']); + $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) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); + 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('province_id', '=', $user->province_id) - ->where('status', '=', 0) - ->count(); - - $road_observations['complaint_cnt'] = RoadObserved::query() - ->where('rms_status', '=', 0) - ->count(); - - $road_observations['total'] += ($road_observations['supervise_cnt'] + $road_observations['complaint_cnt']); + $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']; } return $road_observations; From 5f2cbf5f129218dedfdc764a4e7fc205945b4fb6 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 8 Mar 2025 14:48:03 +0330 Subject: [PATCH 58/61] refactor the web services --- .../Commands/RoadObservationProblems.php | 6 ++ app/Services/NikarayanService.php | 37 +++++--- app/Services/NominatimService.php | 88 ++++++++++++------- config/logging.php | 12 +++ routes/v3.php | 4 +- 5 files changed, 99 insertions(+), 48 deletions(-) diff --git a/app/Console/Commands/RoadObservationProblems.php b/app/Console/Commands/RoadObservationProblems.php index 3c2b3201..e8527113 100755 --- a/app/Console/Commands/RoadObservationProblems.php +++ b/app/Console/Commands/RoadObservationProblems.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use Illuminate\Support\Facades\Log; use SoapFault; use SoapClient; use Illuminate\Console\Command; @@ -84,6 +85,7 @@ class RoadObservationProblems extends Command $msg .= $e->getMessage(); // self::sms_sender('09398586633', $msg); // self::sms_sender('09367487107', $msg); + Log::channel('nikarayan')->error($e->getMessage()); return 0; } $result = serialize($result); @@ -2723,6 +2725,7 @@ class RoadObservationProblems extends Command ] ]; + $affectedRows = 0; $cities = []; foreach ($xml as $value) { // if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 6) { //// code ghabli @@ -2781,6 +2784,7 @@ class RoadObservationProblems extends Command 'city_fa' => $cityModel ? $cityModel->name_fa : null, ] ); + $affectedRows += 1; } } } else { @@ -2788,9 +2792,11 @@ class RoadObservationProblems extends Command $msg = 'rms: error in get data roadobserved babe!!!!' . "\n"; // self::sms_sender('09398586633', $msg); // self::sms_sender('09367487107', $msg); + $this->info('the received body is empty'); return $result; } echo 'done at: ' . date("Y-m-d H:i:s") . "\n"; + $this->info("{$affectedRows} row's affected"); return 0; } public function sms_sender($mobile, $msg) diff --git a/app/Services/NikarayanService.php b/app/Services/NikarayanService.php index 6f2b74bf..da8ab34d 100644 --- a/app/Services/NikarayanService.php +++ b/app/Services/NikarayanService.php @@ -5,29 +5,42 @@ namespace App\Services; use App\Models\RoadObserved; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Log; use SoapClient; +use SoapFault; class NikarayanService { + /** + * @throws SoapFault + */ public function updateRoadObservedInfoByNikarayan(Request $request, RoadObserved $roadObserved, $files) { if (App::isProduction()) { - $url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl"; + try { + $url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl"; - $array = array('strUserName' => 'vaytelrop', - 'strPassword' => 'VaYtelROP*2024', - 'strAutoID' => $roadObserved->fk_RegisteredEventMessage, - 'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3', - 'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description, - 'strPreviousImageLink' => "https://rms.rmto.ir/".$files, - 'strNextImageLink' => "https://rms.rmto.ir/".$files, - 'strRMSDateAndTime' => $roadObserved->updated_at - ); + $array = array('strUserName' => 'vaytelrop', + 'strPassword' => 'VaYtelROP*2024', + 'strAutoID' => $roadObserved->fk_RegisteredEventMessage, + 'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3', + 'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description, + 'strPreviousImageLink' => "https://rms.rmto.ir/".$files, + 'strNextImageLink' => "https://rms.rmto.ir/".$files, + 'strRMSDateAndTime' => $roadObserved->updated_at + ); - $soapClient = new SoapClient($url); + $soapClient = new SoapClient($url); + $result = $soapClient->UpdateInfo_RoadObservedProblems($array); + Log::channel('nikarayan')->info($result); - return $soapClient->UpdateInfo_RoadObservedProblems($array); + return $result; + } + catch (\Exception $e) { + Log::channel('nikarayan')->error($e->getMessage()); + throw $e; + } } return 0; diff --git a/app/Services/NominatimService.php b/app/Services/NominatimService.php index 58815f48..5b1818c4 100644 --- a/app/Services/NominatimService.php +++ b/app/Services/NominatimService.php @@ -2,62 +2,82 @@ namespace App\Services; +use Exception; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Log; class NominatimService { + /** + * @throws Exception + */ public function get_way_id_from_nominatim($lat = null, $lng = null) { if (App::isProduction()) { - $url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16"; - $arrContextOptions=array( - "ssl"=>array( - "verify_peer"=>false, - "verify_peer_name"=>false, - ), - ); + try { + $url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16"; + $arrContextOptions=array( + "ssl"=>array( + "verify_peer"=>false, + "verify_peer_name"=>false, + ), + ); - $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); - $result = json_decode($result); - if (isset($result->osm_type)) { - if ($result->osm_type == 'way') { - return $result->osm_id; + $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); + $result = json_decode($result); + if (isset($result->osm_type)) { + if ($result->osm_type == 'way') { + return $result->osm_id; + } } + return 0; + } + catch (Exception $e) { + Log::channel('nominatim')->error($e->getMessage()); + throw $e; } - return 0; } return 0; } + /** + * @throws Exception + */ function getIDFromNominatim($s_lng, $s_lat, $d_lng, $d_lat) { if (App::isProduction()) { - $url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true"; - $arrContextOptions = array( - "ssl" => array( - "verify_peer" => false, - "verify_peer_name" => false, - ), - ); - $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); - $result = json_decode($result); - if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) { - // if(){ - $ways = $result->routes[1]->legs[0]->steps; - // } - } else - $ways = $result->routes[0]->legs[0]->steps; - $ids = array(); - foreach ($ways as $key => $value) { - if (!in_array($value->name, $ids)) { - $ids[] = $value->name; + try { + $url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true"; + $arrContextOptions = array( + "ssl" => array( + "verify_peer" => false, + "verify_peer_name" => false, + ), + ); + $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); + $result = json_decode($result); + if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) { + // if(){ + $ways = $result->routes[1]->legs[0]->steps; + // } + } else + $ways = $result->routes[0]->legs[0]->steps; + $ids = array(); + foreach ($ways as $key => $value) { + if (!in_array($value->name, $ids)) { + $ids[] = $value->name; + } } - } - return $ids; + return $ids; + } + catch (Exception $e) { + Log::channel('nominatim')->error($e->getMessage()); + throw $e; + } } return [1, 2, 3]; diff --git a/config/logging.php b/config/logging.php index 72cb7076..c0b8208e 100644 --- a/config/logging.php +++ b/config/logging.php @@ -117,6 +117,18 @@ return [ 'path' => storage_path('logs/road_observation_problem.log'), 'level' => 'info', ], + + 'nominatim' => [ + 'driver' => 'single', + 'path' => storage_path('logs/nominatim.log'), + 'level' => 'info', + ], + + 'nikarayan' => [ + 'driver' => 'single', + 'path' => storage_path('logs/nikarayan.log'), + 'level' => 'info', + ], ], ]; diff --git a/routes/v3.php b/routes/v3.php index cb6a018c..26c8af17 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -262,6 +262,7 @@ Route::prefix('receipts') Route::get('/', 'index')->name('index'); Route::get('/excel_report', 'excelReport')->name('excelReport'); Route::post('/', 'store')->name('store'); + Route::get('/accident_types', 'accidentTypes')->name('accidentTypes'); Route::get('/{accident}', 'show')->name('show'); Route::post('/{accident}', 'update')->name('update'); Route::delete('/{accident}', 'destroy')->name('destroy'); @@ -271,7 +272,6 @@ Route::prefix('receipts') Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus'); Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument'); Route::get('/send_sms_again/{accident}', 'sendSmsAgain')->name('sendSmsAgain'); - Route::get('/accident_types', 'accidentTypes')->name('accidentTypes'); }); Route::prefix('receipt_reports') @@ -333,9 +333,9 @@ Route::prefix('safety_and_privacy') 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('/sub_items', 'subItems')->name('subItems'); 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'); From 905cacbd3b89ba85d609fbc22e8d850dccb76abb Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 9 Mar 2025 13:41:00 +0330 Subject: [PATCH 59/61] refactor the web services to be cleaner --- .../Commands/RoadObservationProblems.php | 2741 +---------------- app/Enums/NikarayanComplaints.php | 2643 ++++++++++++++++ .../Requests/V3/Permission/StoreRequest.php | 2 +- .../Requests/V3/Permission/UpdateRequest.php | 2 +- app/Services/NikarayanService.php | 27 + 5 files changed, 2697 insertions(+), 2718 deletions(-) create mode 100644 app/Enums/NikarayanComplaints.php diff --git a/app/Console/Commands/RoadObservationProblems.php b/app/Console/Commands/RoadObservationProblems.php index e8527113..d56da6bb 100755 --- a/app/Console/Commands/RoadObservationProblems.php +++ b/app/Console/Commands/RoadObservationProblems.php @@ -2,6 +2,10 @@ namespace App\Console\Commands; +use App\Enums\NikarayanComplaints; +use App\Services\NikarayanService; +use App\Services\NominatimService; +use Exception; use Illuminate\Support\Facades\Log; use SoapFault; use SoapClient; @@ -39,15 +43,14 @@ class RoadObservationProblems extends Command parent::__construct(); } - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() + /** + * Execute the console command. + * + * @return int|string + * @throws Exception + */ + public function handle(NikarayanService $nikarayanService, NominatimService $nominatimService) { - ////// TODO bayad ba date ham az 1 bahman ye darkhast bedim data koli biad - $url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl"; // try { // $soap_client = new SoapClient($url); // $result = $soap_client->Get_RoadObservedProblems_Current(array('strUserName' => 'vaytelrop', 'strPassword' => 'VaYtelROP*2024')); @@ -59,38 +62,10 @@ class RoadObservationProblems extends Command // // self::sms_sender('09367487107', $msg); // return 0; // } - // echo $v->year = 1395; - // echo "hi\n"; - $v = verta(); // 1396-03-14 14:18:23 - $month = $v->month; - $day = $v->day; - if ($v->month < 10) - $month = '0' . $v->month; - if ($v->day < 10) - $day = '0' . $v->day; - $date = $v->year . $month . $day; - // dd($date); - try { - $soap_client = new SoapClient($url); - $result = $soap_client->Get_RoadObservedProblems_ByDate(array( - 'strUserName' => 'vaytelrop', - 'strPassword' => 'VaYtelROP*2024', - 'strStartDate' => $date, - 'strEndDate' => $date - )); - } catch (SoapFault $e) { - echo $e->getMessage(); - $msg = 'rms: error in get road observation webservice babe!!!!' . "\n"; - $msg .= $e->getMessage(); - // self::sms_sender('09398586633', $msg); - // self::sms_sender('09367487107', $msg); - Log::channel('nikarayan')->error($e->getMessage()); - return 0; - } + $result = $nikarayanService->getRoadObservedProblemsByDate(); + $result = serialize($result); - // return $result; - // dd($result); $x = strpos($result, ' 1, - "57" => 2, - "91" => 3, - "21" => 4, - "18" => 5, - //"83" => 6, - "83" => 7, - "95" => 8, - "11" => 9, - "77" => 10, - "33" => 11, - "31" => 12, - "32" => 13, - "36" => 14, - "67" => 15, - //"26" => 16, - "87" => 17, - "61" => 18, - "41" => 19, - "15" => 20, - "14" => 21, - "73" => 22, - "45" => 23, - //"26" => 24, - "71" => 25, - "85" => 26, - "97" => 27, - "54" => 28, - //"26" => 29, - "81" => 30, - "16" => 31, - "51" => 32, - "64" => 33, - "75" => 34, - "93" => 35, - ]; - - $rmsCityId = [ - 1 => [ - "OnvarID" => 1, - "CityName" => "گمیشان", - "ProvinceID" => "97", - "InvarID" => 353 - ], - 2 => [ - "OnvarID" => 2, - "CityName" => "آق قلا", - "ProvinceID" => "97", - "InvarID" => 13 - ], - 3 => [ - "OnvarID" => 3, - "CityName" => "رامیان", - "ProvinceID" => "97", - "InvarID" => 194 - ], - 4 => [ - "OnvarID" => 4, - "CityName" => "آزادشهر", - "ProvinceID" => "97", - "InvarID" => 8 - ], - 5 => [ - "OnvarID" => 5, - "CityName" => "مینو دشت", - "ProvinceID" => "97", - "InvarID" => 401 - ], - 6 => [ - "OnvarID" => 6, - "CityName" => "گالیكش", - "ProvinceID" => "97", - "InvarID" => 343 - ], - 7 => [ - "OnvarID" => 7, - "CityName" => "علی آباد", - "ProvinceID" => "97", - "InvarID" => 282 - ], - 8 => [ - "OnvarID" => 8, - "CityName" => "گرگان", - "ProvinceID" => "97", - "InvarID" => 347 - ], - 9 => [ - "OnvarID" => 9, - "CityName" => "كردكوی", - "ProvinceID" => "97", - "InvarID" => 324 - ], - 10 => [ - "OnvarID" => 10, - "CityName" => "بندرگز", - "ProvinceID" => "97", - "InvarID" => 80 - ], - 11 => [ - "OnvarID" => 11, - "CityName" => "تركمن", - "ProvinceID" => "97", - "InvarID" => 112 - ], - 12 => [ - "OnvarID" => 12, - "CityName" => "گنبدكاووس", - "ProvinceID" => "97", - "InvarID" => 356 - ], - 13 => [ - "OnvarID" => 13, - "CityName" => "كلاله", - "ProvinceID" => "97", - "InvarID" => 329 - ], - 14 => [ - "OnvarID" => 14, - "CityName" => "مراوه تپه", - "ProvinceID" => "97", - "InvarID" => 374 - ], - 15 => [ - "OnvarID" => 15, - "CityName" => "آستارا", - "ProvinceID" => "54", - "InvarID" => 9 - ], - 16 => [ - "OnvarID" => 16, - "CityName" => "طوالش", - "ProvinceID" => "54", - "InvarID" => 278 - ], - 17 => [ - "OnvarID" => 17, - "CityName" => "رضوانشهر", - "ProvinceID" => "54", - "InvarID" => 201 - ], - 18 => [ - "OnvarID" => 18, - "CityName" => "ماسال", - "ProvinceID" => "54", - "InvarID" => 366 - ], - 19 => [ - "OnvarID" => 19, - "CityName" => "بندر انزلی", - "ProvinceID" => "54", - "InvarID" => 76 - ], - 20 => [ - "OnvarID" => 20, - "CityName" => "صومعه سرا", - "ProvinceID" => "54", - "InvarID" => 274 - ], - 21 => [ - "OnvarID" => 21, - "CityName" => "فومن", - "ProvinceID" => "54", - "InvarID" => 300 - ], - 22 => [ - "OnvarID" => 22, - "CityName" => "شفت", - "ProvinceID" => "54", - "InvarID" => 260 - ], - 23 => [ - "OnvarID" => 23, - "CityName" => "املش", - "ProvinceID" => "54", - "InvarID" => 40 - ], - 24 => [ - "OnvarID" => 24, - "CityName" => "رودسر", - "ProvinceID" => "54", - "InvarID" => 207 - ], - 25 => [ - "OnvarID" => 25, - "CityName" => "آستانه اشرفیه", - "ProvinceID" => "54", - "InvarID" => 10 - ], - 26 => [ - "OnvarID" => 26, - "CityName" => "لاهیجان", - "ProvinceID" => "54", - "InvarID" => 361 - ], - 27 => [ - "OnvarID" => 27, - "CityName" => "رشت", - "ProvinceID" => "54", - "InvarID" => 199 - ], - 28 => [ - "OnvarID" => 28, - "CityName" => "سیاهكل", - "ProvinceID" => "54", - "InvarID" => 248 - ], - 29 => [ - "OnvarID" => 29, - "CityName" => "لنگرود", - "ProvinceID" => "54", - "InvarID" => 365 - ], - 30 => [ - "OnvarID" => 30, - "CityName" => "رودبار", - "ProvinceID" => "54", - "InvarID" => 205 - ], - 31 => [ - "OnvarID" => 31, - "CityName" => "آباده", - "ProvinceID" => "41", - "InvarID" => 2 - ], - 32 => [ - "OnvarID" => 32, - "CityName" => "ممسنی", - "ProvinceID" => "41", - "InvarID" => 385 - ], - 33 => [ - "OnvarID" => 33, - "CityName" => "سپیدان", - "ProvinceID" => "41", - "InvarID" => 225 - ], - 34 => [ - "OnvarID" => 34, - "CityName" => "رستم", - "ProvinceID" => "41", - "InvarID" => 198 - ], - 35 => [ - "OnvarID" => 35, - "CityName" => "پاسارگاد", - "ProvinceID" => "41", - "InvarID" => 99 - ], - 36 => [ - "OnvarID" => 36, - "CityName" => "بوانات", - "ProvinceID" => "41", - "InvarID" => 89 - ], - 37 => [ - "OnvarID" => 37, - "CityName" => "خرم بید", - "ProvinceID" => "41", - "InvarID" => 149 - ], - 38 => [ - "OnvarID" => 38, - "CityName" => "اقلید", - "ProvinceID" => "41", - "InvarID" => 37 - ], - 39 => [ - "OnvarID" => 39, - "CityName" => "كازرون", - "ProvinceID" => "41", - "InvarID" => 318 - ], - 40 => [ - "OnvarID" => 40, - "CityName" => "سروستان", - "ProvinceID" => "41", - "InvarID" => 237 - ], - 41 => [ - "OnvarID" => 41, - "CityName" => "كوار", - "ProvinceID" => "41", - "InvarID" => 337 - ], - 42 => [ - "OnvarID" => 42, - "CityName" => "خرامه", - "ProvinceID" => "41", - "InvarID" => 147 - ], - 43 => [ - "OnvarID" => 43, - "CityName" => "شیراز", - "ProvinceID" => "41", - "InvarID" => 270 - ], - 44 => [ - "OnvarID" => 44, - "CityName" => "مرودشت", - "ProvinceID" => "41", - "InvarID" => 376 - ], - 45 => [ - "OnvarID" => 45, - "CityName" => "ارسنجان", - "ProvinceID" => "41", - "InvarID" => 25 - ], - 46 => [ - "OnvarID" => 46, - "CityName" => "نی ریز", - "ProvinceID" => "41", - "InvarID" => 414 - ], - 47 => [ - "OnvarID" => 47, - "CityName" => "فراشبند", - "ProvinceID" => "41", - "InvarID" => 288 - ], - 48 => [ - "OnvarID" => 48, - "CityName" => "جهرم", - "ProvinceID" => "41", - "InvarID" => 127 - ], - 49 => [ - "OnvarID" => 49, - "CityName" => "قیر و كارزین", - "ProvinceID" => "41", - "InvarID" => 316 - ], - 50 => [ - "OnvarID" => 50, - "CityName" => "فیروز آباد", - "ProvinceID" => "41", - "InvarID" => 301 - ], - 51 => [ - "OnvarID" => 51, - "CityName" => "داراب", - "ProvinceID" => "41", - "InvarID" => 165 - ], - 52 => [ - "OnvarID" => 52, - "CityName" => "زرین دشت", - "ProvinceID" => "41", - "InvarID" => 216 - ], - 53 => [ - "OnvarID" => 53, - "CityName" => "مهر", - "ProvinceID" => "41", - "InvarID" => 3 - ], - 54 => [ - "OnvarID" => 54, - "CityName" => "خنج", - "ProvinceID" => "41", - "InvarID" => 390 - ], - 55 => [ - "OnvarID" => 55, - "CityName" => "لامرد", - "ProvinceID" => "41", - "InvarID" => 360 - ], - 56 => [ - "OnvarID" => 56, - "CityName" => "گراش", - "ProvinceID" => "41", - "InvarID" => 346 - ], - 57 => [ - "OnvarID" => 57, - "CityName" => "لارستان", - "ProvinceID" => "41", - "InvarID" => 358 - ], - 58 => [ - "OnvarID" => 58, - "CityName" => "فسا", - "ProvinceID" => "41", - "InvarID" => 296 - ], - 59 => [ - "OnvarID" => 59, - "CityName" => "استهبان", - "ProvinceID" => "41", - "InvarID" => 28 - ], - 60 => [ - "OnvarID" => 60, - "CityName" => "آران و بیدگل", - "ProvinceID" => "21", - "InvarID" => 7 - ], - 61 => [ - "OnvarID" => 61, - "CityName" => "بوئین و میان دشت", - "ProvinceID" => "21", - "InvarID" => 88 - ], - 62 => [ - "OnvarID" => 62, - "CityName" => "خوانسار", - "ProvinceID" => "21", - "InvarID" => 160 - ], - 63 => [ - "OnvarID" => 63, - "CityName" => "گلپایگان", - "ProvinceID" => "21", - "InvarID" => 351 - ], - 64 => [ - "OnvarID" => 64, - "CityName" => "اردستان", - "ProvinceID" => "21", - "InvarID" => 21 - ], - 65 => [ - "OnvarID" => 65, - "CityName" => "كاشان", - "ProvinceID" => "21", - "InvarID" => 319 - ], - 66 => [ - "OnvarID" => 66, - "CityName" => "خور و بیابانك", - "ProvinceID" => "21", - "InvarID" => 161 - ], - 67 => [ - "OnvarID" => 67, - "CityName" => "چادگان", - "ProvinceID" => "21", - "InvarID" => 133 - ], - 68 => [ - "OnvarID" => 68, - "CityName" => "فریدن", - "ProvinceID" => "21", - "InvarID" => 292 - ], - 69 => [ - "OnvarID" => 69, - "CityName" => "فریدون شهر", - "ProvinceID" => "21", - "InvarID" => 293 - ], - 70 => [ - "OnvarID" => 70, - "CityName" => "شهرضا", - "ProvinceID" => "21", - "InvarID" => 263 - ], - 71 => [ - "OnvarID" => 71, - "CityName" => "مباركه", - "ProvinceID" => "21", - "InvarID" => 370 - ], - 72 => [ - "OnvarID" => 72, - "CityName" => "لنجان", - "ProvinceID" => "21", - "InvarID" => 363 - ], - 73 => [ - "OnvarID" => 73, - "CityName" => "اصفهان", - "ProvinceID" => "21", - "InvarID" => 36 - ], - 74 => [ - "OnvarID" => 74, - "CityName" => "فلاورجان", - "ProvinceID" => "21", - "InvarID" => 297 - ], - 75 => [ - "OnvarID" => 75, - "CityName" => "نجف آباد", - "ProvinceID" => "21", - "InvarID" => 403 - ], - 76 => [ - "OnvarID" => 76, - "CityName" => "خمینی شهر", - "ProvinceID" => "21", - "InvarID" => 156 - ], - 77 => [ - "OnvarID" => 77, - "CityName" => "تیران و كرون", - "ProvinceID" => "21", - "InvarID" => 120 - ], - 78 => [ - "OnvarID" => 78, - "CityName" => "برخوار", - "ProvinceID" => "21", - "InvarID" => 64 - ], - 79 => [ - "OnvarID" => 79, - "CityName" => "نائین", - "ProvinceID" => "21", - "InvarID" => 402 - ], - 80 => [ - "OnvarID" => 80, - "CityName" => "سمیرم", - "ProvinceID" => "21", - "InvarID" => 243 - ], - 81 => [ - "OnvarID" => 81, - "CityName" => "دهاقان", - "ProvinceID" => "21", - "InvarID" => 181 - ], - 82 => [ - "OnvarID" => 82, - "CityName" => "نطنز", - "ProvinceID" => "21", - "InvarID" => 405 - ], - 83 => [ - "OnvarID" => 83, - "CityName" => "شاهین شهر و میمه", - "ProvinceID" => "21", - "InvarID" => 258 - ], - 84 => [ - "OnvarID" => 84, - "CityName" => "مراغه", - "ProvinceID" => "26", - "InvarID" => 373 - ], - 85 => [ - "OnvarID" => 85, - "CityName" => "خدا آفرین", - "ProvinceID" => "26", - "InvarID" => 145 - ], - 86 => [ - "OnvarID" => 86, - "CityName" => "جلفا", - "ProvinceID" => "26", - "InvarID" => 125 - ], - 87 => [ - "OnvarID" => 87, - "CityName" => "شبستر", - "ProvinceID" => "26", - "InvarID" => 259 - ], - 88 => [ - "OnvarID" => 88, - "CityName" => "مرند", - "ProvinceID" => "26", - "InvarID" => 375 - ], - 89 => [ - "OnvarID" => 89, - "CityName" => "تبریز", - "ProvinceID" => "26", - "InvarID" => 109 - ], - 90 => [ - "OnvarID" => 90, - "CityName" => "ورزقان", - "ProvinceID" => "26", - "InvarID" => 429 - ], - 91 => [ - "OnvarID" => 91, - "CityName" => "اهر", - "ProvinceID" => "26", - "InvarID" => 45 - ], - 92 => [ - "OnvarID" => 92, - "CityName" => "كلیبر", - "ProvinceID" => "26", - "InvarID" => 330 - ], - 93 => [ - "OnvarID" => 93, - "CityName" => "اسكو", - "ProvinceID" => "26", - "InvarID" => 31 - ], - 94 => [ - "OnvarID" => 94, - "CityName" => "آذرشهر", - "ProvinceID" => "26", - "InvarID" => 5 - ], - 95 => [ - "OnvarID" => 95, - "CityName" => "عجب شیر", - "ProvinceID" => "26", - "InvarID" => 280 - ], - 96 => [ - "OnvarID" => 96, - "CityName" => "بناب", - "ProvinceID" => "26", - "InvarID" => 75 - ], - 97 => [ - "OnvarID" => 97, - "CityName" => "ملكان", - "ProvinceID" => "26", - "InvarID" => 383 - ], - 98 => [ - "OnvarID" => 98, - "CityName" => "بستان آباد", - "ProvinceID" => "26", - "InvarID" => 69 - ], - 99 => [ - "OnvarID" => 99, - "CityName" => "سراب", - "ProvinceID" => "26", - "InvarID" => 226 - ], - 100 => [ - "OnvarID" => 100, - "CityName" => "هشترود", - "ProvinceID" => "26", - "InvarID" => 422 - ], - 101 => [ - "OnvarID" => 101, - "CityName" => "میانه", - "ProvinceID" => "26", - "InvarID" => 397 - ], - 102 => [ - "OnvarID" => 102, - "CityName" => "چاراویماق", - "ProvinceID" => "26", - "InvarID" => 134 - ], - 103 => [ - "OnvarID" => 103, - "CityName" => "هریس", - "ProvinceID" => "26", - "InvarID" => 421 - ], - 104 => [ - "OnvarID" => 104, - "CityName" => "هوراند", - "ProvinceID" => "26", - "InvarID" => 109 - ], - 105 => [ - "OnvarID" => 105, - "CityName" => "كیار", - "ProvinceID" => "77", - "InvarID" => 342 - ], - 106 => [ - "OnvarID" => 106, - "CityName" => "فارسان", - "ProvinceID" => "77", - "InvarID" => 284 - ], - 107 => [ - "OnvarID" => 107, - "CityName" => "كوهرنگ", - "ProvinceID" => "77", - "InvarID" => 341 - ], - 108 => [ - "OnvarID" => 108, - "CityName" => "لردگان", - "ProvinceID" => "77", - "InvarID" => 362 - ], - 109 => [ - "OnvarID" => 109, - "CityName" => "اردل", - "ProvinceID" => "77", - "InvarID" => 23 - ], - 110 => [ - "OnvarID" => 110, - "CityName" => "بروجن", - "ProvinceID" => "77", - "InvarID" => 68 - ], - 111 => [ - "OnvarID" => 111, - "CityName" => "سامان", - "ProvinceID" => "77", - "InvarID" => 221 - ], - 112 => [ - "OnvarID" => 112, - "CityName" => "بن", - "ProvinceID" => "77", - "InvarID" => 74 - ], - 113 => [ - "OnvarID" => 113, - "CityName" => "شهركرد", - "ProvinceID" => "77", - "InvarID" => 264 - ], - 114 => [ - "OnvarID" => 114, - "CityName" => "دیلم", - "ProvinceID" => "95", - "InvarID" => 187 - ], - 115 => [ - "OnvarID" => 115, - "CityName" => "گناوه", - "ProvinceID" => "95", - "InvarID" => 395 - ], - 116 => [ - "OnvarID" => 116, - "CityName" => "دشتستان", - "ProvinceID" => "95", - "InvarID" => 174 - ], - 117 => [ - "OnvarID" => 117, - "CityName" => "دشتی", - "ProvinceID" => "95", - "InvarID" => 175 - ], - 118 => [ - "OnvarID" => 118, - "CityName" => "بوشهر", - "ProvinceID" => "95", - "InvarID" => 90 - ], - 119 => [ - "OnvarID" => 119, - "CityName" => "تنگستان", - "ProvinceID" => "95", - "InvarID" => 117 - ], - 120 => [ - "OnvarID" => 120, - "CityName" => "دیر", - "ProvinceID" => "95", - "InvarID" => 186 - ], - 121 => [ - "OnvarID" => 121, - "CityName" => "جم", - "ProvinceID" => "95", - "InvarID" => 126 - ], - 122 => [ - "OnvarID" => 122, - "CityName" => "كنگان", - "ProvinceID" => "95", - "InvarID" => 333 - ], - 123 => [ - "OnvarID" => 123, - "CityName" => "عسلویه", - "ProvinceID" => "95", - "InvarID" => 281 - ], - 124 => [ - "OnvarID" => 124, - "CityName" => "مهران", - "ProvinceID" => "83", - "InvarID" => 391 - ], - 125 => [ - "OnvarID" => 125, - "CityName" => "ایلام", - "ProvinceID" => "83", - "InvarID" => 50 - ], - 126 => [ - "OnvarID" => 126, - "CityName" => "ایوان", - "ProvinceID" => "83", - "InvarID" => 51 - ], - 127 => [ - "OnvarID" => 127, - "CityName" => "دره شهر", - "ProvinceID" => "83", - "InvarID" => 171 - ], - 128 => [ - "OnvarID" => 128, - "CityName" => "ملكشاهی", - "ProvinceID" => "83", - "InvarID" => 384 - ], - 129 => [ - "OnvarID" => 129, - "CityName" => "سیروان", - "ProvinceID" => "83", - "InvarID" => 251 - ], - 130 => [ - "OnvarID" => 130, - "CityName" => "بدره", - "ProvinceID" => "83", - "InvarID" => 63 - ], - 131 => [ - "OnvarID" => 131, - "CityName" => "چرداول", - "ProvinceID" => "71", - "InvarID" => 139 - ], - 132 => [ - "OnvarID" => 132, - "CityName" => "دهلران", - "ProvinceID" => "83", - "InvarID" => 183 - ], - 133 => [ - "OnvarID" => 133, - "CityName" => "آبدانان", - "ProvinceID" => "83", - "InvarID" => 3 - ], - 134 => [ - "OnvarID" => 134, - "CityName" => "راور", - "ProvinceID" => "45", - "InvarID" => 195 - ], - 135 => [ - "OnvarID" => 135, - "CityName" => "كوهبنان", - "ProvinceID" => "45", - "InvarID" => 339 - ], - 136 => [ - "OnvarID" => 136, - "CityName" => "شهر بابك", - "ProvinceID" => "45", - "InvarID" => 262 - ], - 137 => [ - "OnvarID" => 137, - "CityName" => "انار", - "ProvinceID" => "45", - "InvarID" => 42 - ], - 138 => [ - "OnvarID" => 138, - "CityName" => "رفسنجان", - "ProvinceID" => "45", - "InvarID" => 202 - ], - 139 => [ - "OnvarID" => 139, - "CityName" => "زرند", - "ProvinceID" => "45", - "InvarID" => 214 - ], - 140 => [ - "OnvarID" => 140, - "CityName" => "كرمان", - "ProvinceID" => "45", - "InvarID" => 325 - ], - 141 => [ - "OnvarID" => 141, - "CityName" => "رابر", - "ProvinceID" => "45", - "InvarID" => 189 - ], - 142 => [ - "OnvarID" => 142, - "CityName" => "بافت", - "ProvinceID" => "45", - "InvarID" => 57 - ], - 143 => [ - "OnvarID" => 143, - "CityName" => "سیرجان", - "ProvinceID" => "45", - "InvarID" => 250 - ], - 144 => [ - "OnvarID" => 144, - "CityName" => "بردسیر", - "ProvinceID" => "45", - "InvarID" => 66 - ], - 145 => [ - "OnvarID" => 145, - "CityName" => "ارزوئیه", - "ProvinceID" => "45", - "InvarID" => 24 - ], - 146 => [ - "OnvarID" => 146, - "CityName" => "ریگان", - "ProvinceID" => "45", - "InvarID" => 210 - ], - 147 => [ - "OnvarID" => 147, - "CityName" => "فهرج", - "ProvinceID" => "45", - "InvarID" => 299 - ], - 148 => [ - "OnvarID" => 148, - "CityName" => "نرماشیر", - "ProvinceID" => "45", - "InvarID" => 404 - ], - 149 => [ - "OnvarID" => 149, - "CityName" => "منوجان", - "ProvinceID" => "45", - "InvarID" => 386 - ], - 150 => [ - "OnvarID" => 150, - "CityName" => "قلعه گنج", - "ProvinceID" => "45", - "InvarID" => 313 - ], - 151 => [ - "OnvarID" => 151, - "CityName" => "كهنوج", - "ProvinceID" => "45", - "InvarID" => 336 - ], - 152 => [ - "OnvarID" => 152, - "CityName" => "فاریاب", - "ProvinceID" => "45", - "InvarID" => 286 - ], - 153 => [ - "OnvarID" => 153, - "CityName" => "رودبار جنوب", - "ProvinceID" => "45", - "InvarID" => 205 - ], - 154 => [ - "OnvarID" => 154, - "CityName" => "عنبرآباد", - "ProvinceID" => "45", - "InvarID" => 283 - ], - 155 => [ - "OnvarID" => 155, - "CityName" => "جیرفت", - "ProvinceID" => "45", - "InvarID" => 131 - ], - 156 => [ - "OnvarID" => 156, - "CityName" => "بم", - "ProvinceID" => "45", - "InvarID" => 73 - ], - 157 => [ - "OnvarID" => 157, - "CityName" => "گیلانغرب", - "ProvinceID" => "71", - "InvarID" => 357 - ], - 158 => [ - "OnvarID" => 158, - "CityName" => "دالاهو", - "ProvinceID" => "71", - "InvarID" => 166 - ], - 159 => [ - "OnvarID" => 159, - "CityName" => "قصر شیرین", - "ProvinceID" => "71", - "InvarID" => 311 - ], - 160 => [ - "OnvarID" => 160, - "CityName" => "سر پل ذهاب", - "ProvinceID" => "71", - "InvarID" => 231 - ], - 161 => [ - "OnvarID" => 161, - "CityName" => "ثلاث باباجانی", - "ProvinceID" => "71", - "InvarID" => 121 - ], - 162 => [ - "OnvarID" => 162, - "CityName" => "جوانرود", - "ProvinceID" => "71", - "InvarID" => 128 - ], - 163 => [ - "OnvarID" => 163, - "CityName" => "اسلام آباد غرب", - "ProvinceID" => "71", - "InvarID" => 32 - ], - 164 => [ - "OnvarID" => 164, - "CityName" => "هرسین", - "ProvinceID" => "71", - "InvarID" => 420 - ], - 165 => [ - "OnvarID" => 165, - "CityName" => "كنگاور", - "ProvinceID" => "71", - "InvarID" => 334 - ], - 166 => [ - "OnvarID" => 166, - "CityName" => "روانسر", - "ProvinceID" => "71", - "InvarID" => 203 - ], - 167 => [ - "OnvarID" => 167, - "CityName" => "سنقر", - "ProvinceID" => "71", - "InvarID" => 244 - ], - 168 => [ - "OnvarID" => 168, - "CityName" => "صحنه", - "ProvinceID" => "71", - "InvarID" => 272 - ], - 169 => [ - "OnvarID" => 169, - "CityName" => "پاوه", - "ProvinceID" => "71", - "InvarID" => 101 - ], - 170 => [ - "OnvarID" => 170, - "CityName" => "كرمانشاه", - "ProvinceID" => "71", - "InvarID" => 326 - ], - 171 => [ - "OnvarID" => 171, - "CityName" => "قوچان", - "ProvinceID" => "31", - "InvarID" => 315 - ], - 172 => [ - "OnvarID" => 172, - "CityName" => "درگز", - "ProvinceID" => "31", - "InvarID" => 169 - ], - 173 => [ - "OnvarID" => 173, - "CityName" => "داورزن", - "ProvinceID" => "31", - "InvarID" => 168 - ], - 174 => [ - "OnvarID" => 174, - "CityName" => "سبزوار", - "ProvinceID" => "31", - "InvarID" => 224 - ], - 175 => [ - "OnvarID" => 175, - "CityName" => "خوشاب", - "ProvinceID" => "31", - "InvarID" => 163 - ], - 176 => [ - "OnvarID" => 176, - "CityName" => "جغتای", - "ProvinceID" => "31", - "InvarID" => 124 - ], - 177 => [ - "OnvarID" => 177, - "CityName" => "جوین", - "ProvinceID" => "31", - "InvarID" => 130 - ], - 178 => [ - "OnvarID" => 178, - "CityName" => "مشهد", - "ProvinceID" => "31", - "InvarID" => 380 - ], - 179 => [ - "OnvarID" => 179, - "CityName" => "بینالود", - "ProvinceID" => "31", - "InvarID" => 96 - ], - 180 => [ - "OnvarID" => 180, - "CityName" => "نیشابور", - "ProvinceID" => "31", - "InvarID" => 416 - ], - 181 => [ - "OnvarID" => 181, - "CityName" => "فیروزه", - "ProvinceID" => "31", - "InvarID" => 303 - ], - 182 => [ - "OnvarID" => 182, - "CityName" => "چناران", - "ProvinceID" => "31", - "InvarID" => 140 - ], - 183 => [ - "OnvarID" => 183, - "CityName" => "كلات", - "ProvinceID" => "31", - "InvarID" => 327 - ], - 184 => [ - "OnvarID" => 184, - "CityName" => "سرخس", - "ProvinceID" => "31", - "InvarID" => 232 - ], - 185 => [ - "OnvarID" => 185, - "CityName" => "كاشمر", - "ProvinceID" => "31", - "InvarID" => 320 - ], - 186 => [ - "OnvarID" => 186, - "CityName" => "خلیل آباد", - "ProvinceID" => "31", - "InvarID" => 153 - ], - 187 => [ - "OnvarID" => 187, - "CityName" => "مه ولایت", - "ProvinceID" => "31", - "InvarID" => 387 - ], - 188 => [ - "OnvarID" => 188, - "CityName" => "تربت حیدریه", - "ProvinceID" => "31", - "InvarID" => 111 - ], - 189 => [ - "OnvarID" => 189, - "CityName" => "زاوه", - "ProvinceID" => "31", - "InvarID" => 213 - ], - 190 => [ - "OnvarID" => 190, - "CityName" => "فریمان", - "ProvinceID" => "31", - "InvarID" => 295 - ], - 191 => [ - "OnvarID" => 191, - "CityName" => "تربت جام", - "ProvinceID" => "31", - "InvarID" => 110 - ], - 192 => [ - "OnvarID" => 192, - "CityName" => "بردسكن", - "ProvinceID" => "31", - "InvarID" => 65 - ], - 193 => [ - "OnvarID" => 193, - "CityName" => "بجستان", - "ProvinceID" => "31", - "InvarID" => 61 - ], - 194 => [ - "OnvarID" => 194, - "CityName" => "گناباد", - "ProvinceID" => "31", - "InvarID" => 354 - ], - 195 => [ - "OnvarID" => 195, - "CityName" => "رشتخوار", - "ProvinceID" => "31", - "InvarID" => 200 - ], - 196 => [ - "OnvarID" => 196, - "CityName" => "خواف", - "ProvinceID" => "31", - "InvarID" => 159 - ], - 197 => [ - "OnvarID" => 197, - "CityName" => "تایباد", - "ProvinceID" => "31", - "InvarID" => 108 - ], - 198 => [ - "OnvarID" => 198, - "CityName" => "باخرز", - "ProvinceID" => "31", - "InvarID" => 54 - ], - 199 => [ - "OnvarID" => 199, - "CityName" => "فردوس", - "ProvinceID" => "33", - "InvarID" => 290 - ], - 200 => [ - "OnvarID" => 200, - "CityName" => "طبس", - "ProvinceID" => "33", - "InvarID" => 277 - ], - 201 => [ - "OnvarID" => 201, - "CityName" => "بشرویه", - "ProvinceID" => "33", - "InvarID" => 72 - ], - 202 => [ - "OnvarID" => 202, - "CityName" => "سرایان", - "ProvinceID" => "33", - "InvarID" => 228 - ], - 203 => [ - "OnvarID" => 203, - "CityName" => "قائنات", - "ProvinceID" => "33", - "InvarID" => 305 - ], - 204 => [ - "OnvarID" => 204, - "CityName" => "زیركوه", - "ProvinceID" => "33", - "InvarID" => 219 - ], - 205 => [ - "OnvarID" => 205, - "CityName" => "سربیشه", - "ProvinceID" => "33", - "InvarID" => 230 - ], - 206 => [ - "OnvarID" => 206, - "CityName" => "خوسف", - "ProvinceID" => "33", - "InvarID" => 162 - ], - 207 => [ - "OnvarID" => 207, - "CityName" => "بیرجند", - "ProvinceID" => "33", - "InvarID" => 94 - ], - 208 => [ - "OnvarID" => 208, - "CityName" => "درمیان", - "ProvinceID" => "33", - "InvarID" => 170 - ], - 209 => [ - "OnvarID" => 209, - "CityName" => "نهبندان", - "ProvinceID" => "33", - "InvarID" => 411 - ], - 210 => [ - "OnvarID" => 210, - "CityName" => "شوشتر", - "ProvinceID" => "36", - "InvarID" => 268 - ], - 211 => [ - "OnvarID" => 211, - "CityName" => "اندیكا", - "ProvinceID" => "36", - "InvarID" => 43 - ], - 212 => [ - "OnvarID" => 212, - "CityName" => "لالی", - "ProvinceID" => "36", - "InvarID" => 359 - ], - 213 => [ - "OnvarID" => 213, - "CityName" => "گتوند", - "ProvinceID" => "36", - "InvarID" => 344 - ], - 214 => [ - "OnvarID" => 214, - "CityName" => "شوش", - "ProvinceID" => "36", - "InvarID" => 267 - ], - 215 => [ - "OnvarID" => 215, - "CityName" => "اندیمشك", - "ProvinceID" => "36", - "InvarID" => 44 - ], - 216 => [ - "OnvarID" => 216, - "CityName" => "دزفول", - "ProvinceID" => "36", - "InvarID" => 172 - ], - 217 => [ - "OnvarID" => 217, - "CityName" => "كارون", - "ProvinceID" => "36", - "InvarID" => 317 - ], - 218 => [ - "OnvarID" => 218, - "CityName" => "هویزه", - "ProvinceID" => "36", - "InvarID" => 426 - ], - 219 => [ - "OnvarID" => 219, - "CityName" => "حمیدیه", - "ProvinceID" => "36", - "InvarID" => 142 - ], - 220 => [ - "OnvarID" => 220, - "CityName" => "باوی", - "ProvinceID" => "36", - "InvarID" => 60 - ], - 221 => [ - "OnvarID" => 221, - "CityName" => "دشت آزادگان", - "ProvinceID" => "36", - "InvarID" => 173 - ], - 222 => [ - "OnvarID" => 222, - "CityName" => "مسجد سلیمان", - "ProvinceID" => "36", - "InvarID" => 378 - ], - 223 => [ - "OnvarID" => 223, - "CityName" => "هفتگل", - "ProvinceID" => "36", - "InvarID" => 423 - ], - 224 => [ - "OnvarID" => 224, - "CityName" => "رامهرمز", - "ProvinceID" => "36", - "InvarID" => 193 - ], - 225 => [ - "OnvarID" => 225, - "CityName" => "باغ ملك", - "ProvinceID" => "36", - "InvarID" => 56 - ], - 226 => [ - "OnvarID" => 226, - "CityName" => "ایذه", - "ProvinceID" => "36", - "InvarID" => 48 - ], - 227 => [ - "OnvarID" => 227, - "CityName" => "شادگان", - "ProvinceID" => "36", - "InvarID" => 254 - ], - 228 => [ - "OnvarID" => 228, - "CityName" => "رامشیر", - "ProvinceID" => "36", - "InvarID" => 192 - ], - 229 => [ - "OnvarID" => 229, - "CityName" => "هندیجان", - "ProvinceID" => "36", - "InvarID" => 425 - ], - 230 => [ - "OnvarID" => 230, - "CityName" => "بهبهان", - "ProvinceID" => "36", - "InvarID" => 84 - ], - 231 => [ - "OnvarID" => 231, - "CityName" => "آغاجاری", - "ProvinceID" => "36", - "InvarID" => 12 - ], - 232 => [ - "OnvarID" => 232, - "CityName" => "امیدیه", - "ProvinceID" => "36", - "InvarID" => 41 - ], - 233 => [ - "OnvarID" => 233, - "CityName" => "آبادان", - "ProvinceID" => "36", - "InvarID" => 1 - ], - 234 => [ - "OnvarID" => 234, - "CityName" => "خرمشهر", - "ProvinceID" => "36", - "InvarID" => 151 - ], - 235 => [ - "OnvarID" => 235, - "CityName" => "اهواز", - "ProvinceID" => "36", - "InvarID" => 46 - ], - 236 => [ - "OnvarID" => 236, - "CityName" => "بندر ماهشهر", - "ProvinceID" => "36", - "InvarID" => 78 - ], - 237 => [ - "OnvarID" => 237, - "CityName" => "گچساران", - "ProvinceID" => "85", - "InvarID" => 345 - ], - 238 => [ - "OnvarID" => 238, - "CityName" => "بهمئی", - "ProvinceID" => "85", - "InvarID" => 86 - ], - 239 => [ - "OnvarID" => 239, - "CityName" => "كهگیلویه", - "ProvinceID" => "85", - "InvarID" => 335 - ], - 240 => [ - "OnvarID" => 240, - "CityName" => "چرام", - "ProvinceID" => "85", - "InvarID" => 138 - ], - 241 => [ - "OnvarID" => 241, - "CityName" => "لنده", - "ProvinceID" => "85", - "InvarID" => 364 - ], - 242 => [ - "OnvarID" => 242, - "CityName" => "باشت", - "ProvinceID" => "85", - "InvarID" => 55 - ], - 243 => [ - "OnvarID" => 243, - "CityName" => "بویراحمد", - "ProvinceID" => "85", - "InvarID" => 92 - ], - 244 => [ - "OnvarID" => 244, - "CityName" => "دنا", - "ProvinceID" => "85", - "InvarID" => 180 - ], - 245 => [ - "OnvarID" => 245, - "CityName" => "پارس آباد", - "ProvinceID" => "91", - "InvarID" => 97 - ], - 246 => [ - "OnvarID" => 246, - "CityName" => "گرمی", - "ProvinceID" => "91", - "InvarID" => 350 - ], - 247 => [ - "OnvarID" => 247, - "CityName" => "بیله سوار", - "ProvinceID" => "91", - "InvarID" => 95 - ], - 248 => [ - "OnvarID" => 248, - "CityName" => "مشگین شهر", - "ProvinceID" => "91", - "InvarID" => 379 - ], - 249 => [ - "OnvarID" => 249, - "CityName" => "نیر", - "ProvinceID" => "91", - "InvarID" => 415 - ], - 250 => [ - "OnvarID" => 250, - "CityName" => "نمین", - "ProvinceID" => "91", - "InvarID" => 409 - ], - 251 => [ - "OnvarID" => 251, - "CityName" => "اردبیل", - "ProvinceID" => "91", - "InvarID" => 20 - ], - 252 => [ - "OnvarID" => 252, - "CityName" => "سرعین", - "ProvinceID" => "91", - "InvarID" => 235 - ], - 253 => [ - "OnvarID" => 253, - "CityName" => "كوثر", - "ProvinceID" => "91", - "InvarID" => 338 - ], - 254 => [ - "OnvarID" => 254, - "CityName" => "خلخال", - "ProvinceID" => "91", - "InvarID" => 152 - ], - 255 => [ - "OnvarID" => 255, - "CityName" => "حاجی آباد", - "ProvinceID" => "64", - "InvarID" => 141 - ], - 256 => [ - "OnvarID" => 256, - "CityName" => "پارسیان", - "ProvinceID" => "64", - "InvarID" => 98 - ], - 257 => [ - "OnvarID" => 257, - "CityName" => "بستك", - "ProvinceID" => "64", - "InvarID" => 70 - ], - 258 => [ - "OnvarID" => 258, - "CityName" => "بندر عباس", - "ProvinceID" => "64", - "InvarID" => 79 - ], - 259 => [ - "OnvarID" => 259, - "CityName" => "میناب", - "ProvinceID" => "64", - "InvarID" => 400 - ], - 260 => [ - "OnvarID" => 260, - "CityName" => "رودان", - "ProvinceID" => "64", - "InvarID" => 204 - ], - 261 => [ - "OnvarID" => 261, - "CityName" => "بندر لنگه", - "ProvinceID" => "64", - "InvarID" => 77 - ], - 262 => [ - "OnvarID" => 262, - "CityName" => "خمیر", - "ProvinceID" => "64", - "InvarID" => 154 - ], - 263 => [ - "OnvarID" => 263, - "CityName" => "بشاگرد", - "ProvinceID" => "64", - "InvarID" => 71 - ], - 264 => [ - "OnvarID" => 264, - "CityName" => "سیریك", - "ProvinceID" => "64", - "InvarID" => 252 - ], - 265 => [ - "OnvarID" => 265, - "CityName" => "جاسك", - "ProvinceID" => "64", - "InvarID" => 123 - ], - 266 => [ - "OnvarID" => 266, - "CityName" => "ابوموسی", - "ProvinceID" => "NULL", - "InvarID" => 18 - ], - 267 => [ - "OnvarID" => 267, - "CityName" => "قشم", - "ProvinceID" => "64", - "InvarID" => 310 - ], - 268 => [ - "OnvarID" => 268, - "CityName" => "طالقان", - "ProvinceID" => "18", - "InvarID" => 276 - ], - 269 => [ - "OnvarID" => 269, - "CityName" => "اشتهارد", - "ProvinceID" => "18", - "InvarID" => 34 - ], - 270 => [ - "OnvarID" => 270, - "CityName" => "كرج", - "ProvinceID" => "18", - "InvarID" => 323 - ], - 271 => [ - "OnvarID" => 271, - "CityName" => "فردیس", - "ProvinceID" => "18", - "InvarID" => 291 - ], - 272 => [ - "OnvarID" => 272, - "CityName" => "ساوجبلاغ", - "ProvinceID" => "18", - "InvarID" => 222 - ], - 273 => [ - "OnvarID" => 273, - "CityName" => "نظر آباد", - "ProvinceID" => "18", - "InvarID" => 406 - ], - 274 => [ - "OnvarID" => 274, - "CityName" => "فامنین", - "ProvinceID" => "75", - "InvarID" => 287 - ], - 275 => [ - "OnvarID" => 275, - "CityName" => "كبودرآهنگ", - "ProvinceID" => "75", - "InvarID" => 322 - ], - 276 => [ - "OnvarID" => 276, - "CityName" => "رزن", - "ProvinceID" => "75", - "InvarID" => 197 - ], - 277 => [ - "OnvarID" => 277, - "CityName" => "ملایر", - "ProvinceID" => "75", - "InvarID" => 382 - ], - 278 => [ - "OnvarID" => 278, - "CityName" => "نهاوند", - "ProvinceID" => "75", - "InvarID" => 410 - ], - 279 => [ - "OnvarID" => 279, - "CityName" => "تویسركان", - "ProvinceID" => "75", - "InvarID" => 119 - ], - 280 => [ - "OnvarID" => 280, - "CityName" => "اسد آباد", - "ProvinceID" => "75", - "InvarID" => 29 - ], - 281 => [ - "OnvarID" => 281, - "CityName" => "همدان", - "ProvinceID" => "75", - "InvarID" => 424 - ], - 282 => [ - "OnvarID" => 282, - "CityName" => "بهار", - "ProvinceID" => "75", - "InvarID" => 82 - ], - 283 => [ - "OnvarID" => 283, - "CityName" => "سقز", - "ProvinceID" => "73", - "InvarID" => 238 - ], - 284 => [ - "OnvarID" => 284, - "CityName" => "سرو آباد", - "ProvinceID" => "73", - "InvarID" => 236 - ], - 285 => [ - "OnvarID" => 285, - "CityName" => "مریوان", - "ProvinceID" => "73", - "InvarID" => 377 - ], - 286 => [ - "OnvarID" => 286, - "CityName" => "بانه", - "ProvinceID" => "73", - "InvarID" => 59 - ], - 287 => [ - "OnvarID" => 287, - "CityName" => "قروه", - "ProvinceID" => "73", - "InvarID" => 308 - ], - 288 => [ - "OnvarID" => 288, - "CityName" => "دهگلان", - "ProvinceID" => "73", - "InvarID" => 182 - ], - 289 => [ - "OnvarID" => 289, - "CityName" => "سنندج", - "ProvinceID" => "73", - "InvarID" => 245 - ], - 290 => [ - "OnvarID" => 290, - "CityName" => "بیجار", - "ProvinceID" => "73", - "InvarID" => 93 - ], - 291 => [ - "OnvarID" => 291, - "CityName" => "دیواندره", - "ProvinceID" => "73", - "InvarID" => 188 - ], - 292 => [ - "OnvarID" => 292, - "CityName" => "كامیاران", - "ProvinceID" => "73", - "InvarID" => 321 - ], - 293 => [ - "OnvarID" => 293, - "CityName" => "دلفان", - "ProvinceID" => "81", - "InvarID" => 176 - ], - 294 => [ - "OnvarID" => 294, - "CityName" => "پل دختر", - "ProvinceID" => "81", - "InvarID" => 103 - ], - 295 => [ - "OnvarID" => 295, - "CityName" => "رومشكان", - "ProvinceID" => "81", - "InvarID" => 208 - ], - 296 => [ - "OnvarID" => 296, - "CityName" => "كوه دشت", - "ProvinceID" => "81", - "InvarID" => 340 - ], - 297 => [ - "OnvarID" => 297, - "CityName" => "دوره", - "ProvinceID" => "81", - "InvarID" => 184 - ], - 298 => [ - "OnvarID" => 298, - "CityName" => "خرم آباد", - "ProvinceID" => "81", - "InvarID" => 148 - ], - 299 => [ - "OnvarID" => 299, - "CityName" => "دورود", - "ProvinceID" => "81", - "InvarID" => 185 - ], - 300 => [ - "OnvarID" => 300, - "CityName" => "ازنا", - "ProvinceID" => "81", - "InvarID" => 27 - ], - 301 => [ - "OnvarID" => 301, - "CityName" => "سلسله", - "ProvinceID" => "81", - "InvarID" => 239 - ], - 302 => [ - "OnvarID" => 302, - "CityName" => "بروجرد", - "ProvinceID" => "81", - "InvarID" => 67 - ], - 303 => [ - "OnvarID" => 303, - "CityName" => "الیگودرز", - "ProvinceID" => "81", - "InvarID" => 39 - ], - 304 => [ - "OnvarID" => 304, - "CityName" => "ساوه", - "ProvinceID" => "51", - "InvarID" => 223 - ], - 305 => [ - "OnvarID" => 305, - "CityName" => "زرندیه", - "ProvinceID" => "51", - "InvarID" => 215 - ], - 306 => [ - "OnvarID" => 306, - "CityName" => "خنداب", - "ProvinceID" => "51", - "InvarID" => 158 - ], - 307 => [ - "OnvarID" => 307, - "CityName" => "كمیجان", - "ProvinceID" => "51", - "InvarID" => 331 - ], - 308 => [ - "OnvarID" => 308, - "CityName" => "اراك", - "ProvinceID" => "51", - "InvarID" => 19 - ], - 309 => [ - "OnvarID" => 309, - "CityName" => "فراهان", - "ProvinceID" => "51", - "InvarID" => 289 - ], - 310 => [ - "OnvarID" => 310, - "CityName" => "آشتیان", - "ProvinceID" => "51", - "InvarID" => 11 - ], - 311 => [ - "OnvarID" => 311, - "CityName" => "تفرش", - "ProvinceID" => "51", - "InvarID" => 114 - ], - 312 => [ - "OnvarID" => 312, - "CityName" => "شازند", - "ProvinceID" => "51", - "InvarID" => 255 - ], - 313 => [ - "OnvarID" => 313, - "CityName" => "خمین", - "ProvinceID" => "51", - "InvarID" => 155 - ], - 314 => [ - "OnvarID" => 314, - "CityName" => "دلیجان", - "ProvinceID" => "51", - "InvarID" => 178 - ], - 315 => [ - "OnvarID" => 315, - "CityName" => "محلات", - "ProvinceID" => "51", - "InvarID" => 371 - ], - 316 => [ - "OnvarID" => 316, - "CityName" => "چالوس", - "ProvinceID" => "16", - "InvarID" => 136 - ], - 317 => [ - "OnvarID" => 317, - "CityName" => "عباس آباد", - "ProvinceID" => "16", - "InvarID" => 279 - ], - 318 => [ - "OnvarID" => 318, - "CityName" => "كلاردشت", - "ProvinceID" => "16", - "InvarID" => 328 - ], - 319 => [ - "OnvarID" => 319, - "CityName" => "تنكابن", - "ProvinceID" => "16", - "InvarID" => 116 - ], - 320 => [ - "OnvarID" => 320, - "CityName" => "رامسر", - "ProvinceID" => "16", - "InvarID" => 191 - ], - 321 => [ - "OnvarID" => 321, - "CityName" => "آمل", - "ProvinceID" => "16", - "InvarID" => 14 - ], - 322 => [ - "OnvarID" => 322, - "CityName" => "نور", - "ProvinceID" => "16", - "InvarID" => 412 - ], - 323 => [ - "OnvarID" => 323, - "CityName" => "نوشهر", - "ProvinceID" => "16", - "InvarID" => 413 - ], - 324 => [ - "OnvarID" => 324, - "CityName" => "محمودآباد", - "ProvinceID" => "16", - "InvarID" => 372 - ], - 325 => [ - "OnvarID" => 325, - "CityName" => "فریدونكنار", - "ProvinceID" => "16", - "InvarID" => 294 - ], - 326 => [ - "OnvarID" => 326, - "CityName" => "سوادكوه", - "ProvinceID" => "16", - "InvarID" => 246 - ], - 327 => [ - "OnvarID" => 327, - "CityName" => "سوادكوه شمالی", - "ProvinceID" => "16", - "InvarID" => 247 - ], - 328 => [ - "OnvarID" => 328, - "CityName" => "قائمشهر", - "ProvinceID" => "16", - "InvarID" => 304 - ], - 329 => [ - "OnvarID" => 329, - "CityName" => "میاندورود", - "ProvinceID" => "16", - "InvarID" => 395 - ], - 330 => [ - "OnvarID" => 330, - "CityName" => "ساری", - "ProvinceID" => "16", - "InvarID" => 220 - ], - 331 => [ - "OnvarID" => 331, - "CityName" => "بابل", - "ProvinceID" => "16", - "InvarID" => 52 - ], - 332 => [ - "OnvarID" => 332, - "CityName" => "سیمرغ", - "ProvinceID" => "16", - "InvarID" => 253 - ], - 333 => [ - "OnvarID" => 333, - "CityName" => "جویبار", - "ProvinceID" => "16", - "InvarID" => 129 - ], - 334 => [ - "OnvarID" => 334, - "CityName" => "نكا", - "ProvinceID" => "16", - "InvarID" => 408 - ], - 335 => [ - "OnvarID" => 335, - "CityName" => "گلوگاه", - "ProvinceID" => "16", - "InvarID" => 352 - ], - 336 => [ - "OnvarID" => 336, - "CityName" => "بهشهر", - "ProvinceID" => "16", - "InvarID" => 85 - ], - 337 => [ - "OnvarID" => 337, - "CityName" => "بابلسر", - "ProvinceID" => "16", - "InvarID" => 53 - ], - 338 => [ - "OnvarID" => 338, - "CityName" => "تاكستان", - "ProvinceID" => "15", - "InvarID" => 107 - ], - 339 => [ - "OnvarID" => 339, - "CityName" => "آبیك", - "ProvinceID" => "15", - "InvarID" => 4 - ], - 340 => [ - "OnvarID" => 340, - "CityName" => "البرز", - "ProvinceID" => "15", - "InvarID" => 38 - ], - 341 => [ - "OnvarID" => 341, - "CityName" => "قزوین", - "ProvinceID" => "15", - "InvarID" => 309 - ], - 342 => [ - "OnvarID" => 342, - "CityName" => "آوج", - "ProvinceID" => "15", - "InvarID" => 15 - ], - 343 => [ - "OnvarID" => 343, - "CityName" => "بوئین زهرا", - "ProvinceID" => "15", - "InvarID" => 87 - ], - 344 => [ - "OnvarID" => 344, - "CityName" => "قم", - "ProvinceID" => "14", - "InvarID" => 314 - ], - 345 => [ - "OnvarID" => 345, - "CityName" => "دامغان", - "ProvinceID" => "87", - "InvarID" => 167 - ], - 346 => [ - "OnvarID" => 346, - "CityName" => "شاهرود", - "ProvinceID" => "87", - "InvarID" => 256 - ], - 347 => [ - "OnvarID" => 347, - "CityName" => "میامی", - "ProvinceID" => "87", - "InvarID" => 394 - ], - 348 => [ - "OnvarID" => 348, - "CityName" => "سرخه", - "ProvinceID" => "87", - "InvarID" => 233 - ], - 349 => [ - "OnvarID" => 349, - "CityName" => "سمنان", - "ProvinceID" => "87", - "InvarID" => 242 - ], - 350 => [ - "OnvarID" => 350, - "CityName" => "مهدیشهر", - "ProvinceID" => "87", - "InvarID" => 389 - ], - 351 => [ - "OnvarID" => 351, - "CityName" => "آرادان", - "ProvinceID" => "87", - "InvarID" => 6 - ], - 352 => [ - "OnvarID" => 352, - "CityName" => "گرمسار", - "ProvinceID" => "87", - "InvarID" => 348 - ], - 353 => [ - "OnvarID" => 353, - "CityName" => "ممانه و سملقان", - "ProvinceID" => "32", - "InvarID" => 368 - ], - 354 => [ - "OnvarID" => 354, - "CityName" => "راز و جرگلان", - "ProvinceID" => "32", - "InvarID" => 190 - ], - 355 => [ - "OnvarID" => 355, - "CityName" => "اسفراین", - "ProvinceID" => "32", - "InvarID" => 30 - ], - 356 => [ - "OnvarID" => 356, - "CityName" => "فاروج", - "ProvinceID" => "32", - "InvarID" => 285 - ], - 357 => [ - "OnvarID" => 357, - "CityName" => "شیروان", - "ProvinceID" => "32", - "InvarID" => 271 - ], - 358 => [ - "OnvarID" => 358, - "CityName" => "بجنورد", - "ProvinceID" => "32", - "InvarID" => 62 - ], - 359 => [ - "OnvarID" => 359, - "CityName" => "جاجرم", - "ProvinceID" => "32", - "InvarID" => 122 - ], - 360 => [ - "OnvarID" => 360, - "CityName" => "گرمه", - "ProvinceID" => "32", - "InvarID" => 349 - ], - 361 => [ - "OnvarID" => 361, - "CityName" => "نیمروز", - "ProvinceID" => "61", - "InvarID" => 418 - ], - 362 => [ - "OnvarID" => 362, - "CityName" => "هیرمند", - "ProvinceID" => "61", - "InvarID" => 427 - ], - 363 => [ - "OnvarID" => 363, - "CityName" => "هامون", - "ProvinceID" => "61", - "InvarID" => 419 - ], - 364 => [ - "OnvarID" => 364, - "CityName" => "زابل", - "ProvinceID" => "61", - "InvarID" => 211 - ], - 365 => [ - "OnvarID" => 365, - "CityName" => "زهك", - "ProvinceID" => "61", - "InvarID" => 218 - ], - 366 => [ - "OnvarID" => 366, - "CityName" => "میرجاوه", - "ProvinceID" => "61", - "InvarID" => 399 - ], - 367 => [ - "OnvarID" => 367, - "CityName" => "زاهدان", - "ProvinceID" => "61", - "InvarID" => 212 - ], - 368 => [ - "OnvarID" => 368, - "CityName" => "خاش", - "ProvinceID" => "61", - "InvarID" => 144 - ], - 369 => [ - "OnvarID" => 369, - "CityName" => "دلگان", - "ProvinceID" => "61", - "InvarID" => 177 - ], - 370 => [ - "OnvarID" => 370, - "CityName" => "ایرانشهر", - "ProvinceID" => "61", - "InvarID" => 49 - ], - 371 => [ - "OnvarID" => 371, - "CityName" => "مهرستان", - "ProvinceID" => "61", - "InvarID" => 392 - ], - 372 => [ - "OnvarID" => 372, - "CityName" => "سیب و سواران", - "ProvinceID" => "61", - "InvarID" => 249 - ], - 373 => [ - "OnvarID" => 373, - "CityName" => "سراوان", - "ProvinceID" => "61", - "InvarID" => 227 - ], - 374 => [ - "OnvarID" => 374, - "CityName" => "فنوج", - "ProvinceID" => "61", - "InvarID" => 298 - ], - 375 => [ - "OnvarID" => 375, - "CityName" => "سرباز", - "ProvinceID" => "61", - "InvarID" => 229 - ], - 376 => [ - "OnvarID" => 376, - "CityName" => "قصر قند", - "ProvinceID" => "61", - "InvarID" => 312 - ], - 377 => [ - "OnvarID" => 377, - "CityName" => "نیك شهر", - "ProvinceID" => "61", - "InvarID" => 417 - ], - 378 => [ - "OnvarID" => 378, - "CityName" => "چاه بهار", - "ProvinceID" => "61", - "InvarID" => 132 - ], - 379 => [ - "OnvarID" => 379, - "CityName" => "كنارك", - "ProvinceID" => "61", - "InvarID" => 332 - ], - 380 => [ - "OnvarID" => 380, - "CityName" => "فیروزكوه", - "ProvinceID" => "11", - "InvarID" => 302 - ], - 381 => [ - "OnvarID" => 381, - "CityName" => "ملارد", - "ProvinceID" => "11", - "InvarID" => 381 - ], - 382 => [ - "OnvarID" => 382, - "CityName" => "پیشوا", - "ProvinceID" => "11", - "InvarID" => 106 - ], - 383 => [ - "OnvarID" => 383, - "CityName" => "قرچك", - "ProvinceID" => "11", - "InvarID" => 307 - ], - 384 => [ - "OnvarID" => 384, - "CityName" => "پاكدشت", - "ProvinceID" => "11", - "InvarID" => 100 - ], - 385 => [ - "OnvarID" => 385, - "CityName" => "پردیس", - "ProvinceID" => "11", - "InvarID" => 102 - ], - 386 => [ - "OnvarID" => 386, - "CityName" => "دماوند", - "ProvinceID" => "11", - "InvarID" => 179 - ], - 387 => [ - "OnvarID" => 387, - "CityName" => "ری", - "ProvinceID" => "11", - "InvarID" => 209 - ], - 388 => [ - "OnvarID" => 388, - "CityName" => "اسلامشهر", - "ProvinceID" => "11", - "InvarID" => 33 - ], - 389 => [ - "OnvarID" => 389, - "CityName" => "قدس", - "ProvinceID" => "11", - "InvarID" => 306 - ], - 390 => [ - "OnvarID" => 390, - "CityName" => "شهریار", - "ProvinceID" => "11", - "InvarID" => 265 - ], - 391 => [ - "OnvarID" => 391, - "CityName" => "ورامین", - "ProvinceID" => "11", - "InvarID" => 428 - ], - 392 => [ - "OnvarID" => 392, - "CityName" => "تهران", - "ProvinceID" => "11", - "InvarID" => 118 - ], - 393 => [ - "OnvarID" => 393, - "CityName" => "شمیرانات", - "ProvinceID" => "11", - "InvarID" => 261 - ], - 394 => [ - "OnvarID" => 394, - "CityName" => "رباط كریم", - "ProvinceID" => "11", - "InvarID" => 196 - ], - 395 => [ - "OnvarID" => 395, - "CityName" => "بهارستان", - "ProvinceID" => "11", - "InvarID" => 83 - ], - 396 => [ - "OnvarID" => 396, - "CityName" => "چالدران", - "ProvinceID" => "57", - "InvarID" => 135 - ], - 397 => [ - "OnvarID" => 397, - "CityName" => "شوط", - "ProvinceID" => "57", - "InvarID" => 269 - ], - 398 => [ - "OnvarID" => 398, - "CityName" => "ماكو", - "ProvinceID" => "57", - "InvarID" => 367 - ], - 399 => [ - "OnvarID" => 399, - "CityName" => "خوی", - "ProvinceID" => "57", - "InvarID" => 164 - ], - 400 => [ - "OnvarID" => 400, - "CityName" => "سلماس", - "ProvinceID" => "57", - "InvarID" => 241 - ], - 401 => [ - "OnvarID" => 401, - "CityName" => "پلدشت", - "ProvinceID" => "57", - "InvarID" => 104 - ], - 402 => [ - "OnvarID" => 402, - "CityName" => "جایپاره", - "ProvinceID" => "57", - "InvarID" => 137 - ], - 403 => [ - "OnvarID" => 403, - "CityName" => "ارومیه", - "ProvinceID" => "57", - "InvarID" => 26 - ], - 404 => [ - "OnvarID" => 404, - "CityName" => "اشنویه", - "ProvinceID" => "57", - "InvarID" => 35 - ], - 405 => [ - "OnvarID" => 405, - "CityName" => "سردشت", - "ProvinceID" => "57", - "InvarID" => 234 - ], - 406 => [ - "OnvarID" => 406, - "CityName" => "بوكان", - "ProvinceID" => "57", - "InvarID" => 91 - ], - 407 => [ - "OnvarID" => 407, - "CityName" => "مهاباد", - "ProvinceID" => "57", - "InvarID" => 388 - ], - 408 => [ - "OnvarID" => 408, - "CityName" => "پیرانشهر", - "ProvinceID" => "57", - "InvarID" => 105 - ], - 409 => [ - "OnvarID" => 409, - "CityName" => "میاندوآب", - "ProvinceID" => "26", - "InvarID" => 396 - ], - 410 => [ - "OnvarID" => 410, - "CityName" => "نقده", - "ProvinceID" => "57", - "InvarID" => 407 - ], - 411 => [ - "OnvarID" => 411, - "CityName" => "تكاب", - "ProvinceID" => "57", - "InvarID" => 115 - ], - 412 => [ - "OnvarID" => 412, - "CityName" => "شاهین دژ", - "ProvinceID" => "57", - "InvarID" => 257 - ], - 413 => [ - "OnvarID" => 413, - "CityName" => "اشكذر", - "ProvinceID" => "93", - "InvarID" => 430 - ], - 414 => [ - "OnvarID" => 414, - "CityName" => "میبد", - "ProvinceID" => "93", - "InvarID" => 398 - ], - 415 => [ - "OnvarID" => 415, - "CityName" => "اردكان", - "ProvinceID" => "93", - "InvarID" => 22 - ], - 416 => [ - "OnvarID" => 416, - "CityName" => "ابركوه", - "ProvinceID" => "93", - "InvarID" => 16 - ], - 417 => [ - "OnvarID" => 417, - "CityName" => "بافق", - "ProvinceID" => "93", - "InvarID" => 58 - ], - 418 => [ - "OnvarID" => 418, - "CityName" => "مهریز", - "ProvinceID" => "93", - "InvarID" => 393 - ], - 419 => [ - "OnvarID" => 419, - "CityName" => "تفت", - "ProvinceID" => "93", - "InvarID" => 113 - ], - 420 => [ - "OnvarID" => 420, - "CityName" => "یزد", - "ProvinceID" => "93", - "InvarID" => 430 - ], - 421 => [ - "OnvarID" => 421, - "CityName" => "بهاباد", - "ProvinceID" => "93", - "InvarID" => 81 - ], - 422 => [ - "OnvarID" => 422, - "CityName" => "خاتم", - "ProvinceID" => "93", - "InvarID" => 143 - ], - 423 => [ - "OnvarID" => 423, - "CityName" => "ماهنشان", - "ProvinceID" => "67", - "InvarID" => 369 - ], - 424 => [ - "OnvarID" => 424, - "CityName" => "خدابنده", - "ProvinceID" => "67", - "InvarID" => 146 - ], - 425 => [ - "OnvarID" => 425, - "CityName" => "ابهر", - "ProvinceID" => "67", - "InvarID" => 17 - ], - 426 => [ - "OnvarID" => 426, - "CityName" => "ابهر", - "ProvinceID" => "67", - "InvarID" => 17 - ], - 427 => [ - "OnvarID" => 427, - "CityName" => "سلطانیه", - "ProvinceID" => "67", - "InvarID" => 240 - ], - 428 => [ - "OnvarID" => 428, - "CityName" => "ایجرود", - "ProvinceID" => "67", - "InvarID" => 47 - ], - 429 => [ - "OnvarID" => 429, - "CityName" => "زنجان", - "ProvinceID" => "67", - "InvarID" => 217 - ], - 430 => [ - "OnvarID" => 430, - "CityName" => "طارم", - "ProvinceID" => "67", - "InvarID" => 275 - ], - 431 => [ - "OnvarID" => 431, - "CityName" => "خرمدره", - "ProvinceID" => "67", - "InvarID" => 150 - ] - ]; - $affectedRows = 0; $cities = []; foreach ($xml as $value) { @@ -2742,7 +90,7 @@ class RoadObservationProblems extends Command $city = findCityFromGeoJson($value->YGeo, $value->XGeo); $cityModel = $city ? City::find($city['city_id']) : null; - $rop = RoadObserved::updateOrCreate( + $rop = RoadObserved::query()->updateOrCreate( ['fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage], [ 'fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage ?? null, @@ -2772,9 +120,12 @@ class RoadObservationProblems extends Command 'fk_FeatureType' => $value->fk_FeatureType ?? null, 'Description' => (strlen($value->Description) > 5) ? $value->Description : null, 'MobileForSendEventSms' => $mobile, - 'rms_province_id' => $rmsProvinceId[(int) $value->fk_Province] ?? null, - 'rms_city_id' => $rmsCityId[(int) $value->fk_Town]["InvarID"] ?? null, - 'observed_way_id' => self::get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, +// 'rms_province_id' => $rmsProvinceId[(int) $value->fk_Province] ?? null, +// 'rms_city_id' => $rmsCityId[(int) $value->fk_Town]["InvarID"] ?? null, +// 'observed_way_id' => self::get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, + 'rms_province_id' => NikarayanComplaints::mapProvinces((int) $value->fk_Province) ?? null, + 'rms_city_id' => NikarayanComplaints::mapCities((int) $value->fk_Town) ?? null, + 'observed_way_id' => $nominatimService->get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, 'province_id' => $city ? $city['province_id'] : null, 'city_id' => $city ? $city['city_id'] : null, @@ -2787,56 +138,14 @@ class RoadObservationProblems extends Command $affectedRows += 1; } } - } else { - /////log for error add all of things like successfull operation - $msg = 'rms: error in get data roadobserved babe!!!!' . "\n"; - // self::sms_sender('09398586633', $msg); - // self::sms_sender('09367487107', $msg); + } + else { $this->info('the received body is empty'); - return $result; + Log::channel('nikarayan')->error("the received body is empty" . date('Y-m-d H:i:s')); + return $result; } echo 'done at: ' . date("Y-m-d H:i:s") . "\n"; $this->info("{$affectedRows} row's affected"); return 0; } - public function sms_sender($mobile, $msg) - { - $client = new SoapClient("http://sms1000.ir/webservice/smspro.asmx?WSDL"); - $result = $client->doSendSMS( - array( - 'uUsername' => 'rmto', - 'uPassword' => 'Rahdari89', - 'uNumber' => '1000141', - 'uCellphones' => $mobile, - 'uMessage' => $msg, - 'uFarsi' => true, - 'uTopic' => false, - 'uFlash' => false - ) - ); - //print_r($result); - $x = $result->doSendSMSResult; - return $x; - } - - - public function get_way_id_from_nominatim($lat, $lng) - { - $url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=" . $lat . "&lon=" . $lng . "&zoom=16&addressdetails=16"; - $arrContextOptions = array( - "ssl" => array( - "verify_peer" => false, - "verify_peer_name" => false, - ) - ); - - $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); - $result = json_decode($result); - if (isset($result->osm_type)) { - if ($result->osm_type == 'way') { - return $result->osm_id; - } - } - return 0; - } -} \ No newline at end of file +} diff --git a/app/Enums/NikarayanComplaints.php b/app/Enums/NikarayanComplaints.php new file mode 100644 index 00000000..9d2d5feb --- /dev/null +++ b/app/Enums/NikarayanComplaints.php @@ -0,0 +1,2643 @@ + 1, + "57" => 2, + "91" => 3, + "21" => 4, + "18" => 5, + //"83" => 6, + "83" => 7, + "95" => 8, + "11" => 9, + "77" => 10, + "33" => 11, + "31" => 12, + "32" => 13, + "36" => 14, + "67" => 15, + //"26" => 16, + "87" => 17, + "61" => 18, + "41" => 19, + "15" => 20, + "14" => 21, + "73" => 22, + "45" => 23, + //"26" => 24, + "71" => 25, + "85" => 26, + "97" => 27, + "54" => 28, + //"26" => 29, + "81" => 30, + "16" => 31, + "51" => 32, + "64" => 33, + "75" => 34, + "93" => 35, + ]; + + return $nikarayanToRmsProvinceId[$province_id]; + } + + public static function mapCities(int $city_id): int + { + $nikarayanToRmsCityId = [ + 1 => [ + "OnvarID" => 1, + "CityName" => "گمیشان", + "ProvinceID" => "97", + "InvarID" => 353 + ], + 2 => [ + "OnvarID" => 2, + "CityName" => "آق قلا", + "ProvinceID" => "97", + "InvarID" => 13 + ], + 3 => [ + "OnvarID" => 3, + "CityName" => "رامیان", + "ProvinceID" => "97", + "InvarID" => 194 + ], + 4 => [ + "OnvarID" => 4, + "CityName" => "آزادشهر", + "ProvinceID" => "97", + "InvarID" => 8 + ], + 5 => [ + "OnvarID" => 5, + "CityName" => "مینو دشت", + "ProvinceID" => "97", + "InvarID" => 401 + ], + 6 => [ + "OnvarID" => 6, + "CityName" => "گالیكش", + "ProvinceID" => "97", + "InvarID" => 343 + ], + 7 => [ + "OnvarID" => 7, + "CityName" => "علی آباد", + "ProvinceID" => "97", + "InvarID" => 282 + ], + 8 => [ + "OnvarID" => 8, + "CityName" => "گرگان", + "ProvinceID" => "97", + "InvarID" => 347 + ], + 9 => [ + "OnvarID" => 9, + "CityName" => "كردكوی", + "ProvinceID" => "97", + "InvarID" => 324 + ], + 10 => [ + "OnvarID" => 10, + "CityName" => "بندرگز", + "ProvinceID" => "97", + "InvarID" => 80 + ], + 11 => [ + "OnvarID" => 11, + "CityName" => "تركمن", + "ProvinceID" => "97", + "InvarID" => 112 + ], + 12 => [ + "OnvarID" => 12, + "CityName" => "گنبدكاووس", + "ProvinceID" => "97", + "InvarID" => 356 + ], + 13 => [ + "OnvarID" => 13, + "CityName" => "كلاله", + "ProvinceID" => "97", + "InvarID" => 329 + ], + 14 => [ + "OnvarID" => 14, + "CityName" => "مراوه تپه", + "ProvinceID" => "97", + "InvarID" => 374 + ], + 15 => [ + "OnvarID" => 15, + "CityName" => "آستارا", + "ProvinceID" => "54", + "InvarID" => 9 + ], + 16 => [ + "OnvarID" => 16, + "CityName" => "طوالش", + "ProvinceID" => "54", + "InvarID" => 278 + ], + 17 => [ + "OnvarID" => 17, + "CityName" => "رضوانشهر", + "ProvinceID" => "54", + "InvarID" => 201 + ], + 18 => [ + "OnvarID" => 18, + "CityName" => "ماسال", + "ProvinceID" => "54", + "InvarID" => 366 + ], + 19 => [ + "OnvarID" => 19, + "CityName" => "بندر انزلی", + "ProvinceID" => "54", + "InvarID" => 76 + ], + 20 => [ + "OnvarID" => 20, + "CityName" => "صومعه سرا", + "ProvinceID" => "54", + "InvarID" => 274 + ], + 21 => [ + "OnvarID" => 21, + "CityName" => "فومن", + "ProvinceID" => "54", + "InvarID" => 300 + ], + 22 => [ + "OnvarID" => 22, + "CityName" => "شفت", + "ProvinceID" => "54", + "InvarID" => 260 + ], + 23 => [ + "OnvarID" => 23, + "CityName" => "املش", + "ProvinceID" => "54", + "InvarID" => 40 + ], + 24 => [ + "OnvarID" => 24, + "CityName" => "رودسر", + "ProvinceID" => "54", + "InvarID" => 207 + ], + 25 => [ + "OnvarID" => 25, + "CityName" => "آستانه اشرفیه", + "ProvinceID" => "54", + "InvarID" => 10 + ], + 26 => [ + "OnvarID" => 26, + "CityName" => "لاهیجان", + "ProvinceID" => "54", + "InvarID" => 361 + ], + 27 => [ + "OnvarID" => 27, + "CityName" => "رشت", + "ProvinceID" => "54", + "InvarID" => 199 + ], + 28 => [ + "OnvarID" => 28, + "CityName" => "سیاهكل", + "ProvinceID" => "54", + "InvarID" => 248 + ], + 29 => [ + "OnvarID" => 29, + "CityName" => "لنگرود", + "ProvinceID" => "54", + "InvarID" => 365 + ], + 30 => [ + "OnvarID" => 30, + "CityName" => "رودبار", + "ProvinceID" => "54", + "InvarID" => 205 + ], + 31 => [ + "OnvarID" => 31, + "CityName" => "آباده", + "ProvinceID" => "41", + "InvarID" => 2 + ], + 32 => [ + "OnvarID" => 32, + "CityName" => "ممسنی", + "ProvinceID" => "41", + "InvarID" => 385 + ], + 33 => [ + "OnvarID" => 33, + "CityName" => "سپیدان", + "ProvinceID" => "41", + "InvarID" => 225 + ], + 34 => [ + "OnvarID" => 34, + "CityName" => "رستم", + "ProvinceID" => "41", + "InvarID" => 198 + ], + 35 => [ + "OnvarID" => 35, + "CityName" => "پاسارگاد", + "ProvinceID" => "41", + "InvarID" => 99 + ], + 36 => [ + "OnvarID" => 36, + "CityName" => "بوانات", + "ProvinceID" => "41", + "InvarID" => 89 + ], + 37 => [ + "OnvarID" => 37, + "CityName" => "خرم بید", + "ProvinceID" => "41", + "InvarID" => 149 + ], + 38 => [ + "OnvarID" => 38, + "CityName" => "اقلید", + "ProvinceID" => "41", + "InvarID" => 37 + ], + 39 => [ + "OnvarID" => 39, + "CityName" => "كازرون", + "ProvinceID" => "41", + "InvarID" => 318 + ], + 40 => [ + "OnvarID" => 40, + "CityName" => "سروستان", + "ProvinceID" => "41", + "InvarID" => 237 + ], + 41 => [ + "OnvarID" => 41, + "CityName" => "كوار", + "ProvinceID" => "41", + "InvarID" => 337 + ], + 42 => [ + "OnvarID" => 42, + "CityName" => "خرامه", + "ProvinceID" => "41", + "InvarID" => 147 + ], + 43 => [ + "OnvarID" => 43, + "CityName" => "شیراز", + "ProvinceID" => "41", + "InvarID" => 270 + ], + 44 => [ + "OnvarID" => 44, + "CityName" => "مرودشت", + "ProvinceID" => "41", + "InvarID" => 376 + ], + 45 => [ + "OnvarID" => 45, + "CityName" => "ارسنجان", + "ProvinceID" => "41", + "InvarID" => 25 + ], + 46 => [ + "OnvarID" => 46, + "CityName" => "نی ریز", + "ProvinceID" => "41", + "InvarID" => 414 + ], + 47 => [ + "OnvarID" => 47, + "CityName" => "فراشبند", + "ProvinceID" => "41", + "InvarID" => 288 + ], + 48 => [ + "OnvarID" => 48, + "CityName" => "جهرم", + "ProvinceID" => "41", + "InvarID" => 127 + ], + 49 => [ + "OnvarID" => 49, + "CityName" => "قیر و كارزین", + "ProvinceID" => "41", + "InvarID" => 316 + ], + 50 => [ + "OnvarID" => 50, + "CityName" => "فیروز آباد", + "ProvinceID" => "41", + "InvarID" => 301 + ], + 51 => [ + "OnvarID" => 51, + "CityName" => "داراب", + "ProvinceID" => "41", + "InvarID" => 165 + ], + 52 => [ + "OnvarID" => 52, + "CityName" => "زرین دشت", + "ProvinceID" => "41", + "InvarID" => 216 + ], + 53 => [ + "OnvarID" => 53, + "CityName" => "مهر", + "ProvinceID" => "41", + "InvarID" => 3 + ], + 54 => [ + "OnvarID" => 54, + "CityName" => "خنج", + "ProvinceID" => "41", + "InvarID" => 390 + ], + 55 => [ + "OnvarID" => 55, + "CityName" => "لامرد", + "ProvinceID" => "41", + "InvarID" => 360 + ], + 56 => [ + "OnvarID" => 56, + "CityName" => "گراش", + "ProvinceID" => "41", + "InvarID" => 346 + ], + 57 => [ + "OnvarID" => 57, + "CityName" => "لارستان", + "ProvinceID" => "41", + "InvarID" => 358 + ], + 58 => [ + "OnvarID" => 58, + "CityName" => "فسا", + "ProvinceID" => "41", + "InvarID" => 296 + ], + 59 => [ + "OnvarID" => 59, + "CityName" => "استهبان", + "ProvinceID" => "41", + "InvarID" => 28 + ], + 60 => [ + "OnvarID" => 60, + "CityName" => "آران و بیدگل", + "ProvinceID" => "21", + "InvarID" => 7 + ], + 61 => [ + "OnvarID" => 61, + "CityName" => "بوئین و میان دشت", + "ProvinceID" => "21", + "InvarID" => 88 + ], + 62 => [ + "OnvarID" => 62, + "CityName" => "خوانسار", + "ProvinceID" => "21", + "InvarID" => 160 + ], + 63 => [ + "OnvarID" => 63, + "CityName" => "گلپایگان", + "ProvinceID" => "21", + "InvarID" => 351 + ], + 64 => [ + "OnvarID" => 64, + "CityName" => "اردستان", + "ProvinceID" => "21", + "InvarID" => 21 + ], + 65 => [ + "OnvarID" => 65, + "CityName" => "كاشان", + "ProvinceID" => "21", + "InvarID" => 319 + ], + 66 => [ + "OnvarID" => 66, + "CityName" => "خور و بیابانك", + "ProvinceID" => "21", + "InvarID" => 161 + ], + 67 => [ + "OnvarID" => 67, + "CityName" => "چادگان", + "ProvinceID" => "21", + "InvarID" => 133 + ], + 68 => [ + "OnvarID" => 68, + "CityName" => "فریدن", + "ProvinceID" => "21", + "InvarID" => 292 + ], + 69 => [ + "OnvarID" => 69, + "CityName" => "فریدون شهر", + "ProvinceID" => "21", + "InvarID" => 293 + ], + 70 => [ + "OnvarID" => 70, + "CityName" => "شهرضا", + "ProvinceID" => "21", + "InvarID" => 263 + ], + 71 => [ + "OnvarID" => 71, + "CityName" => "مباركه", + "ProvinceID" => "21", + "InvarID" => 370 + ], + 72 => [ + "OnvarID" => 72, + "CityName" => "لنجان", + "ProvinceID" => "21", + "InvarID" => 363 + ], + 73 => [ + "OnvarID" => 73, + "CityName" => "اصفهان", + "ProvinceID" => "21", + "InvarID" => 36 + ], + 74 => [ + "OnvarID" => 74, + "CityName" => "فلاورجان", + "ProvinceID" => "21", + "InvarID" => 297 + ], + 75 => [ + "OnvarID" => 75, + "CityName" => "نجف آباد", + "ProvinceID" => "21", + "InvarID" => 403 + ], + 76 => [ + "OnvarID" => 76, + "CityName" => "خمینی شهر", + "ProvinceID" => "21", + "InvarID" => 156 + ], + 77 => [ + "OnvarID" => 77, + "CityName" => "تیران و كرون", + "ProvinceID" => "21", + "InvarID" => 120 + ], + 78 => [ + "OnvarID" => 78, + "CityName" => "برخوار", + "ProvinceID" => "21", + "InvarID" => 64 + ], + 79 => [ + "OnvarID" => 79, + "CityName" => "نائین", + "ProvinceID" => "21", + "InvarID" => 402 + ], + 80 => [ + "OnvarID" => 80, + "CityName" => "سمیرم", + "ProvinceID" => "21", + "InvarID" => 243 + ], + 81 => [ + "OnvarID" => 81, + "CityName" => "دهاقان", + "ProvinceID" => "21", + "InvarID" => 181 + ], + 82 => [ + "OnvarID" => 82, + "CityName" => "نطنز", + "ProvinceID" => "21", + "InvarID" => 405 + ], + 83 => [ + "OnvarID" => 83, + "CityName" => "شاهین شهر و میمه", + "ProvinceID" => "21", + "InvarID" => 258 + ], + 84 => [ + "OnvarID" => 84, + "CityName" => "مراغه", + "ProvinceID" => "26", + "InvarID" => 373 + ], + 85 => [ + "OnvarID" => 85, + "CityName" => "خدا آفرین", + "ProvinceID" => "26", + "InvarID" => 145 + ], + 86 => [ + "OnvarID" => 86, + "CityName" => "جلفا", + "ProvinceID" => "26", + "InvarID" => 125 + ], + 87 => [ + "OnvarID" => 87, + "CityName" => "شبستر", + "ProvinceID" => "26", + "InvarID" => 259 + ], + 88 => [ + "OnvarID" => 88, + "CityName" => "مرند", + "ProvinceID" => "26", + "InvarID" => 375 + ], + 89 => [ + "OnvarID" => 89, + "CityName" => "تبریز", + "ProvinceID" => "26", + "InvarID" => 109 + ], + 90 => [ + "OnvarID" => 90, + "CityName" => "ورزقان", + "ProvinceID" => "26", + "InvarID" => 429 + ], + 91 => [ + "OnvarID" => 91, + "CityName" => "اهر", + "ProvinceID" => "26", + "InvarID" => 45 + ], + 92 => [ + "OnvarID" => 92, + "CityName" => "كلیبر", + "ProvinceID" => "26", + "InvarID" => 330 + ], + 93 => [ + "OnvarID" => 93, + "CityName" => "اسكو", + "ProvinceID" => "26", + "InvarID" => 31 + ], + 94 => [ + "OnvarID" => 94, + "CityName" => "آذرشهر", + "ProvinceID" => "26", + "InvarID" => 5 + ], + 95 => [ + "OnvarID" => 95, + "CityName" => "عجب شیر", + "ProvinceID" => "26", + "InvarID" => 280 + ], + 96 => [ + "OnvarID" => 96, + "CityName" => "بناب", + "ProvinceID" => "26", + "InvarID" => 75 + ], + 97 => [ + "OnvarID" => 97, + "CityName" => "ملكان", + "ProvinceID" => "26", + "InvarID" => 383 + ], + 98 => [ + "OnvarID" => 98, + "CityName" => "بستان آباد", + "ProvinceID" => "26", + "InvarID" => 69 + ], + 99 => [ + "OnvarID" => 99, + "CityName" => "سراب", + "ProvinceID" => "26", + "InvarID" => 226 + ], + 100 => [ + "OnvarID" => 100, + "CityName" => "هشترود", + "ProvinceID" => "26", + "InvarID" => 422 + ], + 101 => [ + "OnvarID" => 101, + "CityName" => "میانه", + "ProvinceID" => "26", + "InvarID" => 397 + ], + 102 => [ + "OnvarID" => 102, + "CityName" => "چاراویماق", + "ProvinceID" => "26", + "InvarID" => 134 + ], + 103 => [ + "OnvarID" => 103, + "CityName" => "هریس", + "ProvinceID" => "26", + "InvarID" => 421 + ], + 104 => [ + "OnvarID" => 104, + "CityName" => "هوراند", + "ProvinceID" => "26", + "InvarID" => 109 + ], + 105 => [ + "OnvarID" => 105, + "CityName" => "كیار", + "ProvinceID" => "77", + "InvarID" => 342 + ], + 106 => [ + "OnvarID" => 106, + "CityName" => "فارسان", + "ProvinceID" => "77", + "InvarID" => 284 + ], + 107 => [ + "OnvarID" => 107, + "CityName" => "كوهرنگ", + "ProvinceID" => "77", + "InvarID" => 341 + ], + 108 => [ + "OnvarID" => 108, + "CityName" => "لردگان", + "ProvinceID" => "77", + "InvarID" => 362 + ], + 109 => [ + "OnvarID" => 109, + "CityName" => "اردل", + "ProvinceID" => "77", + "InvarID" => 23 + ], + 110 => [ + "OnvarID" => 110, + "CityName" => "بروجن", + "ProvinceID" => "77", + "InvarID" => 68 + ], + 111 => [ + "OnvarID" => 111, + "CityName" => "سامان", + "ProvinceID" => "77", + "InvarID" => 221 + ], + 112 => [ + "OnvarID" => 112, + "CityName" => "بن", + "ProvinceID" => "77", + "InvarID" => 74 + ], + 113 => [ + "OnvarID" => 113, + "CityName" => "شهركرد", + "ProvinceID" => "77", + "InvarID" => 264 + ], + 114 => [ + "OnvarID" => 114, + "CityName" => "دیلم", + "ProvinceID" => "95", + "InvarID" => 187 + ], + 115 => [ + "OnvarID" => 115, + "CityName" => "گناوه", + "ProvinceID" => "95", + "InvarID" => 395 + ], + 116 => [ + "OnvarID" => 116, + "CityName" => "دشتستان", + "ProvinceID" => "95", + "InvarID" => 174 + ], + 117 => [ + "OnvarID" => 117, + "CityName" => "دشتی", + "ProvinceID" => "95", + "InvarID" => 175 + ], + 118 => [ + "OnvarID" => 118, + "CityName" => "بوشهر", + "ProvinceID" => "95", + "InvarID" => 90 + ], + 119 => [ + "OnvarID" => 119, + "CityName" => "تنگستان", + "ProvinceID" => "95", + "InvarID" => 117 + ], + 120 => [ + "OnvarID" => 120, + "CityName" => "دیر", + "ProvinceID" => "95", + "InvarID" => 186 + ], + 121 => [ + "OnvarID" => 121, + "CityName" => "جم", + "ProvinceID" => "95", + "InvarID" => 126 + ], + 122 => [ + "OnvarID" => 122, + "CityName" => "كنگان", + "ProvinceID" => "95", + "InvarID" => 333 + ], + 123 => [ + "OnvarID" => 123, + "CityName" => "عسلویه", + "ProvinceID" => "95", + "InvarID" => 281 + ], + 124 => [ + "OnvarID" => 124, + "CityName" => "مهران", + "ProvinceID" => "83", + "InvarID" => 391 + ], + 125 => [ + "OnvarID" => 125, + "CityName" => "ایلام", + "ProvinceID" => "83", + "InvarID" => 50 + ], + 126 => [ + "OnvarID" => 126, + "CityName" => "ایوان", + "ProvinceID" => "83", + "InvarID" => 51 + ], + 127 => [ + "OnvarID" => 127, + "CityName" => "دره شهر", + "ProvinceID" => "83", + "InvarID" => 171 + ], + 128 => [ + "OnvarID" => 128, + "CityName" => "ملكشاهی", + "ProvinceID" => "83", + "InvarID" => 384 + ], + 129 => [ + "OnvarID" => 129, + "CityName" => "سیروان", + "ProvinceID" => "83", + "InvarID" => 251 + ], + 130 => [ + "OnvarID" => 130, + "CityName" => "بدره", + "ProvinceID" => "83", + "InvarID" => 63 + ], + 131 => [ + "OnvarID" => 131, + "CityName" => "چرداول", + "ProvinceID" => "71", + "InvarID" => 139 + ], + 132 => [ + "OnvarID" => 132, + "CityName" => "دهلران", + "ProvinceID" => "83", + "InvarID" => 183 + ], + 133 => [ + "OnvarID" => 133, + "CityName" => "آبدانان", + "ProvinceID" => "83", + "InvarID" => 3 + ], + 134 => [ + "OnvarID" => 134, + "CityName" => "راور", + "ProvinceID" => "45", + "InvarID" => 195 + ], + 135 => [ + "OnvarID" => 135, + "CityName" => "كوهبنان", + "ProvinceID" => "45", + "InvarID" => 339 + ], + 136 => [ + "OnvarID" => 136, + "CityName" => "شهر بابك", + "ProvinceID" => "45", + "InvarID" => 262 + ], + 137 => [ + "OnvarID" => 137, + "CityName" => "انار", + "ProvinceID" => "45", + "InvarID" => 42 + ], + 138 => [ + "OnvarID" => 138, + "CityName" => "رفسنجان", + "ProvinceID" => "45", + "InvarID" => 202 + ], + 139 => [ + "OnvarID" => 139, + "CityName" => "زرند", + "ProvinceID" => "45", + "InvarID" => 214 + ], + 140 => [ + "OnvarID" => 140, + "CityName" => "كرمان", + "ProvinceID" => "45", + "InvarID" => 325 + ], + 141 => [ + "OnvarID" => 141, + "CityName" => "رابر", + "ProvinceID" => "45", + "InvarID" => 189 + ], + 142 => [ + "OnvarID" => 142, + "CityName" => "بافت", + "ProvinceID" => "45", + "InvarID" => 57 + ], + 143 => [ + "OnvarID" => 143, + "CityName" => "سیرجان", + "ProvinceID" => "45", + "InvarID" => 250 + ], + 144 => [ + "OnvarID" => 144, + "CityName" => "بردسیر", + "ProvinceID" => "45", + "InvarID" => 66 + ], + 145 => [ + "OnvarID" => 145, + "CityName" => "ارزوئیه", + "ProvinceID" => "45", + "InvarID" => 24 + ], + 146 => [ + "OnvarID" => 146, + "CityName" => "ریگان", + "ProvinceID" => "45", + "InvarID" => 210 + ], + 147 => [ + "OnvarID" => 147, + "CityName" => "فهرج", + "ProvinceID" => "45", + "InvarID" => 299 + ], + 148 => [ + "OnvarID" => 148, + "CityName" => "نرماشیر", + "ProvinceID" => "45", + "InvarID" => 404 + ], + 149 => [ + "OnvarID" => 149, + "CityName" => "منوجان", + "ProvinceID" => "45", + "InvarID" => 386 + ], + 150 => [ + "OnvarID" => 150, + "CityName" => "قلعه گنج", + "ProvinceID" => "45", + "InvarID" => 313 + ], + 151 => [ + "OnvarID" => 151, + "CityName" => "كهنوج", + "ProvinceID" => "45", + "InvarID" => 336 + ], + 152 => [ + "OnvarID" => 152, + "CityName" => "فاریاب", + "ProvinceID" => "45", + "InvarID" => 286 + ], + 153 => [ + "OnvarID" => 153, + "CityName" => "رودبار جنوب", + "ProvinceID" => "45", + "InvarID" => 205 + ], + 154 => [ + "OnvarID" => 154, + "CityName" => "عنبرآباد", + "ProvinceID" => "45", + "InvarID" => 283 + ], + 155 => [ + "OnvarID" => 155, + "CityName" => "جیرفت", + "ProvinceID" => "45", + "InvarID" => 131 + ], + 156 => [ + "OnvarID" => 156, + "CityName" => "بم", + "ProvinceID" => "45", + "InvarID" => 73 + ], + 157 => [ + "OnvarID" => 157, + "CityName" => "گیلانغرب", + "ProvinceID" => "71", + "InvarID" => 357 + ], + 158 => [ + "OnvarID" => 158, + "CityName" => "دالاهو", + "ProvinceID" => "71", + "InvarID" => 166 + ], + 159 => [ + "OnvarID" => 159, + "CityName" => "قصر شیرین", + "ProvinceID" => "71", + "InvarID" => 311 + ], + 160 => [ + "OnvarID" => 160, + "CityName" => "سر پل ذهاب", + "ProvinceID" => "71", + "InvarID" => 231 + ], + 161 => [ + "OnvarID" => 161, + "CityName" => "ثلاث باباجانی", + "ProvinceID" => "71", + "InvarID" => 121 + ], + 162 => [ + "OnvarID" => 162, + "CityName" => "جوانرود", + "ProvinceID" => "71", + "InvarID" => 128 + ], + 163 => [ + "OnvarID" => 163, + "CityName" => "اسلام آباد غرب", + "ProvinceID" => "71", + "InvarID" => 32 + ], + 164 => [ + "OnvarID" => 164, + "CityName" => "هرسین", + "ProvinceID" => "71", + "InvarID" => 420 + ], + 165 => [ + "OnvarID" => 165, + "CityName" => "كنگاور", + "ProvinceID" => "71", + "InvarID" => 334 + ], + 166 => [ + "OnvarID" => 166, + "CityName" => "روانسر", + "ProvinceID" => "71", + "InvarID" => 203 + ], + 167 => [ + "OnvarID" => 167, + "CityName" => "سنقر", + "ProvinceID" => "71", + "InvarID" => 244 + ], + 168 => [ + "OnvarID" => 168, + "CityName" => "صحنه", + "ProvinceID" => "71", + "InvarID" => 272 + ], + 169 => [ + "OnvarID" => 169, + "CityName" => "پاوه", + "ProvinceID" => "71", + "InvarID" => 101 + ], + 170 => [ + "OnvarID" => 170, + "CityName" => "كرمانشاه", + "ProvinceID" => "71", + "InvarID" => 326 + ], + 171 => [ + "OnvarID" => 171, + "CityName" => "قوچان", + "ProvinceID" => "31", + "InvarID" => 315 + ], + 172 => [ + "OnvarID" => 172, + "CityName" => "درگز", + "ProvinceID" => "31", + "InvarID" => 169 + ], + 173 => [ + "OnvarID" => 173, + "CityName" => "داورزن", + "ProvinceID" => "31", + "InvarID" => 168 + ], + 174 => [ + "OnvarID" => 174, + "CityName" => "سبزوار", + "ProvinceID" => "31", + "InvarID" => 224 + ], + 175 => [ + "OnvarID" => 175, + "CityName" => "خوشاب", + "ProvinceID" => "31", + "InvarID" => 163 + ], + 176 => [ + "OnvarID" => 176, + "CityName" => "جغتای", + "ProvinceID" => "31", + "InvarID" => 124 + ], + 177 => [ + "OnvarID" => 177, + "CityName" => "جوین", + "ProvinceID" => "31", + "InvarID" => 130 + ], + 178 => [ + "OnvarID" => 178, + "CityName" => "مشهد", + "ProvinceID" => "31", + "InvarID" => 380 + ], + 179 => [ + "OnvarID" => 179, + "CityName" => "بینالود", + "ProvinceID" => "31", + "InvarID" => 96 + ], + 180 => [ + "OnvarID" => 180, + "CityName" => "نیشابور", + "ProvinceID" => "31", + "InvarID" => 416 + ], + 181 => [ + "OnvarID" => 181, + "CityName" => "فیروزه", + "ProvinceID" => "31", + "InvarID" => 303 + ], + 182 => [ + "OnvarID" => 182, + "CityName" => "چناران", + "ProvinceID" => "31", + "InvarID" => 140 + ], + 183 => [ + "OnvarID" => 183, + "CityName" => "كلات", + "ProvinceID" => "31", + "InvarID" => 327 + ], + 184 => [ + "OnvarID" => 184, + "CityName" => "سرخس", + "ProvinceID" => "31", + "InvarID" => 232 + ], + 185 => [ + "OnvarID" => 185, + "CityName" => "كاشمر", + "ProvinceID" => "31", + "InvarID" => 320 + ], + 186 => [ + "OnvarID" => 186, + "CityName" => "خلیل آباد", + "ProvinceID" => "31", + "InvarID" => 153 + ], + 187 => [ + "OnvarID" => 187, + "CityName" => "مه ولایت", + "ProvinceID" => "31", + "InvarID" => 387 + ], + 188 => [ + "OnvarID" => 188, + "CityName" => "تربت حیدریه", + "ProvinceID" => "31", + "InvarID" => 111 + ], + 189 => [ + "OnvarID" => 189, + "CityName" => "زاوه", + "ProvinceID" => "31", + "InvarID" => 213 + ], + 190 => [ + "OnvarID" => 190, + "CityName" => "فریمان", + "ProvinceID" => "31", + "InvarID" => 295 + ], + 191 => [ + "OnvarID" => 191, + "CityName" => "تربت جام", + "ProvinceID" => "31", + "InvarID" => 110 + ], + 192 => [ + "OnvarID" => 192, + "CityName" => "بردسكن", + "ProvinceID" => "31", + "InvarID" => 65 + ], + 193 => [ + "OnvarID" => 193, + "CityName" => "بجستان", + "ProvinceID" => "31", + "InvarID" => 61 + ], + 194 => [ + "OnvarID" => 194, + "CityName" => "گناباد", + "ProvinceID" => "31", + "InvarID" => 354 + ], + 195 => [ + "OnvarID" => 195, + "CityName" => "رشتخوار", + "ProvinceID" => "31", + "InvarID" => 200 + ], + 196 => [ + "OnvarID" => 196, + "CityName" => "خواف", + "ProvinceID" => "31", + "InvarID" => 159 + ], + 197 => [ + "OnvarID" => 197, + "CityName" => "تایباد", + "ProvinceID" => "31", + "InvarID" => 108 + ], + 198 => [ + "OnvarID" => 198, + "CityName" => "باخرز", + "ProvinceID" => "31", + "InvarID" => 54 + ], + 199 => [ + "OnvarID" => 199, + "CityName" => "فردوس", + "ProvinceID" => "33", + "InvarID" => 290 + ], + 200 => [ + "OnvarID" => 200, + "CityName" => "طبس", + "ProvinceID" => "33", + "InvarID" => 277 + ], + 201 => [ + "OnvarID" => 201, + "CityName" => "بشرویه", + "ProvinceID" => "33", + "InvarID" => 72 + ], + 202 => [ + "OnvarID" => 202, + "CityName" => "سرایان", + "ProvinceID" => "33", + "InvarID" => 228 + ], + 203 => [ + "OnvarID" => 203, + "CityName" => "قائنات", + "ProvinceID" => "33", + "InvarID" => 305 + ], + 204 => [ + "OnvarID" => 204, + "CityName" => "زیركوه", + "ProvinceID" => "33", + "InvarID" => 219 + ], + 205 => [ + "OnvarID" => 205, + "CityName" => "سربیشه", + "ProvinceID" => "33", + "InvarID" => 230 + ], + 206 => [ + "OnvarID" => 206, + "CityName" => "خوسف", + "ProvinceID" => "33", + "InvarID" => 162 + ], + 207 => [ + "OnvarID" => 207, + "CityName" => "بیرجند", + "ProvinceID" => "33", + "InvarID" => 94 + ], + 208 => [ + "OnvarID" => 208, + "CityName" => "درمیان", + "ProvinceID" => "33", + "InvarID" => 170 + ], + 209 => [ + "OnvarID" => 209, + "CityName" => "نهبندان", + "ProvinceID" => "33", + "InvarID" => 411 + ], + 210 => [ + "OnvarID" => 210, + "CityName" => "شوشتر", + "ProvinceID" => "36", + "InvarID" => 268 + ], + 211 => [ + "OnvarID" => 211, + "CityName" => "اندیكا", + "ProvinceID" => "36", + "InvarID" => 43 + ], + 212 => [ + "OnvarID" => 212, + "CityName" => "لالی", + "ProvinceID" => "36", + "InvarID" => 359 + ], + 213 => [ + "OnvarID" => 213, + "CityName" => "گتوند", + "ProvinceID" => "36", + "InvarID" => 344 + ], + 214 => [ + "OnvarID" => 214, + "CityName" => "شوش", + "ProvinceID" => "36", + "InvarID" => 267 + ], + 215 => [ + "OnvarID" => 215, + "CityName" => "اندیمشك", + "ProvinceID" => "36", + "InvarID" => 44 + ], + 216 => [ + "OnvarID" => 216, + "CityName" => "دزفول", + "ProvinceID" => "36", + "InvarID" => 172 + ], + 217 => [ + "OnvarID" => 217, + "CityName" => "كارون", + "ProvinceID" => "36", + "InvarID" => 317 + ], + 218 => [ + "OnvarID" => 218, + "CityName" => "هویزه", + "ProvinceID" => "36", + "InvarID" => 426 + ], + 219 => [ + "OnvarID" => 219, + "CityName" => "حمیدیه", + "ProvinceID" => "36", + "InvarID" => 142 + ], + 220 => [ + "OnvarID" => 220, + "CityName" => "باوی", + "ProvinceID" => "36", + "InvarID" => 60 + ], + 221 => [ + "OnvarID" => 221, + "CityName" => "دشت آزادگان", + "ProvinceID" => "36", + "InvarID" => 173 + ], + 222 => [ + "OnvarID" => 222, + "CityName" => "مسجد سلیمان", + "ProvinceID" => "36", + "InvarID" => 378 + ], + 223 => [ + "OnvarID" => 223, + "CityName" => "هفتگل", + "ProvinceID" => "36", + "InvarID" => 423 + ], + 224 => [ + "OnvarID" => 224, + "CityName" => "رامهرمز", + "ProvinceID" => "36", + "InvarID" => 193 + ], + 225 => [ + "OnvarID" => 225, + "CityName" => "باغ ملك", + "ProvinceID" => "36", + "InvarID" => 56 + ], + 226 => [ + "OnvarID" => 226, + "CityName" => "ایذه", + "ProvinceID" => "36", + "InvarID" => 48 + ], + 227 => [ + "OnvarID" => 227, + "CityName" => "شادگان", + "ProvinceID" => "36", + "InvarID" => 254 + ], + 228 => [ + "OnvarID" => 228, + "CityName" => "رامشیر", + "ProvinceID" => "36", + "InvarID" => 192 + ], + 229 => [ + "OnvarID" => 229, + "CityName" => "هندیجان", + "ProvinceID" => "36", + "InvarID" => 425 + ], + 230 => [ + "OnvarID" => 230, + "CityName" => "بهبهان", + "ProvinceID" => "36", + "InvarID" => 84 + ], + 231 => [ + "OnvarID" => 231, + "CityName" => "آغاجاری", + "ProvinceID" => "36", + "InvarID" => 12 + ], + 232 => [ + "OnvarID" => 232, + "CityName" => "امیدیه", + "ProvinceID" => "36", + "InvarID" => 41 + ], + 233 => [ + "OnvarID" => 233, + "CityName" => "آبادان", + "ProvinceID" => "36", + "InvarID" => 1 + ], + 234 => [ + "OnvarID" => 234, + "CityName" => "خرمشهر", + "ProvinceID" => "36", + "InvarID" => 151 + ], + 235 => [ + "OnvarID" => 235, + "CityName" => "اهواز", + "ProvinceID" => "36", + "InvarID" => 46 + ], + 236 => [ + "OnvarID" => 236, + "CityName" => "بندر ماهشهر", + "ProvinceID" => "36", + "InvarID" => 78 + ], + 237 => [ + "OnvarID" => 237, + "CityName" => "گچساران", + "ProvinceID" => "85", + "InvarID" => 345 + ], + 238 => [ + "OnvarID" => 238, + "CityName" => "بهمئی", + "ProvinceID" => "85", + "InvarID" => 86 + ], + 239 => [ + "OnvarID" => 239, + "CityName" => "كهگیلویه", + "ProvinceID" => "85", + "InvarID" => 335 + ], + 240 => [ + "OnvarID" => 240, + "CityName" => "چرام", + "ProvinceID" => "85", + "InvarID" => 138 + ], + 241 => [ + "OnvarID" => 241, + "CityName" => "لنده", + "ProvinceID" => "85", + "InvarID" => 364 + ], + 242 => [ + "OnvarID" => 242, + "CityName" => "باشت", + "ProvinceID" => "85", + "InvarID" => 55 + ], + 243 => [ + "OnvarID" => 243, + "CityName" => "بویراحمد", + "ProvinceID" => "85", + "InvarID" => 92 + ], + 244 => [ + "OnvarID" => 244, + "CityName" => "دنا", + "ProvinceID" => "85", + "InvarID" => 180 + ], + 245 => [ + "OnvarID" => 245, + "CityName" => "پارس آباد", + "ProvinceID" => "91", + "InvarID" => 97 + ], + 246 => [ + "OnvarID" => 246, + "CityName" => "گرمی", + "ProvinceID" => "91", + "InvarID" => 350 + ], + 247 => [ + "OnvarID" => 247, + "CityName" => "بیله سوار", + "ProvinceID" => "91", + "InvarID" => 95 + ], + 248 => [ + "OnvarID" => 248, + "CityName" => "مشگین شهر", + "ProvinceID" => "91", + "InvarID" => 379 + ], + 249 => [ + "OnvarID" => 249, + "CityName" => "نیر", + "ProvinceID" => "91", + "InvarID" => 415 + ], + 250 => [ + "OnvarID" => 250, + "CityName" => "نمین", + "ProvinceID" => "91", + "InvarID" => 409 + ], + 251 => [ + "OnvarID" => 251, + "CityName" => "اردبیل", + "ProvinceID" => "91", + "InvarID" => 20 + ], + 252 => [ + "OnvarID" => 252, + "CityName" => "سرعین", + "ProvinceID" => "91", + "InvarID" => 235 + ], + 253 => [ + "OnvarID" => 253, + "CityName" => "كوثر", + "ProvinceID" => "91", + "InvarID" => 338 + ], + 254 => [ + "OnvarID" => 254, + "CityName" => "خلخال", + "ProvinceID" => "91", + "InvarID" => 152 + ], + 255 => [ + "OnvarID" => 255, + "CityName" => "حاجی آباد", + "ProvinceID" => "64", + "InvarID" => 141 + ], + 256 => [ + "OnvarID" => 256, + "CityName" => "پارسیان", + "ProvinceID" => "64", + "InvarID" => 98 + ], + 257 => [ + "OnvarID" => 257, + "CityName" => "بستك", + "ProvinceID" => "64", + "InvarID" => 70 + ], + 258 => [ + "OnvarID" => 258, + "CityName" => "بندر عباس", + "ProvinceID" => "64", + "InvarID" => 79 + ], + 259 => [ + "OnvarID" => 259, + "CityName" => "میناب", + "ProvinceID" => "64", + "InvarID" => 400 + ], + 260 => [ + "OnvarID" => 260, + "CityName" => "رودان", + "ProvinceID" => "64", + "InvarID" => 204 + ], + 261 => [ + "OnvarID" => 261, + "CityName" => "بندر لنگه", + "ProvinceID" => "64", + "InvarID" => 77 + ], + 262 => [ + "OnvarID" => 262, + "CityName" => "خمیر", + "ProvinceID" => "64", + "InvarID" => 154 + ], + 263 => [ + "OnvarID" => 263, + "CityName" => "بشاگرد", + "ProvinceID" => "64", + "InvarID" => 71 + ], + 264 => [ + "OnvarID" => 264, + "CityName" => "سیریك", + "ProvinceID" => "64", + "InvarID" => 252 + ], + 265 => [ + "OnvarID" => 265, + "CityName" => "جاسك", + "ProvinceID" => "64", + "InvarID" => 123 + ], + 266 => [ + "OnvarID" => 266, + "CityName" => "ابوموسی", + "ProvinceID" => "NULL", + "InvarID" => 18 + ], + 267 => [ + "OnvarID" => 267, + "CityName" => "قشم", + "ProvinceID" => "64", + "InvarID" => 310 + ], + 268 => [ + "OnvarID" => 268, + "CityName" => "طالقان", + "ProvinceID" => "18", + "InvarID" => 276 + ], + 269 => [ + "OnvarID" => 269, + "CityName" => "اشتهارد", + "ProvinceID" => "18", + "InvarID" => 34 + ], + 270 => [ + "OnvarID" => 270, + "CityName" => "كرج", + "ProvinceID" => "18", + "InvarID" => 323 + ], + 271 => [ + "OnvarID" => 271, + "CityName" => "فردیس", + "ProvinceID" => "18", + "InvarID" => 291 + ], + 272 => [ + "OnvarID" => 272, + "CityName" => "ساوجبلاغ", + "ProvinceID" => "18", + "InvarID" => 222 + ], + 273 => [ + "OnvarID" => 273, + "CityName" => "نظر آباد", + "ProvinceID" => "18", + "InvarID" => 406 + ], + 274 => [ + "OnvarID" => 274, + "CityName" => "فامنین", + "ProvinceID" => "75", + "InvarID" => 287 + ], + 275 => [ + "OnvarID" => 275, + "CityName" => "كبودرآهنگ", + "ProvinceID" => "75", + "InvarID" => 322 + ], + 276 => [ + "OnvarID" => 276, + "CityName" => "رزن", + "ProvinceID" => "75", + "InvarID" => 197 + ], + 277 => [ + "OnvarID" => 277, + "CityName" => "ملایر", + "ProvinceID" => "75", + "InvarID" => 382 + ], + 278 => [ + "OnvarID" => 278, + "CityName" => "نهاوند", + "ProvinceID" => "75", + "InvarID" => 410 + ], + 279 => [ + "OnvarID" => 279, + "CityName" => "تویسركان", + "ProvinceID" => "75", + "InvarID" => 119 + ], + 280 => [ + "OnvarID" => 280, + "CityName" => "اسد آباد", + "ProvinceID" => "75", + "InvarID" => 29 + ], + 281 => [ + "OnvarID" => 281, + "CityName" => "همدان", + "ProvinceID" => "75", + "InvarID" => 424 + ], + 282 => [ + "OnvarID" => 282, + "CityName" => "بهار", + "ProvinceID" => "75", + "InvarID" => 82 + ], + 283 => [ + "OnvarID" => 283, + "CityName" => "سقز", + "ProvinceID" => "73", + "InvarID" => 238 + ], + 284 => [ + "OnvarID" => 284, + "CityName" => "سرو آباد", + "ProvinceID" => "73", + "InvarID" => 236 + ], + 285 => [ + "OnvarID" => 285, + "CityName" => "مریوان", + "ProvinceID" => "73", + "InvarID" => 377 + ], + 286 => [ + "OnvarID" => 286, + "CityName" => "بانه", + "ProvinceID" => "73", + "InvarID" => 59 + ], + 287 => [ + "OnvarID" => 287, + "CityName" => "قروه", + "ProvinceID" => "73", + "InvarID" => 308 + ], + 288 => [ + "OnvarID" => 288, + "CityName" => "دهگلان", + "ProvinceID" => "73", + "InvarID" => 182 + ], + 289 => [ + "OnvarID" => 289, + "CityName" => "سنندج", + "ProvinceID" => "73", + "InvarID" => 245 + ], + 290 => [ + "OnvarID" => 290, + "CityName" => "بیجار", + "ProvinceID" => "73", + "InvarID" => 93 + ], + 291 => [ + "OnvarID" => 291, + "CityName" => "دیواندره", + "ProvinceID" => "73", + "InvarID" => 188 + ], + 292 => [ + "OnvarID" => 292, + "CityName" => "كامیاران", + "ProvinceID" => "73", + "InvarID" => 321 + ], + 293 => [ + "OnvarID" => 293, + "CityName" => "دلفان", + "ProvinceID" => "81", + "InvarID" => 176 + ], + 294 => [ + "OnvarID" => 294, + "CityName" => "پل دختر", + "ProvinceID" => "81", + "InvarID" => 103 + ], + 295 => [ + "OnvarID" => 295, + "CityName" => "رومشكان", + "ProvinceID" => "81", + "InvarID" => 208 + ], + 296 => [ + "OnvarID" => 296, + "CityName" => "كوه دشت", + "ProvinceID" => "81", + "InvarID" => 340 + ], + 297 => [ + "OnvarID" => 297, + "CityName" => "دوره", + "ProvinceID" => "81", + "InvarID" => 184 + ], + 298 => [ + "OnvarID" => 298, + "CityName" => "خرم آباد", + "ProvinceID" => "81", + "InvarID" => 148 + ], + 299 => [ + "OnvarID" => 299, + "CityName" => "دورود", + "ProvinceID" => "81", + "InvarID" => 185 + ], + 300 => [ + "OnvarID" => 300, + "CityName" => "ازنا", + "ProvinceID" => "81", + "InvarID" => 27 + ], + 301 => [ + "OnvarID" => 301, + "CityName" => "سلسله", + "ProvinceID" => "81", + "InvarID" => 239 + ], + 302 => [ + "OnvarID" => 302, + "CityName" => "بروجرد", + "ProvinceID" => "81", + "InvarID" => 67 + ], + 303 => [ + "OnvarID" => 303, + "CityName" => "الیگودرز", + "ProvinceID" => "81", + "InvarID" => 39 + ], + 304 => [ + "OnvarID" => 304, + "CityName" => "ساوه", + "ProvinceID" => "51", + "InvarID" => 223 + ], + 305 => [ + "OnvarID" => 305, + "CityName" => "زرندیه", + "ProvinceID" => "51", + "InvarID" => 215 + ], + 306 => [ + "OnvarID" => 306, + "CityName" => "خنداب", + "ProvinceID" => "51", + "InvarID" => 158 + ], + 307 => [ + "OnvarID" => 307, + "CityName" => "كمیجان", + "ProvinceID" => "51", + "InvarID" => 331 + ], + 308 => [ + "OnvarID" => 308, + "CityName" => "اراك", + "ProvinceID" => "51", + "InvarID" => 19 + ], + 309 => [ + "OnvarID" => 309, + "CityName" => "فراهان", + "ProvinceID" => "51", + "InvarID" => 289 + ], + 310 => [ + "OnvarID" => 310, + "CityName" => "آشتیان", + "ProvinceID" => "51", + "InvarID" => 11 + ], + 311 => [ + "OnvarID" => 311, + "CityName" => "تفرش", + "ProvinceID" => "51", + "InvarID" => 114 + ], + 312 => [ + "OnvarID" => 312, + "CityName" => "شازند", + "ProvinceID" => "51", + "InvarID" => 255 + ], + 313 => [ + "OnvarID" => 313, + "CityName" => "خمین", + "ProvinceID" => "51", + "InvarID" => 155 + ], + 314 => [ + "OnvarID" => 314, + "CityName" => "دلیجان", + "ProvinceID" => "51", + "InvarID" => 178 + ], + 315 => [ + "OnvarID" => 315, + "CityName" => "محلات", + "ProvinceID" => "51", + "InvarID" => 371 + ], + 316 => [ + "OnvarID" => 316, + "CityName" => "چالوس", + "ProvinceID" => "16", + "InvarID" => 136 + ], + 317 => [ + "OnvarID" => 317, + "CityName" => "عباس آباد", + "ProvinceID" => "16", + "InvarID" => 279 + ], + 318 => [ + "OnvarID" => 318, + "CityName" => "كلاردشت", + "ProvinceID" => "16", + "InvarID" => 328 + ], + 319 => [ + "OnvarID" => 319, + "CityName" => "تنكابن", + "ProvinceID" => "16", + "InvarID" => 116 + ], + 320 => [ + "OnvarID" => 320, + "CityName" => "رامسر", + "ProvinceID" => "16", + "InvarID" => 191 + ], + 321 => [ + "OnvarID" => 321, + "CityName" => "آمل", + "ProvinceID" => "16", + "InvarID" => 14 + ], + 322 => [ + "OnvarID" => 322, + "CityName" => "نور", + "ProvinceID" => "16", + "InvarID" => 412 + ], + 323 => [ + "OnvarID" => 323, + "CityName" => "نوشهر", + "ProvinceID" => "16", + "InvarID" => 413 + ], + 324 => [ + "OnvarID" => 324, + "CityName" => "محمودآباد", + "ProvinceID" => "16", + "InvarID" => 372 + ], + 325 => [ + "OnvarID" => 325, + "CityName" => "فریدونكنار", + "ProvinceID" => "16", + "InvarID" => 294 + ], + 326 => [ + "OnvarID" => 326, + "CityName" => "سوادكوه", + "ProvinceID" => "16", + "InvarID" => 246 + ], + 327 => [ + "OnvarID" => 327, + "CityName" => "سوادكوه شمالی", + "ProvinceID" => "16", + "InvarID" => 247 + ], + 328 => [ + "OnvarID" => 328, + "CityName" => "قائمشهر", + "ProvinceID" => "16", + "InvarID" => 304 + ], + 329 => [ + "OnvarID" => 329, + "CityName" => "میاندورود", + "ProvinceID" => "16", + "InvarID" => 395 + ], + 330 => [ + "OnvarID" => 330, + "CityName" => "ساری", + "ProvinceID" => "16", + "InvarID" => 220 + ], + 331 => [ + "OnvarID" => 331, + "CityName" => "بابل", + "ProvinceID" => "16", + "InvarID" => 52 + ], + 332 => [ + "OnvarID" => 332, + "CityName" => "سیمرغ", + "ProvinceID" => "16", + "InvarID" => 253 + ], + 333 => [ + "OnvarID" => 333, + "CityName" => "جویبار", + "ProvinceID" => "16", + "InvarID" => 129 + ], + 334 => [ + "OnvarID" => 334, + "CityName" => "نكا", + "ProvinceID" => "16", + "InvarID" => 408 + ], + 335 => [ + "OnvarID" => 335, + "CityName" => "گلوگاه", + "ProvinceID" => "16", + "InvarID" => 352 + ], + 336 => [ + "OnvarID" => 336, + "CityName" => "بهشهر", + "ProvinceID" => "16", + "InvarID" => 85 + ], + 337 => [ + "OnvarID" => 337, + "CityName" => "بابلسر", + "ProvinceID" => "16", + "InvarID" => 53 + ], + 338 => [ + "OnvarID" => 338, + "CityName" => "تاكستان", + "ProvinceID" => "15", + "InvarID" => 107 + ], + 339 => [ + "OnvarID" => 339, + "CityName" => "آبیك", + "ProvinceID" => "15", + "InvarID" => 4 + ], + 340 => [ + "OnvarID" => 340, + "CityName" => "البرز", + "ProvinceID" => "15", + "InvarID" => 38 + ], + 341 => [ + "OnvarID" => 341, + "CityName" => "قزوین", + "ProvinceID" => "15", + "InvarID" => 309 + ], + 342 => [ + "OnvarID" => 342, + "CityName" => "آوج", + "ProvinceID" => "15", + "InvarID" => 15 + ], + 343 => [ + "OnvarID" => 343, + "CityName" => "بوئین زهرا", + "ProvinceID" => "15", + "InvarID" => 87 + ], + 344 => [ + "OnvarID" => 344, + "CityName" => "قم", + "ProvinceID" => "14", + "InvarID" => 314 + ], + 345 => [ + "OnvarID" => 345, + "CityName" => "دامغان", + "ProvinceID" => "87", + "InvarID" => 167 + ], + 346 => [ + "OnvarID" => 346, + "CityName" => "شاهرود", + "ProvinceID" => "87", + "InvarID" => 256 + ], + 347 => [ + "OnvarID" => 347, + "CityName" => "میامی", + "ProvinceID" => "87", + "InvarID" => 394 + ], + 348 => [ + "OnvarID" => 348, + "CityName" => "سرخه", + "ProvinceID" => "87", + "InvarID" => 233 + ], + 349 => [ + "OnvarID" => 349, + "CityName" => "سمنان", + "ProvinceID" => "87", + "InvarID" => 242 + ], + 350 => [ + "OnvarID" => 350, + "CityName" => "مهدیشهر", + "ProvinceID" => "87", + "InvarID" => 389 + ], + 351 => [ + "OnvarID" => 351, + "CityName" => "آرادان", + "ProvinceID" => "87", + "InvarID" => 6 + ], + 352 => [ + "OnvarID" => 352, + "CityName" => "گرمسار", + "ProvinceID" => "87", + "InvarID" => 348 + ], + 353 => [ + "OnvarID" => 353, + "CityName" => "ممانه و سملقان", + "ProvinceID" => "32", + "InvarID" => 368 + ], + 354 => [ + "OnvarID" => 354, + "CityName" => "راز و جرگلان", + "ProvinceID" => "32", + "InvarID" => 190 + ], + 355 => [ + "OnvarID" => 355, + "CityName" => "اسفراین", + "ProvinceID" => "32", + "InvarID" => 30 + ], + 356 => [ + "OnvarID" => 356, + "CityName" => "فاروج", + "ProvinceID" => "32", + "InvarID" => 285 + ], + 357 => [ + "OnvarID" => 357, + "CityName" => "شیروان", + "ProvinceID" => "32", + "InvarID" => 271 + ], + 358 => [ + "OnvarID" => 358, + "CityName" => "بجنورد", + "ProvinceID" => "32", + "InvarID" => 62 + ], + 359 => [ + "OnvarID" => 359, + "CityName" => "جاجرم", + "ProvinceID" => "32", + "InvarID" => 122 + ], + 360 => [ + "OnvarID" => 360, + "CityName" => "گرمه", + "ProvinceID" => "32", + "InvarID" => 349 + ], + 361 => [ + "OnvarID" => 361, + "CityName" => "نیمروز", + "ProvinceID" => "61", + "InvarID" => 418 + ], + 362 => [ + "OnvarID" => 362, + "CityName" => "هیرمند", + "ProvinceID" => "61", + "InvarID" => 427 + ], + 363 => [ + "OnvarID" => 363, + "CityName" => "هامون", + "ProvinceID" => "61", + "InvarID" => 419 + ], + 364 => [ + "OnvarID" => 364, + "CityName" => "زابل", + "ProvinceID" => "61", + "InvarID" => 211 + ], + 365 => [ + "OnvarID" => 365, + "CityName" => "زهك", + "ProvinceID" => "61", + "InvarID" => 218 + ], + 366 => [ + "OnvarID" => 366, + "CityName" => "میرجاوه", + "ProvinceID" => "61", + "InvarID" => 399 + ], + 367 => [ + "OnvarID" => 367, + "CityName" => "زاهدان", + "ProvinceID" => "61", + "InvarID" => 212 + ], + 368 => [ + "OnvarID" => 368, + "CityName" => "خاش", + "ProvinceID" => "61", + "InvarID" => 144 + ], + 369 => [ + "OnvarID" => 369, + "CityName" => "دلگان", + "ProvinceID" => "61", + "InvarID" => 177 + ], + 370 => [ + "OnvarID" => 370, + "CityName" => "ایرانشهر", + "ProvinceID" => "61", + "InvarID" => 49 + ], + 371 => [ + "OnvarID" => 371, + "CityName" => "مهرستان", + "ProvinceID" => "61", + "InvarID" => 392 + ], + 372 => [ + "OnvarID" => 372, + "CityName" => "سیب و سواران", + "ProvinceID" => "61", + "InvarID" => 249 + ], + 373 => [ + "OnvarID" => 373, + "CityName" => "سراوان", + "ProvinceID" => "61", + "InvarID" => 227 + ], + 374 => [ + "OnvarID" => 374, + "CityName" => "فنوج", + "ProvinceID" => "61", + "InvarID" => 298 + ], + 375 => [ + "OnvarID" => 375, + "CityName" => "سرباز", + "ProvinceID" => "61", + "InvarID" => 229 + ], + 376 => [ + "OnvarID" => 376, + "CityName" => "قصر قند", + "ProvinceID" => "61", + "InvarID" => 312 + ], + 377 => [ + "OnvarID" => 377, + "CityName" => "نیك شهر", + "ProvinceID" => "61", + "InvarID" => 417 + ], + 378 => [ + "OnvarID" => 378, + "CityName" => "چاه بهار", + "ProvinceID" => "61", + "InvarID" => 132 + ], + 379 => [ + "OnvarID" => 379, + "CityName" => "كنارك", + "ProvinceID" => "61", + "InvarID" => 332 + ], + 380 => [ + "OnvarID" => 380, + "CityName" => "فیروزكوه", + "ProvinceID" => "11", + "InvarID" => 302 + ], + 381 => [ + "OnvarID" => 381, + "CityName" => "ملارد", + "ProvinceID" => "11", + "InvarID" => 381 + ], + 382 => [ + "OnvarID" => 382, + "CityName" => "پیشوا", + "ProvinceID" => "11", + "InvarID" => 106 + ], + 383 => [ + "OnvarID" => 383, + "CityName" => "قرچك", + "ProvinceID" => "11", + "InvarID" => 307 + ], + 384 => [ + "OnvarID" => 384, + "CityName" => "پاكدشت", + "ProvinceID" => "11", + "InvarID" => 100 + ], + 385 => [ + "OnvarID" => 385, + "CityName" => "پردیس", + "ProvinceID" => "11", + "InvarID" => 102 + ], + 386 => [ + "OnvarID" => 386, + "CityName" => "دماوند", + "ProvinceID" => "11", + "InvarID" => 179 + ], + 387 => [ + "OnvarID" => 387, + "CityName" => "ری", + "ProvinceID" => "11", + "InvarID" => 209 + ], + 388 => [ + "OnvarID" => 388, + "CityName" => "اسلامشهر", + "ProvinceID" => "11", + "InvarID" => 33 + ], + 389 => [ + "OnvarID" => 389, + "CityName" => "قدس", + "ProvinceID" => "11", + "InvarID" => 306 + ], + 390 => [ + "OnvarID" => 390, + "CityName" => "شهریار", + "ProvinceID" => "11", + "InvarID" => 265 + ], + 391 => [ + "OnvarID" => 391, + "CityName" => "ورامین", + "ProvinceID" => "11", + "InvarID" => 428 + ], + 392 => [ + "OnvarID" => 392, + "CityName" => "تهران", + "ProvinceID" => "11", + "InvarID" => 118 + ], + 393 => [ + "OnvarID" => 393, + "CityName" => "شمیرانات", + "ProvinceID" => "11", + "InvarID" => 261 + ], + 394 => [ + "OnvarID" => 394, + "CityName" => "رباط كریم", + "ProvinceID" => "11", + "InvarID" => 196 + ], + 395 => [ + "OnvarID" => 395, + "CityName" => "بهارستان", + "ProvinceID" => "11", + "InvarID" => 83 + ], + 396 => [ + "OnvarID" => 396, + "CityName" => "چالدران", + "ProvinceID" => "57", + "InvarID" => 135 + ], + 397 => [ + "OnvarID" => 397, + "CityName" => "شوط", + "ProvinceID" => "57", + "InvarID" => 269 + ], + 398 => [ + "OnvarID" => 398, + "CityName" => "ماكو", + "ProvinceID" => "57", + "InvarID" => 367 + ], + 399 => [ + "OnvarID" => 399, + "CityName" => "خوی", + "ProvinceID" => "57", + "InvarID" => 164 + ], + 400 => [ + "OnvarID" => 400, + "CityName" => "سلماس", + "ProvinceID" => "57", + "InvarID" => 241 + ], + 401 => [ + "OnvarID" => 401, + "CityName" => "پلدشت", + "ProvinceID" => "57", + "InvarID" => 104 + ], + 402 => [ + "OnvarID" => 402, + "CityName" => "جایپاره", + "ProvinceID" => "57", + "InvarID" => 137 + ], + 403 => [ + "OnvarID" => 403, + "CityName" => "ارومیه", + "ProvinceID" => "57", + "InvarID" => 26 + ], + 404 => [ + "OnvarID" => 404, + "CityName" => "اشنویه", + "ProvinceID" => "57", + "InvarID" => 35 + ], + 405 => [ + "OnvarID" => 405, + "CityName" => "سردشت", + "ProvinceID" => "57", + "InvarID" => 234 + ], + 406 => [ + "OnvarID" => 406, + "CityName" => "بوكان", + "ProvinceID" => "57", + "InvarID" => 91 + ], + 407 => [ + "OnvarID" => 407, + "CityName" => "مهاباد", + "ProvinceID" => "57", + "InvarID" => 388 + ], + 408 => [ + "OnvarID" => 408, + "CityName" => "پیرانشهر", + "ProvinceID" => "57", + "InvarID" => 105 + ], + 409 => [ + "OnvarID" => 409, + "CityName" => "میاندوآب", + "ProvinceID" => "26", + "InvarID" => 396 + ], + 410 => [ + "OnvarID" => 410, + "CityName" => "نقده", + "ProvinceID" => "57", + "InvarID" => 407 + ], + 411 => [ + "OnvarID" => 411, + "CityName" => "تكاب", + "ProvinceID" => "57", + "InvarID" => 115 + ], + 412 => [ + "OnvarID" => 412, + "CityName" => "شاهین دژ", + "ProvinceID" => "57", + "InvarID" => 257 + ], + 413 => [ + "OnvarID" => 413, + "CityName" => "اشكذر", + "ProvinceID" => "93", + "InvarID" => 430 + ], + 414 => [ + "OnvarID" => 414, + "CityName" => "میبد", + "ProvinceID" => "93", + "InvarID" => 398 + ], + 415 => [ + "OnvarID" => 415, + "CityName" => "اردكان", + "ProvinceID" => "93", + "InvarID" => 22 + ], + 416 => [ + "OnvarID" => 416, + "CityName" => "ابركوه", + "ProvinceID" => "93", + "InvarID" => 16 + ], + 417 => [ + "OnvarID" => 417, + "CityName" => "بافق", + "ProvinceID" => "93", + "InvarID" => 58 + ], + 418 => [ + "OnvarID" => 418, + "CityName" => "مهریز", + "ProvinceID" => "93", + "InvarID" => 393 + ], + 419 => [ + "OnvarID" => 419, + "CityName" => "تفت", + "ProvinceID" => "93", + "InvarID" => 113 + ], + 420 => [ + "OnvarID" => 420, + "CityName" => "یزد", + "ProvinceID" => "93", + "InvarID" => 430 + ], + 421 => [ + "OnvarID" => 421, + "CityName" => "بهاباد", + "ProvinceID" => "93", + "InvarID" => 81 + ], + 422 => [ + "OnvarID" => 422, + "CityName" => "خاتم", + "ProvinceID" => "93", + "InvarID" => 143 + ], + 423 => [ + "OnvarID" => 423, + "CityName" => "ماهنشان", + "ProvinceID" => "67", + "InvarID" => 369 + ], + 424 => [ + "OnvarID" => 424, + "CityName" => "خدابنده", + "ProvinceID" => "67", + "InvarID" => 146 + ], + 425 => [ + "OnvarID" => 425, + "CityName" => "ابهر", + "ProvinceID" => "67", + "InvarID" => 17 + ], + 426 => [ + "OnvarID" => 426, + "CityName" => "ابهر", + "ProvinceID" => "67", + "InvarID" => 17 + ], + 427 => [ + "OnvarID" => 427, + "CityName" => "سلطانیه", + "ProvinceID" => "67", + "InvarID" => 240 + ], + 428 => [ + "OnvarID" => 428, + "CityName" => "ایجرود", + "ProvinceID" => "67", + "InvarID" => 47 + ], + 429 => [ + "OnvarID" => 429, + "CityName" => "زنجان", + "ProvinceID" => "67", + "InvarID" => 217 + ], + 430 => [ + "OnvarID" => 430, + "CityName" => "طارم", + "ProvinceID" => "67", + "InvarID" => 275 + ], + 431 => [ + "OnvarID" => 431, + "CityName" => "خرمدره", + "ProvinceID" => "67", + "InvarID" => 150 + ] + ]; + return $nikarayanToRmsCityId[$city_id]["InvarID"]; + } +} \ No newline at end of file diff --git a/app/Http/Requests/V3/Permission/StoreRequest.php b/app/Http/Requests/V3/Permission/StoreRequest.php index 4c04b82b..9a09ab36 100644 --- a/app/Http/Requests/V3/Permission/StoreRequest.php +++ b/app/Http/Requests/V3/Permission/StoreRequest.php @@ -24,7 +24,7 @@ class StoreRequest extends FormRequest return [ 'name' => 'required|string|unique:permissions,name', 'name_fa' => 'required|string', - 'description' => 'required|string', + 'description' => 'string', 'type' => 'required|string', 'type_fa' => 'required|string', 'need_province' => 'required|in:0,1', diff --git a/app/Http/Requests/V3/Permission/UpdateRequest.php b/app/Http/Requests/V3/Permission/UpdateRequest.php index 3c16cab0..e5213c11 100644 --- a/app/Http/Requests/V3/Permission/UpdateRequest.php +++ b/app/Http/Requests/V3/Permission/UpdateRequest.php @@ -24,7 +24,7 @@ class UpdateRequest extends FormRequest return [ 'name' => "required|string|unique:permissions,name,{$this->permission->id}", 'name_fa' => 'required|string', - 'description' => 'required|string', + 'description' => 'string', 'type' => 'required|string', 'type_fa' => 'required|string', 'need_province' => 'required|in:0,1', diff --git a/app/Services/NikarayanService.php b/app/Services/NikarayanService.php index da8ab34d..19f4945e 100644 --- a/app/Services/NikarayanService.php +++ b/app/Services/NikarayanService.php @@ -45,4 +45,31 @@ class NikarayanService return 0; } + + /** + * @throws SoapFault + */ + public function getRoadObservedProblemsByDate() + { + 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; + + $soap_client = new SoapClient($url); + return $soap_client->Get_RoadObservedProblems_ByDate(array( + 'strUserName' => 'vaytelrop', + 'strPassword' => 'VaYtelROP*2024', + 'strStartDate' => $date, + 'strEndDate' => $date + )); + } + catch (\Exception $e) { + Log::channel('nikarayan')->error($e->getMessage()); + throw $e; + } + } } From eb75537d9b631a34db0dc00d8b21f1ff732c80df Mon Sep 17 00:00:00 2001 From: joddyabott Date: Sun, 9 Mar 2025 14:29:36 +0330 Subject: [PATCH 60/61] creatcrud for loglist --- app/Http/Controllers/V3/LogListController.php | 49 ++++++++++++++++++- app/Http/Requests/V3/LogList/StoreRequest.php | 30 ++++++++++++ .../Requests/V3/LogList/UpdateRequest.php | 31 ++++++++++++ app/Models/LogList.php | 2 + routes/v3.php | 5 ++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 app/Http/Requests/V3/LogList/StoreRequest.php create mode 100644 app/Http/Requests/V3/LogList/UpdateRequest.php diff --git a/app/Http/Controllers/V3/LogListController.php b/app/Http/Controllers/V3/LogListController.php index b383924e..7e0bb72a 100644 --- a/app/Http/Controllers/V3/LogListController.php +++ b/app/Http/Controllers/V3/LogListController.php @@ -2,17 +2,62 @@ namespace App\Http\Controllers\V3; +use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\LogList\StoreRequest; +use App\Http\Requests\V3\LogList\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\LogList; +use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; class LogListController extends Controller { use ApiResponse; - public function index(): JsonResponse + public function index(Request $request): JsonResponse { - return $this->successResponse(LogList::all('description','log_unique_code')); + return response()->json(DataTableFacade::run( + LogList::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'])); + } + + public function list(): JsonResponse + { + return $this->successResponse(LogList::all('description', 'log_unique_code')); + } + + public function store(StoreRequest $request): JsonResponse + { + LogList::query()->create([ + 'description' => $request->description, + 'log_unique_code' => $request->log_unique_code, + 'action_type' => $request->action_type, + ]); + + return $this->successResponse(); + } + + public function show(LogList $logList): JsonResponse + { + return $this->successResponse($logList); + } + + public function update(UpdateRequest $request, LogList $logList): JsonResponse + { + LogList::query()->update([ + 'description' => $request->description, + 'log_unique_code' => $request->log_unique_code, + 'action_type' => $request->action_type, + ]); + return $this->successResponse(); + } + + public function destroy(LogList $logList): JsonResponse + { + $logList->delete(); + return $this->successResponse(); } } diff --git a/app/Http/Requests/V3/LogList/StoreRequest.php b/app/Http/Requests/V3/LogList/StoreRequest.php new file mode 100644 index 00000000..65d1da73 --- /dev/null +++ b/app/Http/Requests/V3/LogList/StoreRequest.php @@ -0,0 +1,30 @@ +|string> + */ + public function rules(): array + { + return [ + 'description' =>'required|string', + 'log_unique_code' =>'required|numeric|unique:log_lists,log_unique_code', + 'action_type' =>'required|string', + ]; + } +} diff --git a/app/Http/Requests/V3/LogList/UpdateRequest.php b/app/Http/Requests/V3/LogList/UpdateRequest.php new file mode 100644 index 00000000..feee0d27 --- /dev/null +++ b/app/Http/Requests/V3/LogList/UpdateRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'description' => 'required|string', + 'log_unique_code' => ['required', 'numeric', Rule::unique('log_lists', 'log_unique_code')->ignore($this->logList->id)], + 'action_type' => 'required|string', + ]; + } +} diff --git a/app/Models/LogList.php b/app/Models/LogList.php index c7831a54..bc07f4f0 100644 --- a/app/Models/LogList.php +++ b/app/Models/LogList.php @@ -10,4 +10,6 @@ class LogList extends Model use HasFactory; public $timestamps = false; + + protected $guarded = []; } \ No newline at end of file diff --git a/routes/v3.php b/routes/v3.php index 14306eaf..5a85fb8e 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -323,6 +323,11 @@ Route::prefix('log_list') ->controller(LogListController::class) ->group(function () { Route::get('/', 'index')->name('index'); + Route::get('/list', 'list')->name('list'); + Route::post('/', 'store')->name('store'); + Route::get('/{logList}', 'show')->name('show'); + Route::post('/{logList}', 'update')->name('update'); + Route::delete('/{logList}', 'destroy')->name('destroy'); }); Route::prefix('safety_and_privacy') From 3291eba66ef0f4ab3b200788d53659975f9d5c4a Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 10 Mar 2025 11:24:14 +0330 Subject: [PATCH 61/61] refactor the job --- .../Commands/SendRoadObservationToNikarayanCommand.php | 9 ++++----- ...istController.php => LogListManagementController.php} | 4 ++-- app/Jobs/SendRoadObservationToNikarayan.php | 7 +++++++ routes/v3.php | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) rename app/Http/Controllers/V3/{LogListController.php => LogListManagementController.php} (95%) diff --git a/app/Console/Commands/SendRoadObservationToNikarayanCommand.php b/app/Console/Commands/SendRoadObservationToNikarayanCommand.php index 224c0acd..e04568bd 100644 --- a/app/Console/Commands/SendRoadObservationToNikarayanCommand.php +++ b/app/Console/Commands/SendRoadObservationToNikarayanCommand.php @@ -32,15 +32,14 @@ class SendRoadObservationToNikarayanCommand extends Command $count = 0; $this->info("Dispatching jobs with a delay between each..."); - DB::transaction(function () use ($count) { + 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']) - ->where('rms_status', '=', 0) - ->chunkById(50, function ($roads) use ($delay, $count) { + ->chunkById(50, function ($roads) use (&$delay, &$count) { foreach ($roads as $road) { - $road->update(['rms_status' => 1]); - SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addMinutes(10)->addSeconds($delay)); + $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; diff --git a/app/Http/Controllers/V3/LogListController.php b/app/Http/Controllers/V3/LogListManagementController.php similarity index 95% rename from app/Http/Controllers/V3/LogListController.php rename to app/Http/Controllers/V3/LogListManagementController.php index 7e0bb72a..c351fca6 100644 --- a/app/Http/Controllers/V3/LogListController.php +++ b/app/Http/Controllers/V3/LogListManagementController.php @@ -11,7 +11,7 @@ use App\Models\LogList; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; -class LogListController extends Controller +class LogListManagementController extends Controller { use ApiResponse; @@ -47,7 +47,7 @@ class LogListController extends Controller public function update(UpdateRequest $request, LogList $logList): JsonResponse { - LogList::query()->update([ + $logList->update([ 'description' => $request->description, 'log_unique_code' => $request->log_unique_code, 'action_type' => $request->action_type, diff --git a/app/Jobs/SendRoadObservationToNikarayan.php b/app/Jobs/SendRoadObservationToNikarayan.php index ffb21eab..87cdeb0c 100644 --- a/app/Jobs/SendRoadObservationToNikarayan.php +++ b/app/Jobs/SendRoadObservationToNikarayan.php @@ -15,6 +15,13 @@ class SendRoadObservationToNikarayan implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * The number of times the job may be attempted. + * + * @var int + */ + public int $tries = 2; + /** * Create a new job instance. */ diff --git a/routes/v3.php b/routes/v3.php index 8db404f3..380dd3c9 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -20,7 +20,7 @@ use App\Http\Controllers\V3\Dashboard\RoadPatrolProjectController; use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacyController; use App\Http\Controllers\V3\FMSVehicleManagementController; use App\Http\Controllers\V3\Harim\DivarkeshiController; -use App\Http\Controllers\V3\LogListController; +use App\Http\Controllers\V3\LogListManagementController; use App\Http\Controllers\V3\NotificationController; use App\Http\Controllers\V3\PermissionManagementController; use App\Http\Controllers\V3\ProfileController; @@ -321,7 +321,7 @@ Route::prefix('road_observations') Route::prefix('log_list') ->name('logList.') - ->controller(LogListController::class) + ->controller(LogListManagementController::class) ->group(function () { Route::get('/', 'index')->name('index'); Route::get('/list', 'list')->name('list');