From b31ea8bba24fd921c5bc2eb9a09db504bf04c616 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 2 Mar 2025 10:55:03 +0330 Subject: [PATCH] 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'); });