add country activity report

This commit is contained in:
2025-03-02 10:55:03 +03:30
parent a65ec5e2bd
commit b31ea8bba2
3 changed files with 89 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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');
});